I have an ESP8266 with a servo and a photoresistor with a digital out.
Both work fine Home Assistant can control the servo HA respond to light changes.
The HDMI state is the entity that reads which output is active on the switch so on or off means TV or Projector.
I have earlier got the following working with some help.
switch.sonoff_1000000000:
friendly_name: Kaffekokaren
templates:
icon: mdi:coffee-maker
icon_color: if (state === 'off') return '';
if (entities['counter.counter'].state == "0") return 'rgb(255, 0, 0)';
if (entities['counter.counter'].state == "1") return 'rgb(155, 100, 0)';
if (entities['counter.counter'].state == "2") return 'rgb(50, 200, 0)';
if (entities['counter.counter'].state == "3") return 'rgb(0, 255, 0)';
if (entities['counter.counter'].state == "4") return 'rgb(0, 155, 100)';
if (entities['counter.counter'].state == "5") return 'rgb(0, 50, 200)';
if (entities['counter.counter'].state == "6") return 'rgb(0, 0, 255)';
if (entities['counter.counter'].state == "7") return 'rgb(100, 0, 155)';
if (entities['counter.counter'].state == "8") return 'rgb(200, 0, 50)';
and this change the color of the icon.
I figured I could use the same with changing icon, so I tried the following:
script.1585736971040:
friendly_name: HDMI_Switch
assumed_state: false
templates:
icon: if (entities['binary_sensor.hdmi_state'].state === 'off') return 'mdi:projector';
if (entities['binary_sensor.hdmi_state'].state === 'on') return 'mdi:television-classic';
I have tried with if, else, with === or == and switching place with on and off state. It will only shows as ‘on’.
Even when I can see the state in the frontend saying off, the HDMI switch icon is not changed.
What I’m doing wrong?