Toggle (or turn off) a running script?

I have a script that runs a handful of fans and an AC on boost mode for 20 minutes, to rapidly decrease temperature. I have a Lovelace button that calls this script.

What I’d like is an ability to a) cancel running the script and b) return to the device states before running the script. B) is optional.

How can i do this? I was looking into script.toggle and script.turn_off but I’m not sure what these even do, they do not seem to do what I want. Thanks!

Runs the script if not running. Stops the script if running.

Cancels a running script.

Yes but what do these actually mean? They do not effect the running devices (the actual fans and AC at all). I understand those cancel the script so steps in the future do not trigger but how do I actually stop what’s happening and return to the pre-run state?

Exactly what I said. They stop or start a running script.

So you do understand. Why ask ask that first question?

By using the script.turn_off service.

That would require you storing the pre-run state. See creating scenes on the fly.

Thanks, so the Lovelace “toggle script” button would actually call scene.turn_on and script.turn_off services?

There is a caveat to stopping a running script. You can only stop or cancel a script which has a delay or wait in it. If your script is just a bunch of service calls the script will just execute and won’t give you a chance to cancel it.

Your pseudo code would be something like this:

- script:
  - name: cooling boost
  - scene.create
    - entity_id: climate.hvac
    - name: normal_cooling
  - climate.set_target
    - temperature: 
    - mode:
  - delay:
    - minutes: 20

- script:
  - name: resume schedule
  - script.turn_off
    - entity_id: script.cooling_boost
  - scene.restore
    - name: normal_cooling

Thanks, I’ll do it like this.

Hi folks, this is a really interesting moment with HA. Sure, as @tom_l says, script off makes sense and as @squirtbrnr says, if you trigger a bunch of services or turn on button helpers, these are different entities living their triggered state. What a blow on a head when designing a logic in your HA. So, the solution is to stop the script from executing next steps in the sequence AND (in my situation) if you do not want to have your house flooded, you must immediately shut down the valves that were triggered. Understandably…

Lovely! It’s better if the logic is so straightforward and do not presume our expectations…

1 Like