Trying to make a switch that calls a script

Hi All,

I’m trying make a switch that calls a script (so I can use it with emulated hue), but I’m not sure how to get there. It looks like a command_line switch is the way to go, but I can’t find the syntax to use to call the script.

This is what I’ve got, but I’m pretty sure the command_on & command_off calls are wrong. The scripts when activated via the front end do work.

switch:
    platform: command_line
    switches:
      bedtime:
        command_on: script.bedtime_on
        command_off: script.bedtime_off

I am not familiair with the command line switch, but one way to get it working is by combining an input_boolean and a template switch:

input_boolean:
  toggle_switch:
   name: Hue

switch:
  - platform: template
    switches:
      bedtime_onoff:
        value_template: "{{ is_state('input_booelan.toggle_switch', 'on') }}"
        turn_on:
          service: script.turn_on
          entity_id: script.bedtime_on
        turn_off:
          service: script.turn_on
          entity_id: script.bedtime_off
1 Like

Thanks for the suggestion NJB. I tried your suggestion, but got an error in the log:

homeassistant.components.switch.template: Received invalid switch is_on state: none. Expected: on, off, true, false

In the frontend the bedtime_onoff switch is unavailable

A typo there, my bad. Should be input_boolean.toggle_switch.
You can check the state of the switch at the developer tools, states.

Ugh, I should have caught that! Thanks heaps NJB, that worked :smiley: