Variable Length Timers and Automation Delays

Hey everyone, I’m reaching out to share an experience I had with setting up automation in my smart home. I recently moved into a new apartment and decided to integrate some smart devices to make my life easier. One thing I’ve been experimenting with is automation delays, particularly with motion sensors.

I have a motion sensor in my office that turns on the lights when I walk in, and another in the staircase that turns them off when I leave. It’s been working well, but I noticed that sometimes when I step out for just a minute, the lights turn off too quickly. To address this, I added a two-minute delay to the automation that turns off the lights.

However, I ran into an issue where if I walked back into the office within those two minutes, the lights would still turn off after the delay had expired. I tried modifying the automation to cancel the delay when the motion sensor in the office detects movement again, but it hasn’t been working as expected.

I’ve been using the following setup:

yaml

  • id: ‘1608423397772’
    alias: office on with motion
    trigger:

    • platform: state
      entity_id: sensor.zooz_sensor_office_burglar_2
      to: ‘8’
      action:
    • type: turn_on
      entity_id: switch.office_light
  • id: ‘1610481877555’
    alias: turn off office if motion in staircase
    trigger:

    • platform: state
      entity_id: sensor.zooz_sensor_basement_staircase_burglar
      to: ‘8’
      action:
    • delay: ‘00:02:00’
    • type: turn_off
      entity_id: switch.office_light

I was hoping that adding the delay and then having the motion sensor in the office cancel it would solve the problem, but it doesn’t seem to be working. I’m wondering if there’s a better way to structure this automation so that the delay can be reset or canceled when I walk back into the office.

I’d love to hear if anyone else has tackled a similar issue or has suggestions on how to improve this setup. Automation can really enhance the convenience of a smart home, but getting the timing just right is tricky! Thanks in advance for any advice you can offer.