Motion Sensor, turn lights off

Hi,

I want a motion sensor to turn off the lights if it has not detected motion for 10 seconds.
If motion is detected again within these 10 seconds a check should only be carried out again if no motion has been detected for 10 seconds and so on.
This is to ensure that the light does not go out all the time when you stay in this area for a long time, but only when no one is there or no longer moves.
Here my code:

alias: Lichter Flur Bewegungsmelder aus
description: ''
trigger:
  - type: no_motion
    platform: device
    device_id: 111
    entity_id: binary_sensor.presence_65
    domain: binary_sensor
    for:
      hours: 0
      minutes: 0
      seconds: 20
      milliseconds: 0
condition:
  - condition: state
    entity_id: binary_sensor.presence_65
    state: 'off'
    for:
      hours: 0
      minutes: 0
      seconds: 10
      milliseconds: 0
action:
  - service: light.turn_off
    data: {}
    target:
      entity_id:
        - light.licht_flur_lo
        - light.licht_flur_lu
        - light.licht_flur_ro
        - light.licht_flur_ru
mode: single

If no more motion is detected within 20 seconds, this code works. But if motion is detected again, there is no further check.
How could this be solved?

I don’t quite understand the issue.
What’s wrong with using your current condition as the trigger, i.e. to plainly turn off the lights if no motion has been detected in 10sec?

So surely just make the automation turn off the lights if no motion is detected for x amount of time, I am not sure I understand the trigger and then the subsequent condition or what your trying to achieve?

alias: Lichter Flur Bewegungsmelder aus
description: ''
trigger:
  - platform: state
    entity_id: binary_sensor.presence_65
    from: 'on'
    to:  'off'
    for:
      seconds: 10
action:
  - service: light.turn_off
    data: {}
    target:
      entity_id:
        - light.licht_flur_lo
        - light.licht_flur_lu
        - light.licht_flur_ro
        - light.licht_flur_ru
mode: single
1 Like

This will only trigger after continuous uninterrupted no motion for 10 seconds. If movement is detected the timer starts again.

When I use this code:

alias: Lichter Flur Bewegungsmelder aus
description: ''
trigger:
  - type: no_motion
    platform: device
    device_id: 1234
    entity_id: binary_sensor.presence_65
    domain: binary_sensor
    for:
      hours: 0
      minutes: 0
      seconds: 0
      milliseconds: 0
condition: []
action:
  - service: light.turn_off
    data: {}
    target:
      entity_id:
        - light.licht_flur_lo
        - light.licht_flur_lu
        - light.licht_flur_ro
        - light.licht_flur_ru
mode: single

The lights go off when the motion sensor change the state to no motion. However, if a person is in this area, the light always goes out and you have to move again so that it comes on again. There is only one trigger: no motion
What I want: if the status of the motion sensor changes to no motion, wait 10 seconds to see whether motion is detected again. The light should then not go out. Then it takes another 2 minutes and the motion sensor changes back to no motion. Then it should be checked again whether someone is moving and so on.
With this code:

alias: Lichter Flur Bewegungsmelder aus
description: ''
trigger:
  - type: no_motion
    platform: device
    device_id: 1234
    entity_id: binary_sensor.presence_65
    domain: binary_sensor
    for:
      hours: 0
      minutes: 0
      seconds: 0
      milliseconds: 0
condition:
  - condition: state
    entity_id: binary_sensor.presence_65
    state: 'off'
    for:
      hours: 0
      minutes: 0
      seconds: 10
      milliseconds: 0
action:
  - service: light.turn_off
    data: {}
    target:
      entity_id:
        - light.licht_flur_lo
        - light.licht_flur_lu
        - light.licht_flur_ro
        - light.licht_flur_ru
mode: single

the light stays on.

Ok now I have found the problem. My aqara motion sensor did not change the status to on after changing it to off (no motion) when I use this code:

alias: Lichter Flur Bewegungsmelder aus
description: ''
trigger:
  - type: no_motion
    platform: device
    device_id: 1234
    entity_id: binary_sensor.presence_65
    domain: binary_sensor
    for:
      hours: 0
      minutes: 0
      seconds: 20
      milliseconds: 0
condition:
  - condition: state
    entity_id: binary_sensor.presence_65
    state: 'off'
    for:
      hours: 0
      minutes: 0
      seconds: 10
      milliseconds: 0
action:
  - service: light.turn_off
    data: {}
    target:
      entity_id:
        - light.licht_flur_lo
        - light.licht_flur_lu
        - light.licht_flur_ro
        - light.licht_flur_ru
mode: single

I have a other motion sensor from Ikea. I tried it with this one, and it works. But the Ikea motion sensor need 30seconds to go on after it goes off.
So I use:

alias: Lichter Flur Bewegungsmelder aus
description: ''
trigger:
  - type: no_motion
    platform: device
    device_id: 1234
    entity_id: binary_sensor.tradfri_motion_sensor
    domain: binary_sensor
    for:
      hours: 0
      minutes: 0
      seconds: 40
      milliseconds: 0
