Switch Template with Boolean Toggle

I have an IR Blaster that doesn’t have an on/off function, just an action. I’m trying to create a switch that will show on/off by input_boolean.toggle but I can’t figure it out

switch:
  - platform: template
    switches:
      space_heater:
        value_template: "{{ is_state('input_boolean.ir_heater_onoff', 'on') }}"
        turn_on:
          service: scene.turn_on
          target:
            entity_id: scene.xgzu9izdfgwmqqj4
          service: input_boolean.toggle
          data:
            entity_id:input_boolean.ir_heater_onoff
        turn_off:
          service: scene.turn_on
          target:
            entity_id: scene.xgzu9izdfgwmqqj4
          service: input_boolean.toggle
          data:
            entity_id:input_boolean.ir_heater_onoff
switch:
  - platform: template
    switches:
      space_heater:
        value_template: "{{ is_state('input_boolean.ir_heater_onoff', 'on') }}"
        turn_on:
          - service: scene.turn_on
            entity_id: scene.xgzu9izdfgwmqqj4
          - service: input_boolean.toggle
            entity_id: input_boolean.ir_heater_onoff
        turn_off:
          - service: scene.turn_on
            entity_id: scene.xgzu9izdfgwmqqj4
          - service: input_boolean.toggle
            entity_id: input_boolean.ir_heater_onoff
1 Like

Going crazy here. I got yours above working and used it as a roadmap to build two others. Now only the third one is working (Soundbar Mute Switch). The first two aren’t even showing under my entities, whereas the last one is. Pulling my hair out here!

## IR Blaster Switch heater ##
switch:
  - platform: template
    switches:
      space_heater:
        value_template: "{{ is_state('input_boolean.ir_heater_onoff', 'on') }}"
        turn_on:
          - service: scene.turn_on
            entity_id: scene.xgzu9izdfgwmqqj4
          - service: input_boolean.toggle
            entity_id: input_boolean.ir_heater_onoff
        turn_off:
          - service: scene.turn_on
            entity_id: scene.xgzu9izdfgwmqqj4
          - service: input_boolean.toggle
            entity_id: input_boolean.ir_heater_onoff

## TV Power Switch ##
switch:
  - platform: template
    switches:
      tv_power_onoff:
        value_template: "{{ is_state('input_boolean.tv_onoff', 'on') }}"
        turn_on:
          - service: scene.turn_on
            entity_id: scene.wx8clarfb9kvriot
          - service: input_boolean.toggle
            entity_id: input_boolean.tv_onoff
        turn_off:
          - service: scene.turn_on
            entity_id: scene.wx8clarfb9kvriot
          - service: input_boolean.toggle
            entity_id: input_boolean.tv_onoff

## Soundbar Mute Switch ##
switch:
  - platform: template
    switches:
      soundbar_mute_onoff:
        value_template: "{{ is_state('input_boolean.tv_muted', 'on') }}"
        turn_on:
          - service: scene.turn_on
            entity_id: scene.ytfelxgcqixfnile
          - service: input_boolean.toggle
            entity_id: input_boolean.tv_muted
        turn_off:
          - service: scene.turn_on
            entity_id: scene.ytfelxgcqixfnile
          - service: input_boolean.toggle
            entity_id: input_boolean.tv_muted
switch:
  - platform: template
    switches:
      ## IR Blaster Switch heater ##
      space_heater:
        value_template: "{{ is_state('input_boolean.ir_heater_onoff', 'on') }}"
        turn_on:
          - service: scene.turn_on
            entity_id: scene.xgzu9izdfgwmqqj4
          - service: input_boolean.toggle
            entity_id: input_boolean.ir_heater_onoff
        turn_off:
          - service: scene.turn_on
            entity_id: scene.xgzu9izdfgwmqqj4
          - service: input_boolean.toggle
            entity_id: input_boolean.ir_heater_onoff

      ## TV Power Switch ##
      tv_power_onoff:
        value_template: "{{ is_state('input_boolean.tv_onoff', 'on') }}"
        turn_on:
          - service: scene.turn_on
            entity_id: scene.wx8clarfb9kvriot
          - service: input_boolean.toggle
            entity_id: input_boolean.tv_onoff
        turn_off:
          - service: scene.turn_on
            entity_id: scene.wx8clarfb9kvriot
          - service: input_boolean.toggle
            entity_id: input_boolean.tv_onoff

      ## Soundbar Mute Switch ##
      soundbar_mute_onoff:
        value_template: "{{ is_state('input_boolean.tv_muted', 'on') }}"
        turn_on:
          - service: scene.turn_on
            entity_id: scene.ytfelxgcqixfnile
          - service: input_boolean.toggle
            entity_id: input_boolean.tv_muted
        turn_off:
          - service: scene.turn_on
            entity_id: scene.ytfelxgcqixfnile
          - service: input_boolean.toggle
            entity_id: input_boolean.tv_muted

Or, if you want to be a real yaml ninja and save a few lines…

switch:
  - platform: template
    switches:
      ## IR Blaster Switch heater ##
      space_heater:
        value_template: "{{ is_state('input_boolean.ir_heater_onoff', 'on') }}"
        turn_on: &space_heater 
          - service: scene.turn_on
            entity_id: scene.xgzu9izdfgwmqqj4
          - service: input_boolean.toggle
            entity_id: input_boolean.ir_heater_onoff
        turn_off: *space_heater

      ## TV Power Switch ##
      tv_power_onoff:
        value_template: "{{ is_state('input_boolean.tv_onoff', 'on') }}"
        turn_on: &tv_power
          - service: scene.turn_on
            entity_id: scene.wx8clarfb9kvriot
          - service: input_boolean.toggle
            entity_id: input_boolean.tv_onoff
        turn_off: *tv_power

      ## Soundbar Mute Switch ##
      soundbar_mute_onoff:
        value_template: "{{ is_state('input_boolean.tv_muted', 'on') }}"
        turn_on: &soundbar
          - service: scene.turn_on
            entity_id: scene.ytfelxgcqixfnile
          - service: input_boolean.toggle
            entity_id: input_boolean.tv_muted
        turn_off: *soundbar
1 Like

And another solution…Yaml whisperer, indeed! I owe you a beer! Thank you, sir!

1 Like

What are the & and * operators? I am not familiar w/ them and I cant find them documented anywhere

That’s just shorthand. In other words noting that we’re taking about the sound bar, for example, (&), and then to repeat the above YAML (*), adjusting for off instead of on.

where is this documented?

It’s nothing official

Is it possible to create a button with these functions?

  • button pressed > activates/deactivates a switch entity with 1 sec delay (on/off)
  • for 60 seconds > the button cannot be pressed (inhibited)
  • after 60 seconds > button can be pressed again