How to turn off light if no motion is detected for 10 minutes?

I put up two cheap Zigbee motion sensors in my staircase, one at the top and one at the bottom, and a Zigbee light bulb in the ceiling. I have created an automation that turns on the light bulb if motion is detected and then turns off the light if motion is detected again, e.g. if I go downstairs the light turns on and when I am at the bottom the light turns off.

What I’m having problems with is that I want the light to turn off if no second motion is detected within 10 minutes, e.g. if I start going downstairs and go back up instead. Right now the light stays on indefinitely in that case.

Here’s what I’ve done so far (I put a 1 minute delay on the light because the motion sensors have a 1 minute timeout)

alias: Lidl motion test
description: ""
trigger:
  - type: motion
    platform: device
    device_id: aa6b0932cb81fae0c6eb8cbcfa7fe979
    entity_id: binary_sensor.lidl_motion_sensor_up_occupancy
    domain: binary_sensor
    id: motion-up
  - type: motion
    platform: device
    device_id: 1ab4c3c77c28e426fb478d4f44be7a48
    entity_id: binary_sensor.lidl_motion_sensor_down_occupancy
    domain: binary_sensor
    id: motion-down
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: motion-up
          - condition: device
            type: is_off
            device_id: 7ab757b64dc096a28c18b1c790b8f50a
            entity_id: light.lidl_light_1
            domain: light
        sequence:
          - type: turn_on
            device_id: 7ab757b64dc096a28c18b1c790b8f50a
            entity_id: light.lidl_light_1
            domain: light
      - conditions:
          - condition: trigger
            id: motion-down
          - condition: device
            type: is_off
            device_id: 7ab757b64dc096a28c18b1c790b8f50a
            entity_id: light.lidl_light_1
            domain: light
        sequence:
          - type: turn_on
            device_id: 7ab757b64dc096a28c18b1c790b8f50a
            entity_id: light.lidl_light_1
            domain: light
    default: []
  - choose:
      - conditions:
          - condition: trigger
            id: motion-up
          - condition: device
            type: is_on
            device_id: 7ab757b64dc096a28c18b1c790b8f50a
            entity_id: light.lidl_light_1
            domain: light
        sequence:
          - delay:
              hours: 0
              minutes: 1
              seconds: 0
              milliseconds: 0
            enabled: true
          - type: turn_off
            device_id: 7ab757b64dc096a28c18b1c790b8f50a
            entity_id: light.lidl_light_1
            domain: light
      - conditions:
          - condition: trigger
            id: motion-down
          - condition: device
            type: is_on
            device_id: 7ab757b64dc096a28c18b1c790b8f50a
            entity_id: light.lidl_light_1
            domain: light
        sequence:
          - delay:
              hours: 0
              minutes: 1
              seconds: 0
              milliseconds: 0
            enabled: true
          - type: turn_off
            device_id: 7ab757b64dc096a28c18b1c790b8f50a
            entity_id: light.lidl_light_1
            domain: light
  - if:
      - condition: device
        type: is_on
        device_id: 7ab757b64dc096a28c18b1c790b8f50a
        entity_id: light.lidl_light_1
        domain: light
        for:
          hours: 0
          minutes: 10
          seconds: 0
        enabled: true
    then:
      - type: turn_off
        device_id: 7ab757b64dc096a28c18b1c790b8f50a
        entity_id: light.lidl_light_1
        domain: light
    enabled: true
mode: single

1 Like

Wouldn’t this mean your last steps are in the dark?
“Normally” light turns on if motion is detected, stays ‘on’ as long as there is motion and turns off when there is no montion anymore. This means you need an automation turning on the light if one of your two motion sensors detects montion and turn off the light when both sensors don’t dedect motion anymore…

No, right now when I pass the second motion sensor and I have exited the stairs a 1 minute timer starts before the light turns off.

The first part of the automation works as I intended it’s just the last 10 minute check that doesn’t work.

For anyone having the same problem here’s my solution:

