Make sure light switches off only if room is empty

I want to automate a light. If there is no motion I delay my automation to switch off after 4.5 minutes. However, if I just don’t move in this room I don’t want it to switch off.

I have multiple sensors nearby. All my motion sensors have maximum of 30 s occupation time.
At least one sensor will trigger, when I leave the room. So I could check if there is motion (on or off) in the last 5 minutes of a group of sensors. This still isn’t bulletproof as someone else could trigger outside the room, while there is no motion inside of the room causing this to switch off.

For that I would need to check if the group of sensors has triggered (on or off) in the last 5 minutes.

But the more I think about this, the more issues appear…

I am also open for other ideas.

“Bulletproof” is difficult to achieve with conventional motion sensors - if you haven’t already, do a search for posts on “presence detection”.

Thanks for the hint. I will read into that.

I would still like to try this approach. But how can I make a template that checks if a group of sensors had any changes (on/off) in the last 5 minutes?

Create a binary_sensor group using Helpers (Setting > Devices and Services > Helpers) and add all of your motion sensors there. That will create a binary sensor which you can use in your automation.

Thanks, that was indeed new to me.

Here’s what I am trying out:

alias: test
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.motion
    to: "off"
    for:
      hours: 0
      minutes: 4
      seconds: 30
condition:
  - condition: not
    conditions:
      - condition: or
        conditions:
          - condition: state
            entity_id: binary_sensor.motion_group
            state: "on"
            for:
              hours: 0
              minutes: 5
              seconds: 0
          - condition: state
            entity_id: binary_sensor.motion_group
            state: "off"
            for:
              hours: 0
              minutes: 5
              seconds: 0
action:
  - service: lights.turn_off
    data: {}
    target:
      entity_id: lights.test
mode: single

Have you considered using the Bayesian integration to calculate the probability of someone being in the room from several entities?

Motion sensor detects no movement, but TV is on, so 80% chance of the room still being occupied, so don’t switch off the lights.

1 Like

I have played around with that, but I just don’t switch off lights when TV is on as I always switch it off if not in use. But I might have to look into that, thanks for the reminder.