Motion,door sensor Automation extend delay

Hi all,

I got an automation which has multiple triggers, as of now 2 motion 1 door sensors and a wall switch.
when the trigger goes of it will turn on the light, start a delay of 5 minutes and turns the lights off. Not so difficult, and this works.

Only thing that is bothering me is dat when i stay in the room the motion sensor won’t retrigger until it clears. Most of the times i am not longer in the room then 5 minutes but when i do i need the automation to keep the lights on and extend the 5 minutes (or restart the automation till there is a clear)

I am not sure on how to make such a automation, hope some one can help me out. Thanks!! Current automation below:

alias: Ganglamp
description: ''
trigger:
  - platform: state
    entity_id: binary_sensor.door2_contact
    from: 'off'
    to: 'on'
  - platform: state
    entity_id: switch.voordeur_schakelaars_switch_l1
    from: 'off'
    to: 'on'
  - type: motion
    platform: device
    device_id: 77bee982c70d989779e277109e9b9004
    entity_id: binary_sensor.trap_beweging_occupancy
    domain: binary_sensor
  - type: motion
    platform: device
    device_id: e7577b34e61fe50055b171d21731cfc8
    entity_id: binary_sensor.lobby_beweging_occupancy
    domain: binary_sensor
condition: []
action:
  - service: switch.turn_on
    data: {}
    entity_id: switch.voordeur_schakelaars_switch_l1
  - type: turn_on
    device_id: c64f5a9433ebaf40a4dbdcef11a18ca0
    entity_id: switch.lobby_l1
    domain: switch
  - delay: '00:05:00'
  - service: switch.turn_off
    data: {}
    entity_id: switch.voordeur_schakelaars_switch_l1
  - type: turn_off
    device_id: c64f5a9433ebaf40a4dbdcef11a18ca0
    entity_id: switch.lobby_l1
    domain: switch
mode: restart

@djansen1987 it’s been a month but your post appears after a google search of the same topic so I will place a link that possibly answers the question. I have not implemented this case yet - the proximity sensors are waiting for soldering ( :unamused: ) but from my understanding you need to split the automation. The triggers for turning the lights on should stay as you have them now, but for turning it off you need to have a different trigger, see the docs here:

The light should turn off only if there is no motion detected for 5 minutes, and the time should be in the trigger not in the delay. Hope this helps.

1 Like

Hi Iknop,

Thanks for your reply. Will give it a try, and think this wil work. Only scenario i can tink of it would not work on is if the light is turned on by wall switch and no detection is triggered. In this scenario the light will never be turned off unless the wall switch is used again. But i can cover this scenario by building in a delay of say 30 min and then turn of the light just to be sure it is not left on.