Can anyone recommend a tutorial for Jinja where they explain the data structures? None of the tutorials seem to have information on syntax and how to populate structures. For example, i am trying to create a list of device IDs so that i can later iterate through them to determine which device triggered, but i can’t even figure out how to get the data into the list. Thinking Jinja would do substitutions, I’ve tried:
{% set up_bath =
[
device_id("switch.upstairs_bathroom_fan"),
device_id("light.upstairs_bathroom_light"),
device_id("light.upstairs_bathroom_vanity_light")
]
%}
the logic part of things is easy, i am just having issues with basic syntax and would welcome any pointers or reading recommendations. Sorry for the super basic question
well, i am not sure what happened, but i moved the code in the dev tools to the very top so i could do a screen capture like yours and magically now it is working…
thank you! so, aside from years of doing templates, where do you find information such as this so i don’t have to pepper the forum with questions every 5 minutes?
thank you all for the help, i really appreciate it. maybe you can help me push this over the goal line. I’ve been trying to create an automation to turn on all lights and switches in any of the bathrooms if any of the lights are double tapped. when the device is double tapped, i get the device-id of the device that triggered it. i then put all these into a dictionary so i can determine which bathroom was the one that was triggered. the final step that i can’t really figure out is how to turn on the devices from the device id’s that i have. they could be either switches or lights, so i was hoping I could find a generic turn_on event, but have yet to find it. Is there a way to set the state to on via a template? here is the code i’ve been messing with so far:
#This is the trigger value i expect to receive i hard coded one for testing.
{% set trigger_id = '1297c3624136259c6d4237f1b9dbd99e' %}
#Set up of the groups
{% set up_bath = [
"switch.upstairs_bathroom_fan",
"light.upstairs_bathroom_light",
"light.upstairs_bathroom_vanity_light"
] | map('device_id') | list %}
{% set master_bath = [
"switch.master_bathroom_fan",
"light.master_bathroom_light",
"light.master_bathroom_vanity_light"
] | map('device_id') | list %}
{% set guest_bath = [
"switch.guest_bathroom_fan_2",
"light.guest_bathroom_light",
"light.guest_bathroom_vanity_light"
] | map('device_id') | list %}
#Load into dictionary
{% set all_baths = { 'up_bath' : up_bath,
'master_bath': master_bath,
'guest_bath' : guest_bath
} %}
# loop through dictionary to find the group
{% for key, value in all_baths.items() %}
{% if trigger_id in value %}
# found the device, this is the group
{% for dev in value %}
#
# HERE IS WHERE I NEED TO TURN THE DEVICES ON
# I HAVE THE DEVICE ID FOR EACH OF THE DEVICES
#
{% endfor %}
{% endif %}
{% endfor %}
I’m making an assumption that the trigger variable for the Event Trigger you created has an entity_id property. Its availability depends on the trigger type. According to the documentation for the Event Trigger, it’s not present.
even better than mine. you are right, it does not have an entity_id, it has a device_id, but since all the entities associated with it are in the same area, could i use something like:
ok, thank you very much @123, @vingerha, and @petro… i think i am getting the hang of this and all your help has definitely made it easier… here is the final and WORKING automation: