I’d like to apply the same logic to a number of lights and I just can’t see a nice way to do it that doesn’t involve a whole load of repetition. Basically when a light is turned on, turn it off an hour (or whatever) later. The problem; this needs to happen to about 5 lights in the house. Basically I use motion sensors in most rooms, but they are never going to work in bedrooms. Entity state triggers only work on one entity. Device triggers (which I don’t like using because they are not YAML friendly) are the same. So I guess I might need a template? But then how does the action know what light to turn off?
#Light turn off after on for an hour
1 messages · Page 1 of 1 (latest)
There are several way to achieve this with a single automation:
- Use one trigger with your 5 entities and use the state trigger with
onandfor: "1:00:00"to trigger after it is on for 1h. Use thetrigger.entity_idvariable to fetch the entity that triggered the automation and then use this variable in thelight.turn_offaction. - Create 5 triggers for the same automation, assign the ID to each of them, and then in the choose action manually turn off each light.
Something like this is best I think, and then you list your entities you want to react on
triggers:
- trigger: state
entity_id:
- light.a
- light.b
- light.c
to: "on"
for: "1:00:00"
actions:
- action: light.turn_off
target:
entity_id: "{{ trigger.entity_id }}"
I’ll try your first idea first. And the Choose tree will be a standby. But yup I think using trigger.entity_id will do the job, thanks so much! That’s a new one for me. Use Choose “trees” everywhere in my automations but I’ve never dug into the trigger object before.
Another way to do this would be to write your automation once for one light, then turn it into a blueprint that takes the light entity id as a parameter. Then you can update the automation in one place by editing the blueprint and it'll apply to all the lights. See https://www.home-assistant.io/docs/blueprint/tutorial/ to get started.
that feels like a really smart solution 👍