condition:
  - condition: state
    entity_id: binary_sensor.tradfri_motion_sensor
    state: 'off'
    for:
      hours: 0
      minutes: 0
      seconds: 30
      milliseconds: 0
action:
  - service: light.turn_off
    data: {}
    target:
      entity_id:
        - light.licht_flur_lo
        - light.licht_flur_lu
        - light.licht_flur_ro
        - light.licht_flur_ru
mode: single

Now the light is on a little too long, but it works.
Or is there another option?

Interesting video regarding the pros/cons/quirks of multiple motion sensors:

Cool Video, thank you.

Do I always nee a Hue bridge to use the Hue Motion Sensor with hassio?

No, using it directly via ZHA myself.

You can use this hack to reduce the time to 5 seconds

I had the same problem. Change mode: single to mode: restart
That does it. When the mode is “single” the motion sensor just starts counting down the set time. Even when he sees motion and licht turns off.
If set to “restart” the motion sensor start counting from beginning. When there is no motion in a set time. The lights goes off.

alias: Zolder verlichting uit
description: ‘’
trigger:

  • type: no_motion
    platform: device
    device_id: e05553bf1deb6d95ea48b4c349b6ef50
    entity_id: binary_sensor.zolder_sensor_motion
    domain: binary_sensor
    for:
    hours: 0
    minutes: 2
    seconds: 0
    milliseconds: 0
    condition: []
    action:
  • type: turn_off
    device_id: 55e134e83ca8518b82bafac1c9a4c69d
    entity_id: switch.aqara_1
    domain: switch
    mode: restart
2 Likes

Thank you very much @ all. I will test it.

Can we set multiple motion sensors on the trigger? like if we want to shutdown all the lights in the house? or should we put one trigger (example the closest one from the door.) and the remaining ones on conditions?

Yes I use multiple sensor and light toggles in one of my automations

- id: 'XXXXXXXXX'
  alias: Bar Lights - Turn on and off based on stairwell light.
  description: Turn on and off all the lights in the bar area
  trigger:
    - id: 'bar_on'
      platform: state
      entity_id: binary_sensor.bar_stairwell_motion_sensor_motion
      from: 'off'
      to: 'on'
    - id: 'bar_on'
      platform: state
      entity_id: binary_sensor.bar_main_motion_sensor_motion
      from: 'off'
      to: 'on'
    - id: 'bar_on'
      platform: state
      entity_id: switch.stairwell_light
      from: 'off'
      to: 'on'
    - id: 'bar_off'
      platform: state
      entity_id: binary_sensor.bar_main_motion_sensor_motion
      from: 'on'
      to: 'off'
      for: '00:01:30'
    - id: 'bar_off'
      platform: state
      entity_id: switch.stairwell_light
      from: 'on'
      to: 'off'
    - id: 'bar_off1'
      platform: state
      entity_id: binary_sensor.bar_stairwell_motion_sensor_motion
      from: 'on'
      to: 'off'
      for: '00:01:30'
  condition: []
  action:
  - choose:
    - conditions:
        - "{{ trigger.id == 'bar_on' }}"
      sequence:
        - service: switch.turn_on
          target:
            entity_id:
            - switch.area_cans
            - switch.bar_pool_table_light
            - switch.rope_lights
            - switch.bar_hall_to_media
            - switch.bar_landing
            - switch.stairwell_light
        - service: light.turn_on
          target:
            entity_id:
            - light.bar_pendant_light
            - light.bar_back_bar_cans
          data:
            brightness_pct: 50
    - conditions:
        - "{{ trigger.id == 'bar_off' }}"
      sequence:
        - service: switch.turn_off
          target:
            entity_id:
            - switch.area_cans
            - switch.bar_pool_table_light
            - switch.rope_lights
            - switch.bar_hall_to_media
            - switch.bar_landing
            - switch.stairwell_light
        - service: light.turn_off
          target:
            entity_id:
            - light.bar_back_bar_cans
            - light.bar_pendant_light
    - conditions:
        - "{{ trigger.id == 'bar_off1' }}"
        - "{{ states('binary_sensor.bar_main_motion_sensor_motion') == 'off' }}"
      sequence:
        - service: switch.turn_off
          target:
            entity_id:
            - switch.area_cans
            - switch.bar_pool_table_light
            - switch.rope_lights
            - switch.bar_hall_to_media
            - switch.bar_landing
            - switch.stairwell_light
        - service: light.turn_off
          target:
            entity_id:
            - light.bar_back_bar_cans
            - light.bar_pendant_light
    default: []
  mode: single
2 Likes

Hi. Have you solved with the Aqara motion sensor? Can you post the ultimate automation?

Hi,
I bought the motion sensors from Philips. They fixed the problem without additional settings.

Greetings