Template Switch - value_template HELP

Hello, I am trying to create a switch that will activate my ‘on’ script when turned on, and then my ‘off’ script when turned off. I just want a switch that will activate my on command when I turn it on, and my off command when I turn it off. I doesn’t need to have a known state as the device it is activating doesn’t report back its state. Below is the config I have created so far which works to a point, but its just the state issue…

 platform: template
  switches:
sidelight:
 value_template: ??????? 
 turn_on:
   service: script.side_lights_on
   entity_id: script.side_lights_on
 turn_off:
    service: script.side_lights_off
    entity_id: script.side_lights_off

Bump, Anyone have any tips?

What does your script entail?

It may be easier to put the lights in a group and add that group to your front end. The group will have a switch associated with it.

If the script is only switching lights you could add them all to a group and that group would report on if any one of the lights is on and off if all the lights are off. Not sure if that would work for you. Then your value template could check the status of that group for your value template.

Thanks for the reply. I managed to achieve what I wanted with an automation and an input boolean. The switch is to activate a script which sends a maker web request through IFTTT to turn on my LightwaveRF lights which aren’t supported with HA just yet.

Hi Jack,

Did you have the code for that? trying to do the same thing.

Thanks

Hi Mark, Sorry don’t have this code anymore. Cant remember off the top of my head what I did. I got a Broadlink Pro in the end, to send RF commands to the Lightwave RF switches.

No problem, thanks anyway

Tying an input boolean to your template switch should do the trick. I’ll post an example of mine, but basically you turn the template on and off with the switch that way you can use the boolean for the value_template section. Only make sure the boolean doesn’t have the “initial” option set in your config.

  master_bedroom_motion:
    value_template: "{{ is_state('input_boolean.master_bedroom_motion', 'on') }}"
    turn_on:
      - service: input_boolean.turn_on
        entity_id: input_boolean.master_bedroom_motion
    turn_off:
      - service: input_boolean.turn_off
        entity_id: input_boolean.master_bedroom_motion
      - service: light.turn_off
        entity_id: light.bedroom_lights
        data:
          transition: 1
      - service: light.turn_off
        entity_id: light.bedroom_lamps
        data:
          transition: 1
1 Like

Thanks! This helped me a lot when trying to control my heat pump that has dedicated on and off commands even though there is only one power button.