#Light turn off after on for an hour

1 messages · Page 1 of 1 (latest)

wispy kayak
#

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?

twin sequoia
#

There are several way to achieve this with a single automation:

  1. Use one trigger with your 5 entities and use the state trigger with on and for: "1:00:00" to trigger after it is on for 1h. Use the trigger.entity_id variable to fetch the entity that triggered the automation and then use this variable in the light.turn_off action.
  2. 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 }}"
wispy kayak
#

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.

clear oyster
exotic tusk