Ignore second script run

I have this script that I use when I go to bed to wait two minutes and then turn off all the lights:

alias: All lights off
sequence:
  - delay:
      hours: 0
      minutes: 2
      seconds: 0
      milliseconds: 0
  - service: light.turn_off
    data: {}
    target:
      entity_id:
        - light.maxcio_dimmer
        - light.osram_sylvania_zigbee_3_0_dali_conv_li_9ad2ce15_level_on_off
mode: single
icon: mdi:lightbulb-group-off

I put this script as a service button widget with script.turn_on on my home screen on Android.

It works fine the first time I start it, but if I forget whether I started it again and hit it a second time, it will take forever to confirm (turn into a green checkmark).

2022-10-22-07-03-43-PotPlayerMini64

I have a guess what might be happening. The docs (for automations, but I’m assuming scripts work the same way) mention that a warning is generated when a single script is run again:

image

I’m not sure how this “warning” is actually represented in the API, but maybe it causes the Android widget to think that starting the script wasn’t successful?

It wasn’t successful. You only allow one instance of the script to run at a time.

Change this:

mode: single

To:

mode: restart

If you want to restart the timer when you press the button again.

Otherwise change it to:

mode: parallel

This will not stop the first instance running so the timer continues, however a second instance is started. With the actions you have shown this should not be an issue (it will simple turn off light that are already off).

I don’t want the timer to restart when I press a second time. I also don’t want to start a second run because if I turn the lights back on after they are turned off, I want them to stay on.

Maybe I can use mode: parallel and then have a condition that the script only runs if it is not already running?