was this addressed to me? if so, which template sensor are you referring to? My post was referring to an automation using the variable custom component.
@Mariusthvdb, yes sorry for not being clear
I like the screenshot you have posted above, I assumed this being created with a template sensor.
If its not the case, I still want to know how you achieved this to show the the history of the different motion sensor in 1 big sensor view.
a ok, sure, I use this automation I built using my motion sensors:
automation:
# Update Last Motion variable
- alias: 'Update Last Motion'
id: 'Update Last Motion'
# initial_state: 'on'
trigger:
platform: state
entity_id:
- binary_sensor.laundry_motion_sensor
- binary_sensor.dining_table_motion_sensor
- etc etc etc
to: 'on'
action:
service: variable.set_variable
data:
variable: last_motion
attributes_template: >
{
"history_1": "{{ variable.state }}",
"history_2": "{{ variable.attributes.history_1 }}",
"history_3": "{{ variable.attributes.history_2 }}",
"history_4": "{{ variable.attributes.history_3 }}",
"history_5": "{{ variable.attributes.history_4 }}",
"history_6": "{{ variable.attributes.history_5 }}",
"history_7": "{{ variable.attributes.history_6 }}",
"history_8": "{{ variable.attributes.history_7 }}",
"history_9": "{{ variable.attributes.history_8 }}",
"history_10": "{{ variable.attributes.history_9 }}"
}
data_template:
value: >
{{ trigger.to_state.attributes.friendly_name|replace('motion sensor','') }}:
{{as_timestamp(states.variable.last_motion.last_changed)| timestamp_custom('%X') }}
and variable:
##########################################################################################
# Inputs
# https://diyfuturism.com/index.php/2017/12/15/useful-sensor-motion-last-seen-________/
##########################################################################################
variable:
last_motion:
value: 'Not set'
restore: true
attributes:
icon: mdi:map-marker
friendly_name: 'Last Motion'
in the link in my comments, there’s some extra info on this custom component
I think the biggest one is that you can also set attributes without the limitation of 255 characters.
Attributes don’t have a 255 character limit, only states do.
As i said.
Can this (or similar) component solve the challange in this post? Namely I would like to control entity templates in one place and re-use them where needed. Thanks!
Is there a way to delete attributes from the variable entity after you create them?
I updated the attribute names in a varaiable. set_variable service call and instead of changing the existing variable attributes it just added the new ones to the list. Now I have a bunch of unused attributes and the list is twice as long.
please help, I am using the variable and setting a value just find
when i try and use the variable in a template , the value is not resolving.
data_template:
event: send-sam-reminder
value1: {{ variable.messagetosend }}
service: ifttt.trigger
reposting with correct indentation
data_template:
event: send-sam-reminder
value1: {{ variable.messagetosend }}
service: ifttt.trigger
never mind if fixed it
I use them like this:
{{ states.variable.messagetosend.state }}
Hello. I’ve tried to update/change a variables value and/or its attributes in node red with call service nod, but it doesn’t work. Node configuration:
Server: Home Assistant
Domain: variable
Service: set_variable
Entity Id: variable.example_123
Data: { “value” : “{{Buterbrod}}”}
And… Debug: “Call-service API error. Error Message: extra keys not allowed @ data[‘entity_id’]”
What should I do to make it work?
Do not use Entity_id field. Use this part in data field.
Hello, give example plz
Like:
Data: {
“value” : “{{Buterbrod}}”
“variable”: “moi_zavtrak”
}
Why doesn’t this update my variable?
- alias: "Automation - Update"
trigger:
- platform: state
entity_id: sensor.consumption
action:
- service: variable.set_variable
data:
variable: usage
value_template: "{{ (trigger.to_state.state|float-trigger.from_state.state|float)|round(3) }}"
And changing the action to this does work:
action:
- service: variable.set_variable
data:
variable: usage
value_template: "{{ (now().minute/1000)|round(3) }}"
@rogro82.
I need help please.
I am a newbie to Home Assistant so if emailing you for help is an inappropriate thing to do please accept my apologies.
I am trying to use your variables as data to a service call but I just am not getting the result I need.
I wonder if you could please advise what I’m doing wrong.
I have included two of the service calls in the scripts.yaml. The one in bold tries to use the variables to give the same result as the one not bold.
The one not bold works fine and an 8 is sent to my TV. The one with the variables does not work.
Configuration.yaml
var: !include variables.yaml
variables.yaml
which_remote:
friendly_name: "which_remote"
initial_value: remote.rmpro_remote
which_freesat:
friendly_name: "which_freesat"
initial_value: "lounge freesat"
automations.yaml
- alias: 'TV Channel BBC1'
trigger:
- platform: state
entity_id: input_select.freesat_channel
to: 'BBC1'
action:
- service: script.lounge_tv_channel_9
- service: script.lounge_tv_channel_5
- service: script.lounge_tv_channel_8
Scripts.yaml
lounge_tv_channel_8:
alias: Lounge TV channel 8
sequence:
- service: remote.send_command
data:
entity_id: remote.rmpro_remote
device: lounge freesat
command: b64:JgBgAAABJpMSExETEhISExETEhISExETEhMRExETEhMROBITERMSEhITETgTEhE4EhMRExISEhMROBITETgTEhE4EjgROBI4EwAGHwABJkoSAAxEAAEmSRQADEQAASVLEgANBQAAAAAAAAAA
lounge_tv_channel_9:
alias: Lounge TV channel 9
sequence:
- service: remote.send_command
data_template:
entity_id: var.which_remote
device: var.which_device
command: b64:JgBYAAABJpMTEhETEhISExISEhISExETEhMRExETEhMROBITERMTERI4ETgSExE4ExIRExITERMRExITETgTEhE4EzcSNxM3EwAGHwABJkoTAAxDAAEmShMADQU`
You need to set variable with variable.set_variable service call in automations. I don’t see that in your code. I had some problems with HA 0.117 and original rogro82 component, so i replaced it with forked version. https://github.com/Wibias/hass-variables Also are you sure that you need this custom component? What do you try to achieve with this automation?
Vladimir,
Thank you for your response. I didn’t try to set variables yet as I wanted to make sure everything would work using the initial value settings.
You ask what I am trying to do. Well I have two set top boxes in different rooms that are controlled by the same infrared codes. I have a Broadlink RMpro in one room and a Broadlink Mini in the other. I didn’t want to duplicate code to use the individual IR sender so my plan was to set the sender at the top of each automation.
My final thought was to set the IR code as well to minimise coding completely.
Perhaps I should try your fork?
Thanks again
I have had issue setting variables in automations, though I believe they work when set in a script - perhaps have the automation call a script?
I have not yet tried the new fork.
I’m also contemplating moving all these variables to input_* (as I was a noob when I first setup variables custom_component a year ago and wasn’t aware of them). I’m also still on .116.4, so can’t speak to if they work in .117.