Activate/on/off for script

Scripts with delay can, in theory be stopped while being executed, reason for which they appear as a switch rather than Activate (turning switch off is to cancel script execution).

You can have it show always as Activate / Switch, by using can_cancel: false / can_cancel: true in customize section of configuration.yaml.

6 Likes

For example, I have a script that turns on my fan, waits forty minutes, and then shuts it off. If I turn off the script itself during that time, the fan will stay on.

Thanks for this information. This makes sense i many cases. I will just use the customisation.

Hey,

i did it in my file, but still, i have on/ off only

switch.philips_tv:
  friendly_name: "Philips TV"
  can_cancel: true also / false

The example you were looking at was listing the two options for can cancel: which are true or false. So, because you don’t want to be able to cancel the script running, you should write your customize like this:

switch.philips_tv:
  friendly_name: "Philips TV"
  can_cancel: false

Yes i did it, still not working :frowning:

switch.philips_tv sounds like a switch, can_cancel is for scripts?

1 Like

my I do some think worng

where i need to add the can_cancel: ?

Because the switch.philips_tv is a switch, it can only be off or on. Perhaps you could do some custom UI thing to change it to say “activate / deactivate,” but the original poster’s problem was that he wanted a script to show only the activate button.

This link will be much more helpful in describing what a script is.

sorry :frowning: I still do not understand what I need to do I order to get a activate button …

i be happy if anyone can share me a code for sample

in your customize.yaml

script.script1:
  icon: mdi:timelapse
  can_cancel: false

yes, i did it… still did not show.

I’ll say it again. Those are switches not scripts.

As switches I assume they show a switch?

What are you trying to show? Please explain again!

never mind, Thanks… i will stay with on / off button .

Apologies for opening up an old thread but wasn’t sure if protocol is to open a new thread or add to existing thread on a topic.

I’m struggling to get can_cancel to work within my yaml configuration.

I have edited my configure.yaml and included the following code

homeassistant:
  customize: !include customize.yaml'

and also created a customize.yaml file and included the following code

script_heat_downstairs:
    can_cancel: false
    
script.1645352977749:
    can_cancel: true

Following a reboot I still get both scripts offer me the capability to both run and cancel. I thought the code would allow me to stop the first script being cancelled.

I had the same question myself after release 0.113.

Check here and here and the following posts/answers.

Hi @pplucky

Can for the quick response. I’ve read through the link you provided but I can’t seem to find out how I now stop a script being cancelled.

Currently I’m trying to setup a Lovelace button to run the script but not offer the option to cancel the run. I’m using a button entity and on the first click it runs the script but if the user clicks the button again it cancels the script. Any ideas how I can stop the script being cancelled if can_cancel has been removed as an option?

My understanding is that this is no longer possible, not sure exactly why, but probably due to the improvements/changes introduced in scripts from 0.113 on…

@pplucky - Thanks for pointing me at the latest documentation. I can see what they’ve done and now realise it’s how you call the script. I’ve now called the script using the following code and it works. First click runs the script and second click doesn’t do anything.

type: custom:button-card
entity: script.light_test
tap_action:
  action: call-service
  service: script.light_test
1 Like