Call script turn it off

Hi, I plan to use a script for a delay counter in order to keep a light on some time after movement.
Each movement trigger a PIR and its signal is handled into one automation task to call a script to delay the light off:
movement -> PIR -> Start delay counter -> Light off
The test code is:

[code]…
automation:

  • alias: ‘test_start’
    trigger:
    platform: state
    entity_id: switch.sw3
    state: ‘on’
    action:
    service: script.turn_on
    entity_id: script.test

    script:

    test:
    alias: test_delay
    sequence:
    - delay:
    minutes: 1
    …[/code]
    The first PIR signal call the delay script ok, but the second signal coming during the delay interval just switch off the script.
    I think this behavior is not normal, because there is no script.turn_off , I expect it to start the delay script again.

Activating a script that is in a delay will skip the delay and move to the next step. This is expected behavior. In your case, you want to turn the script off first.

1 Like

Thank you! I have tested also with two delays and indeed, it moves from the first delay to the next one then outside from that second delay.
The solution is to have another script that turn the scrip off, then on again.