Why do some scripts have a toggle switch rather than "EXECUTE" text?

Can any one tell me why some of my scripts appear with a switch-style toggle, yet most appear with clickable “Execute” text?

54

As far as I can tell, there’s nothing remarkable about the YAML for any of them. I can’t see a difference.

Here’s the YAML for “Watch Chromecast”:

livingroom_videocast:
  alias: 'Living room videocast'
  sequence:
    - service: homeassistant.turn_on
      entity_id:
        - switch.livingroom_tv_power
        - media_player.livingroom_amp
    - service: media_player.select_source
      data:
        entity_id: media_player.livingroom_amp
        source: 'Videocast'

And here’s “Nighttime bathroom lighting”:

nighttime_bathroom_lighting:
  alias: Nighttime bathroom lighting
  sequence:
    - service: homeassistant.turn_on
      data:
        entity_id:
          - light.livingroom_light
    - delay: "00:10:00"
    - service: homeassistant.turn_off
      data:
        entity_id:
          - light.livingroom_light

I figured it out. Should have done some digging before asking here, but maybe this will be of interest to others.

I checked out the dev-state page and found that it was adding a “can_cancel: true” property to the state of the script. I believe it is adding this automatically to any script that has a “delay” in it. Kind of makes sense. Lets you cancel the script in the middle of its execution by turning off the toggle.

4 Likes

If they have a wait time, or pause time, that’s what I found

Usually I’m not the RTFM type of guy, but if you would’ve read the second last sentence on the script component page, it would have spared you some time. :wink:

Reading the documentation is a last resort! :slight_smile:

i just add a 1 second timer to the script so they all look the same, just for esthetics.

If it’s really just for aesthetics, you could also use the can_cancel attribute in the customize section of the script definition and set it to true or false:

  my_uninterruptable_script:
    customize:
      - can_cancel: false
    sequence:
      - service: light.turn_on
    [...]

If you do this, script won’t even load as there is no such thing as customize section in the script definition.
This needs to be done in customize.yaml.

script.script_name:
  can_cancel: false
1 Like

You are right, thanks for the correction. I can’t remember anymore, but obviously I mixed up something while writing the reply. :thinking:

A bit of an old thread, but on 0.105.2 I’m finding that the toggle switch only stays ‘on’ for a few seconds, even though I’ve got a WAIT statement in there.

And before you ask - no, the wait statement isn’t being evaluated as True after a few seconds, it can take up to 120 :slight_smile:

I think for neatness I’ll just add the 'can cancel:false" flag to all my scripts that have toggles.

I noticed this after upgrading from 0.84 to 0.103

I believe a bug report has been raised to correct it

1 Like

I’ve just updated to 2021.1.4. Earlier, last year, seeing this thread, I’ve added a delay to one of my scripts to show a switch instead of the nonsensical (from human UI standpoint) EXECUTE text.

In this version it stopped showing the switch icon, instead it always shows EXECUTE. Did something change in this version? Is this a bug? Can I change my config so it always shows a switch on the panel?