Add delay and reset timer

Hi I have a motion sensor in office which turns on lights when I walk in.
I have a motion sensor in staircase.

I have the following set up so when I walk into the office the lights go on
when I go towards staircase the office light goes off.

Problem is evertime I walk out of the office the lights close which is ok but sometimes I only leave for a minute. so wanted to add a delay.

I added delay in the turn off office automation which worked. But problem is even though I walk back into the office within the 2 minutes the light closes 2 minutes later.

would like to modify the automation so that when I walk back into my office and the motion sensor in office sees me it cancels the 2 minute off cycle.

this is what I have

- id: '1608423397772'
  alias: office on with motion
  description: ''
  trigger:
  - platform: state
    entity_id: sensor.zooz_sensor_office_burglar_2
    to: '8'
  condition: []
  action:
  - type: turn_on
    device_id: f9da103eb77c412cbb080627e0ec9328
    entity_id: switch.office_light
    domain: switch
  mode: single
- id: '1610481877555'
  alias: turn off office if motion in staircase
  description: ''
  trigger:
  - platform: state
    entity_id: sensor.zooz_sensor_basement_staircase_burglar
    to: '8'
  condition: []
  action:
  - delay: '00:02:00'
  - type: turn_off
    device_id: f9da103eb77c412cbb080627e0ec9328
    entity_id: switch.office_light
    domain: switch
  mode: single

You need a 3rd automation and a Timer. You can create a timer in the UI as “helper”. Then:

  • in your automation entering office, cancel that timer as an additionally action
  • in your automation for entering the staircase, remove the delay. Instead start the timer
  • in an additional automation, turn off lights in office when timer finishes.

Great ideas ,I will try that tomorrow. Need to read up on timers since I never used before.
Hopefully it will go smoothly.
Thanks for the reply

Try this modified version of your second automation:

- id: '1610481877555'
  alias: turn off office if motion in staircase
  description: ''
  trigger:
  - platform: state
    entity_id: sensor.zooz_sensor_basement_staircase_burglar
    to: '8'
  condition: []
  action:
  - wait_for_trigger:
    - platform: state
      entity_id: sensor.zooz_sensor_office_burglar_2
      to: '8'
    timeout: '00:02:00'
  - choose:
    - conditions: "{{ wait.trigger == none }}"
      sequence:
      - service: switch.turn_off
        entity_id: switch.office_light
  mode: single

It is triggered the same way as your original automation, when the staircase motion sensor detects your presence. After that it waits for the office motion sensor to trigger. It waits a maximum of 2 minutes for the office motion sensor to trigger.

  • If it does not trigger within 2 minutes (meaning you never returned to the office) then wait.trigger is none and the office light is turned off.
  • If it does triggers within 2 minutes (meaning you returned to the office) then wait.trigger is not none and the office light is not turned off.

Elegant. Did not know about the „wait for trigger“ option.

wow , just tried and works great , exactly what I needed. Thanks much appreciated.

1 Like

I’m pleased to hear it works and meets your requirements.

Please consider marking my post (above) with the Solution tag. It will automatically place a check-mark next to the topic’s title. This signals to other users that this topic has an accepted solution. It will also place a link below your first post that leads directly to the Solution post.

All of this helps other users find answers to similar questions.

1 Like