I created a timer helper that starts a countdown when the light turns on. If any motion is detected then the timer is canceled. If no motion is detected and the timer runs out (10 min) then the light turns off.
Here’s the full code:

alias: Lidl motion sensor stairs
description: ""
trigger:
  - type: motion
    platform: device
    device_id: aa6b0932cb81fae0c6eb8cbcfa7fe979
    entity_id: binary_sensor.lidl_motion_sensor_up_occupancy
    domain: binary_sensor
    id: motion-up
  - type: motion
    platform: device
    device_id: 1ab4c3c77c28e426fb478d4f44be7a48
    entity_id: binary_sensor.lidl_motion_sensor_down_occupancy
    domain: binary_sensor
    id: motion-down
  - platform: event
    event_type: timer.finished
    event_data:
      entity_id: timer.motion_timer
    id: Timer-finished
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: motion-up
          - condition: device
            type: is_off
            device_id: 7ab757b64dc096a28c18b1c790b8f50a
            entity_id: light.lidl_light_1
            domain: light
        sequence:
          - type: turn_on
            device_id: 7ab757b64dc096a28c18b1c790b8f50a
            entity_id: light.lidl_light_1
            domain: light
          - service: timer.start
            data:
              duration: "600"
            target:
              entity_id: timer.motion_timer
      - conditions:
          - condition: trigger
            id: motion-down
          - condition: device
            type: is_off
            device_id: 7ab757b64dc096a28c18b1c790b8f50a
            entity_id: light.lidl_light_1
            domain: light
        sequence:
          - type: turn_on
            device_id: 7ab757b64dc096a28c18b1c790b8f50a
            entity_id: light.lidl_light_1
            domain: light
          - service: timer.start
            data:
              duration: "600"
            target:
              entity_id: timer.motion_timer
    default: []
  - choose:
      - conditions:
          - condition: trigger
            id: motion-up
          - condition: device
            type: is_on
            device_id: 7ab757b64dc096a28c18b1c790b8f50a
            entity_id: light.lidl_light_1
            domain: light
        sequence:
          - delay:
              hours: 0
              minutes: 1
              seconds: 0
              milliseconds: 0
            enabled: true
          - type: turn_off
            device_id: 7ab757b64dc096a28c18b1c790b8f50a
            entity_id: light.lidl_light_1
            domain: light
          - service: timer.cancel
            data: {}
            target:
              entity_id: timer.motion_timer
      - conditions:
          - condition: trigger
            id: motion-down
          - condition: device
            type: is_on
            device_id: 7ab757b64dc096a28c18b1c790b8f50a
            entity_id: light.lidl_light_1
            domain: light
        sequence:
          - delay:
              hours: 0
              minutes: 1
              seconds: 0
              milliseconds: 0
            enabled: true
          - type: turn_off
            device_id: 7ab757b64dc096a28c18b1c790b8f50a
            entity_id: light.lidl_light_1
            domain: light
          - service: timer.cancel
            data: {}
            target:
              entity_id: timer.motion_timer
      - conditions:
          - condition: device
            type: is_on
            device_id: 7ab757b64dc096a28c18b1c790b8f50a
            entity_id: light.lidl_light_1
            domain: light
          - condition: trigger
            id: Timer-finished
        sequence:
          - type: turn_off
            device_id: 7ab757b64dc096a28c18b1c790b8f50a
            entity_id: light.lidl_light_1
            domain: light
mode: single

1 Like

For ones having problems that the light is turning off while motion is detected:
You should start a timer to turn off the light when motion stops being detected (As a grace period, to see if new motion is detected shortly after).

You should not do it when it starts to detect motion. That is because when you start it when motion is detected, any repeated motion does not trigger a new event when the sensor still reports motion. So if the motion detect sensor stays on longer than the timer, the light will still go out, with motion being detected on.

1 Like

I also need your help urgently, I need to design a fully analogue circuit (no programmable components) that does this .As long as motion is detected within the specified time interval set by the timer, the countdown process continues to reset, and the bulb remains illuminated. Once no motion is detected for the entire duration of the countdown cycle, the timer’s output signal switches off, turning off the bulb.