Script delay and activation knob

I’ve made a simple script that contains a delay to show a switch icon instead of the “EXECUTE” text on the LL card and to align it with the behavior of my actual MQTT payload (a Tasmota RF command for a Sonoff RF Bridge). The relevant script config:

    - service: mqtt.publish
        topic: "sonoff-rf-1/cmnd/backlog"
        payload: "rfraw AA B0 15 ... 55; delay 50"
    - delay: 00:00:05

Now when I click/push the switch that appears in the card, it sends the MQTT message, and then in about a second the switch slides back to its initial position. What I want (and what I thought it works like) is to have it slide back when it has executed the full script, which would be 5 seconds. Also, as bonus, and if possible, I want to disable/gray out the switch icon somehow to prevent it from being clicked on while the script runs. This is because the gate controlled via RF can’t take subsequent commands within about 5 seconds.

Is there a simple solution for this? Am I doing it the right way in HA?

That is not possible. The whole reason for that toggle switch is to cancel scripts that are waiting in delays.

Not sure why your switch is returning to off after 1sec. It should definitely be on for the whole delay time. Try the delay with quotes like this:

delay: "00:00:05"

I would use an input_boolean and two automations.

When you turn on the input_boolean, it triggers both automations.

  • The first automation immediately publishes the payload.
  • The second automation contains a for: '00:00:05' so it waits 5 seconds before it turns off the input_boolean.
1 Like

@tom_l: Thanks. Adding the quotes unfortunately didn’t help. The test for this I’ve set up looks like this:

In scripts.yaml:

    - delay: "00:00:05"

In ui-lovelace.yaml:

          - entity: script.test_script
            name: "Test script"
            icon: mdi:repeat

Clicking the switch slides it to ON position, and then after about 2 seconds, it slides back by itself. Meanwhile the script should still be running for about 3 more seconds. Does it seem like a bug?

It does sound like a bug.

@123: Thanks, if all else fails, I’ll think about something like this.

The bug report is here for reference:

what LL card are you using? I couldn’t find any switch in docs…

A script with a delay or wait template in it will display a switch instead of ‘EXECUTE’ when listed as an entity in any Lovelace card.

1 Like

The link you did not know in that pull request ( Component/platform:) should be:

You can edit it and include it.