Create a switch out of scenes

Sorry but I wasn’t sure whether it’s best to post an entirely new comment, or revive one from June 2017.

I’m trying to make two scenes (fan off, fan on) appear as one on/off switch, however it doesn’t seem to be holding the value of on or off and appears as off after about 3 seconds. My config is as follows:

switch:
  - platform: template
    switches:
      bedroom_fan:
        #value_template: "{{ is_state('bedroom_fan', 'on') }}"
        turn_on:
          service: scene.turn_on
          entity_id: scene.bedroom_fan_on
        turn_off:
          service: switch.turn_on
          entity_id: scene.bedroom_fan_off

I’ve tried various “value_template” settings to no avail, I have a strong feeling this is because nothing exists to hold the value as on / off. Any idea how I can solve this?

You could add an action at the end of the two script to turn on/off an input boolean and then use this input_boolean to determine the state of the fan.

1 Like

This sounds like a fantastic idea, and I should be able to implement this by using scripts instead of scenes. Thanks for the keywords to search for, I’ll post back when I have a solution in case anyone else needs it.

You are a genius my friend. I have no idea if my yaml is efficient, but it works perfectly.

input_boolean:
  bedroom_fan:
    name: bedroom_fan
    initial: off

script:
  bedroom_fan_on:
    sequence:
      - service: input_boolean.turn_on
        data:
          entity_id: input_boolean.bedroom_fan
      - service: scene.turn_on
        data:
          entity_id: scene.bedroom_fan_on
  bedroom_fan_off:
    sequence:
      - service: input_boolean.turn_off
        data:
          entity_id: input_boolean.bedroom_fan
      - service: scene.turn_on
        data:
          entity_id: scene.bedroom_fan_off

switch:
  - platform: template
    switches:
      bedroom_fan:
        value_template: "{{ is_state('input_boolean.bedroom_fan', 'on') }}"
        turn_on:
          service: script.turn_on
          entity_id: script.bedroom_fan_on
        turn_off:
          service: script.turn_on
          entity_id: script.bedroom_fan_off
1 Like

Hi friends, If i have one scene. Is it possible? And if so, can you write me the code please?