Script delay(timer)- Can it be reset?

Hi,

I would like to reset a script delay on sensor event, is that possible somehow?

This is what I’m trying to do
I’m trying to handle lights so they stay on when someone is in a room. So when motion is triggered I start a “lamp off” script with a 2min delay. On repeated motion I would like to just reset the delay, not run the whole sequence.

This is a simplified snipped of my current code

script:
  bathroom_day_timer_on:
    sequence:
      - service: script.turn_off
        data:
           entity_id: script.bathroom_timer_off
      - service: light.turn_on
        data:
          entity_id: group.bathroom
          brightness: 240
          rgb_color: [ 209, 104, 30 ]
      - service: script.turn_on
        data:
          entity_id: script.bathroom_timer_off

  bathroom_timer_off:
    sequence:
      - delay:
          minutes: 1
      - service: light.turn_off
        data:
          entity_id: group.bathroom

hey @ZyberSE,

I use this script:

  timed_lamp:
    alias: "Turn on lamp and set timer"
    sequence:
      # Cancel ev. old timers
      - service: script.turn_off
        data:
        entity_id: script.timer_off
      - service: switch.turn_on
        data:
        entity_id: switch.light1
     # Set new timer
     - service: script.turn_on
       data:
       entity_id: script.timer_off
  timer_off:
    alias: "Turn off lamp after 10 minutes"
    sequence:
      - delay:
        minutes: 10
      - service: switch.turn_off
        data:
        entity_id: switch.light

when a momement is detected first stop the countdown, turn on the light and activate countdown … this fires everytime a movement is detected by one motion sensor.

I think is what you need.

BTW: I took this from the community … Can’t remember where … credits to the original author :blush:

3 Likes

Was it this one? I seem to remember this too, but I can’t be sure:

it might be …

Also I see it’s in the examples section: https://home-assistant.io/cookbook/turn_on_light_for_10_minutes_when_motion_detected/

1 Like

Thanks! Thats the script I modified :slight_smile:

But that will send all commands again at repeted motion, that makes my sonos units go mute for a sec which I would like to avoid.

hmmm … hold on :slight_smile:

I thought it was a lighting script for the bathroom, what’s sonos doing in all this?

are you interacting with Sonos in your script?

I am thinking he is having the same issue as me. All my scripted automatons fire every time it is reset. I am having an issue with some other automatons not running now since they keep getting reset. When I force my sensor to 1 using set state it will reset and fire all my scripts that are just verbal commands (which I do not want) and turn on the light then like its supposed to.

I am currently trying to figure out how to get it to reset the script without messing with the other scripts. I am putting the entity after the as well.

This is causing my Away/Home automations (turn all lights on/ off) to not fire.

Because I have Play:1’s in my bathrooms :smiley:

Sorry if this is off topic since the title is about resetting script delays and I’m referencing an automation. I never got feedback on whether this worked or not so I’m not sure if it does because it calls brightness and RGB color while sending the turn off command but maybe you could try something like…