Dummy switch to run Script

Hi,

I am trying to create an on/off switch which will run a script at each position.

Any help would be great.

Thanks

Do you mean a HA script? Then use the Template Switch.
For bash/python scripts, use the Command line switch.

1 Like

Thanks, but which value template do I use?

  switches:
    bedroom_light:
       value_template: "{{is_state('group.all_switches', 'on') or is_state('group.all_switches', 'off')}}"
        turn_on:
          service: script.turn_on
          entity_id: script.bedroom_on
        turn_off:
          service: script.turn_off
          entity_id: script.bedroom_off

You need a template that returns True (switch = on) or False (switch = off).

Sorry, how do I do that? New to this whole thing

For example, when your script.turn_off turns a light off.
"{{ is_state('light.whatever_01', 'on') }}" will return False and the switch is off.

What if the script you want to run has no need to be tied to the state of a particular device? Maybe it’s just sending a notification of the current weather or something?

Is there really no way to put a button in the UI that simply runs a script?

Just add the script to your UI and you get an Activate button?

If you want a simple toggle, you can also use the input_boolean component. Simply define your boolean switch, add it to your template, then add an automation for each state. There are some simple examples in the Input Boolean docs

1 Like