Automation to turn lights off when not present

Hi, I need some help with an automation that isn’t working and I can’t figure out why. I have espresense setup to track the movement of 3 devices in our home and was hoping to include these as conditions in the automation. What I need to happen is for the lights in the bedroom to turn off after 1 minute of no motion but only when the 3 devices are not in the room (lights stay on when room occupied). Any help would be appreciated.

alias: Automation - Our bedroom lights - off
description: ''
trigger:
  - type: no_motion
    platform: device
    device_id: 33f4b8c859817f4066e5
    entity_id: binary_sensor.our_bedroom_motion_ias_zone
    domain: binary_sensor
    for:
      hours: 0
      minutes: 1
      seconds: 0
condition:
  - condition: state
    entity_id: sensor.gareth_smart_watch
    state: lucas_room
  - condition: or
    conditions:
      - condition: state
        entity_id: sensor.gareth_smart_watch
        state: not_home
  - condition: state
    entity_id: sensor.lou_smart_watch
    state: not_home
  - condition: or
    conditions:
      - condition: state
        entity_id: sensor.lou_smart_watch
        state: lucas_room
action:
  - type: turn_off
    device_id: 0f19c9c6402bc8cf3
    entity_id: light.gareth_light_strip
    domain: light
  - type: turn_off
    device_id: d67f8aca4c3ea48ba95
    entity_id: light.lou_light_strip
    domain: light
  - type: turn_off
    device_id: f8c4271d8f4e9ba556e3f007d
    entity_id: light.our_bedroom_light
    domain: light
  - service: switch.turn_off
    target:
      entity_id: switch.our_bedroom_lamp
    data: {}
mode: single

1 Like

Like this:

condition:
  - condition: or
    conditions:
      - condition: state
        entity_id: sensor.gareth_smart_watch
        state: lucas_room
      - condition: state
        entity_id: sensor.gareth_smart_watch
        state: not_home
      - condition: state
        entity_id: sensor.lou_smart_watch
        state: not_home
      - condition: state
        entity_id: sensor.lou_smart_watch
        state: lucas_room

I think you want all the conditions to be true, so that would make:

condition:
  - condition: state
    entity_id: sensor.gareth_smart_watch
    state: lucas_room
  - condition: state
    entity_id: sensor.gareth_smart_watch
    state: not_home
  - condition: state
    entity_id: sensor.lou_smart_watch
    state: not_home
  - condition: state
    entity_id: sensor.lou_smart_watch
    state: lucas_room

Looking at what you created, I think what you had in mind was:

condition:
  - condition: or
    conditions:
      - condition: state
        entity_id: sensor.gareth_smart_watch
        state: lucas_room
      - condition: state
        entity_id: sensor.gareth_smart_watch
        state: not_home
  - condition: or
    conditions:
      - condition: state
        entity_id: sensor.lou_smart_watch
        state: not_home
      - condition: state
        entity_id: sensor.lou_smart_watch
        state: lucas_room

It would make more sense to check that no one was in the bedroom (if it has a presence sensor) rather than checking if they are in other rooms or away. This could be done with a not condition.

condition:
  - condition: not
    conditions:
      - condition: state
        entity_id: sensor.gareth_smart_watch
        state: bedroom # assuming this exists
      - condition: state
        entity_id: sensor.lou_smart_watch
        state: bedroom # assuming this exists

You are right. I should have resisted responding on my phone. It just doesn’t work for me :blush:

It still depends on them having a room sensor in the bedroom, otherwise I think your second set of conditions would be the correct one.

Hi Tom, thanks for the suggestion. That’s exactly what I wanted, I don’t know why I didn’t think of that, it seems the most logical.

1 Like