I am trying to make my a script play along with a condition containing templates, and I simply cant figure out, why this is not working.
Long story short, when I press a switch, I want an automation to send two variables to a script. The script checks if the switch is still on, if so, volume up and call another script that does exactly the same (loop so I can longpress the switch).
It seems to work without the condition, but as I see it, there is nothing wrong with my condition, is there?
Automation:
- alias: Volume Up Køkken
initial_state: True
trigger:
platform: state
entity_id: switch.stue_4_overst_hojre
to: 'on'
action:
service: script.volume_op_1
data_template:
switch: "stue_4_overst_hojre"
where: "livingroom"
using brackets will not work on a string. That only works on objects. The function is_state is looking for an entity_id string. Which will only have the format 'domain.object_id', not 'domain.[object_id]'.
So to clarify. This is a state object:
states.light.laundry
Items inside can be accessed in 1 of 2 ways:
Direct access to state:
states.light.laundry.state
Keyword access to state:
states.light.laundry['state']
When using any of the built in attribute accessing functions: states(), state_attr(), is_state(), etc. They expect strings. They can only be accessed with the entity_id.
That helped a lot on the condition, thanks.
Supposed that I change the variable switch to switch.tryk_4_overst_hojre and where to media_player.livingroom, whould it make the template_value more clean, or will it have no effect.
And one more question. I try to pass the variable to the other script, but that part seems to not work aswell. Is that even possible to pass a variable on like that?
Think I was to fast on the trigger. I had a test automation turning up the volume once along with the actual automation I wanted to use. So it seems the condition still don’t let me pass. So back to the question if it could help setting the entire entity Id into the variable
You are the best! Thanks for helping me out.
I could not make it work after copy/pasting it in after correcting my typo in milliseconds (no errors when checking the config), so i ended up writing everything in from scratch.