Another Switch Template question

Hi,
I am looking for some help regarding a switch template and the subsequent switch state.

I am no programmer and have pieced bits together to create a switch from a template that runs two scripts, the first turns on the console including TV, Soundbar, Sky box and sets the channel to a set channel. Many of these items are switched on via IR using a broadlink RM Pro. The second script switches everything off.

So I have a switch template, input boolean and the scripts.

What I am trying to do is tidy up my dashboard using entity mushroom cards, with the icon colour changing when the state changes from off to on. The problem I have is that by default the switch state is on and regardless of whether the switch is on or off it never changes. I tested the icon changing by setting the state in the developer tools section. However with the switch it leaves the icon lit on the dashboard. Is there any way to change the switch state to off when the off script is triggered and on when the on script is run.

The switch works other than the state changing. Please go easy on me as I’m miles out of my depth here.

The code is as follows:

In boolean.yaml

   entertainment:
     name: System
     initial: on

In broadlink.yaml (my switches)

  - platform: template
    switches:
      console:
        value_template: "{% if is_state('input_boolean.entertainment', 'on') %}on{% else %}off{% endif %}"
        turn_on:
          service: script.turn_on
          entity_id: script.console_on
        turn_off:
          service: script.turn_on
          entity_id: script.1577541085737

This is my console on script as an example

alias: Console On
sequence:
  - condition: state
    entity_id: switch.sonoff_100184f911
    state: "off"
  - service: switch.turn_on
    data: {}
    target:
      entity_id:
        - switch.sonoff_100184f911
  - delay:
      hours: 0
      minutes: 0
      seconds: 3
      milliseconds: 0
  - service: switch.turn_on
    data: {}
    target:
      entity_id: switch.curve
  - service: switch.turn_on
    data: {}
    target:
      entity_id: switch.hdmi_1
  - delay:
      hours: 0
      minutes: 1
      seconds: 45
      milliseconds: 0
  - service: remote.send_command
    data:
      device: Stream
      command: power
      delay_secs: 0.9
    target:
      entity_id: remote.broadlink3
    enabled: true
  - delay:
      hours: 0
      minutes: 0
      seconds: 5
      milliseconds: 0
  - service: remote.send_command
    data:
      device: Stream
      command: left
      delay_secs: 1
    target:
      entity_id: remote.broadlink3
    enabled: true
  - service: remote.send_command
    data:
      device: Stream
      command: select
      delay_secs: 1
    target:
      entity_id: remote.broadlink3
    enabled: true
  - service: remote.send_command
    data:
      device: Stream
      command: 3
      delay_secs: 1
    target:
      entity_id: remote.broadlink3
    enabled: true
  - delay:
      hours: 0
      minutes: 0
      seconds: 3
      milliseconds: 0
    enabled: true
  - service: switch.turn_on
    data: {}
    target:
      entity_id: switch.sky_cooling_fans
  - delay:
      hours: 0
      minutes: 0
      seconds: 1
      milliseconds: 0
    enabled: true
  - service: switch.turn_on
    data: {}
    target:
      entity_id: switch.sound
    enabled: true
mode: single
icon: mdi:power-cycle

Thanks for any advice/help.

Paul.

Change this:

value_template: "{% if is_state('input_boolean.entertainment', 'on') %}on{% else %}off{% endif %}"

To this:

value_template: "{{ is_state('input_boolean.entertainment', 'on') }}"

Thanks I’ll give it a try and report back tomorrow.

Hi Tom,

I tried this and I couldn’t get the state to change, however I removed the line altogether and it now seems to work. I’ve checked the state in dev tools and the state changes as expected when the switch is on and off. As it is working I’ll leave it there. Thanks for your input.

Paul