One-touch script on/off

Hi,

Im trying to make a card (glance) that toggles a script on/off but I want to show the state of the script on the card, just like any of glance card would show. Currently, the switch is only every showing “off” and everytime I click it, it only executes the “sonos_lazy_sunday” script.

These are the scripts

sonos_lazy_sunday:
  alias: "Lazy Sunday"
  sequence:
    - service: media_player.sonos_join
      data:
        master: media_player.sonos_office
      entity_id:
        - media_player.sonos_lounge
        - media_player.sonos_bedroom
    - service: media_player.volume_set
      entity_id:
        - media_player.sonos_office
        - media_player.sonos_lounge
        - media_player.sonos_bedroom
      data:
        volume_level: 0.15
    - service: media_player.select_source
      entity_id: media_player.sonos_office
      data:
        source: "Lazy Sunday"

sonos_off:
  alias: "Sonos Off"
  sequence:
    - service: media_player.turn_off
    - service: media_player.sonos_unjoin

This is the switch

# One-Touch Scenes
- platform: template
  switches:
    sonos_lazy_sunday:
      value_template: "{{ is_state('input_boolean.toggle_switch', 'on') }}"
      turn_on:
        - service: script.sonos_lazy_sunday
      turn_off:
        - service: script.sonos_off

This is the input_boolean

toggle_switch:
  name: Sonos Lazy Sunday

UI

all fixed. Didnt need any “input_boolean” or anything fancy. This is all I needed. Ive since learnt that the “value_template” is basically what is determining on/off :slight_smile: in this case, the Media Player “playing”.

Switch

- platform: template
  switches:
    sonos_lazy_sunday:
      value_template: "{{ is_state('media_player.sonos_office', 'playing') }}"
      turn_on:
        - service: script.sonos_lazy_sunday
      turn_off:
        - service: script.sonos_off

Script

sonos_lazy_sunday:
  alias: "Lazy Sunday"
  sequence:
    - service: media_player.sonos_join
      data:
        master: media_player.sonos_office
      entity_id:
        - media_player.sonos_lounge
        - media_player.sonos_bedroom
    - service: media_player.volume_set
      entity_id:
        - media_player.sonos_office
        - media_player.sonos_lounge
        - media_player.sonos_bedroom
      data:
        volume_level: 0.15
    - service: media_player.select_source
      entity_id: media_player.sonos_office
      data:
        source: "Lazy Sunday"

sonos_off:
  alias: "Sonos Off"
  sequence:
    - service: media_player.turn_off
    - service: media_player.sonos_unjoin