Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 95919

Automation: Automatically turn off lights if left on too long without turning off other lights

$
0
0

@kendobendo wrote:

So this has probably happened to a lot of people. You turn on the light in one room. You leave the room to do something else and forget to turn off the light in the other room. So I want an automation that keeps track of my lights in my house. I know I could put a motion sensor or something like that but this time I want it to trigger based on how long the lights have been turned on.

There are 10+ lights that I want to monitor. I want them to turn off if left on for more than two hours. I can on top of my head think of a few ways of doing this but none of them are particularly elegant. here’s an example of how i could do this:

- alias: Turn off ligts if on for more than two hours
  trigger:
    platform: state
    entity_id: light.light1, light.light2, light.light3
    from: 'off'
    to: 'on'
    for:
      hours: 2
      minutes: 0
      seconds: 0
  action:
    service: light.turn_off
    data:
      entity_id: light.light1
    service: light.turn_off
    data:
      entity_id: light.light2
    service: light.turn_off
    data:
      entity_id: light.light3

But the problem with the above code is that it would turn off lights that have not been on for more than two hours. I guess I could make one automation for each and ever light but that feels heavy.

is there a way to detect what light that triggered the automation and then only turn off that particular light and leave the rest of them on? At least until they too have been on for too long?

Posts: 12

Participants: 7

Read full topic


Viewing all articles
Browse latest Browse all 95919

Trending Articles