I’m trying to have my sensor icons change color based on their state (online/offline)
Those sensors are binary sensors using ping platform:
> # Ping sensors
> - platform: ping
> host: 192.168.1.254
> name: sfpfsense
> count: 2
> scan_interval: 30
>
> - platform: ping
> host: 192.168.1.15
> name: hp_printer
> count: 2
> scan_interval: 30
>
> - platform: ping
> host: 192.168.1.10
> name: sfserver
> count: 2
> scan_interval: 30
>
> - platform: ping
> host: 192.168.1.11
> name: hdhomerun
> count: 2
> scan_interval: 30
>
> - platform: ping
> host: 192.168.1.35
> name: sonosonebureau
> count: 2
> scan_interval: 30
>
> - platform: ping
> host: 192.168.1.253
> name: sfap
> count: 2
> scan_interval: 30
Then, in sensor.yaml (to use “online” and “offline” instead of on/off):
> # sensor template for LAN devices
> - platform: template
> sensors:
> sfserver:
> value_template: '{% if is_state("binary_sensor.sfserver", "on") %} Online {% else %} Offline {%- endif %}'
> friendly_name: sfserver
> sfpfsense:
> value_template: '{% if is_state("binary_sensor.sfpfsense", "on") %} Online {% else %} Offline {%- endif %}'
> friendly_name: sf-pfsense router
> hp_printer:
> value_template: '{% if is_state("binary_sensor.hp_printer", "on") %} Online {% else %} Offline {%- endif %}'
> friendly_name: Imprimante HP
> sonos_one_bureau:
> value_template: '{% if is_state("binary_sensor.sonosonebureau", "on") %} Online {% else %} Offline {%- endif %}'
> friendly_name: Sonos One Bureau
> hdhomerun:
> value_template: '{% if is_state("binary_sensor.hdhomerun", "on") %} Online {% else %} Offline {%- endif %}'
> friendly_name: HD Homerun
> sfap:
> value_template: '{% if is_state("binary_sensor.sfap", "on") %} Online {% else %} Offline {%- endif %}'
> friendly_name: sf-AP (Asus WiFi)
> sfmediabridge:
> value_template: '{% if is_state("binary_sensor.sfmediabridge", "on") %} Online {% else %} Offline {%- endif %}'
> friendly_name: sf-mediabridge
> sfn_nvr:
> value_template: '{% if is_state("binary_sensor.sfn_nvr", "on") %} Online {% else %} Offline {%- endif %}'
> friendly_name: sf-network NVR
> sfhue:
> value_template: '{% if is_state("binary_sensor.sfhue", "on") %} Online {% else %} Offline {%- endif %}'
> friendly_name: sf-Hue
> lutronhub:
> value_template: '{% if is_state("binary_sensor.lutronhub", "on") %} Online {% else %} Offline {%- endif %}'
> friendly_name: Lutron hub
> appletv:
> value_template: '{% if is_state("binary_sensor.appletv", "on") %} Online {% else %} Offline {%- endif %}'
> friendly_name: Apple TV
And finally, in customize.yaml (icons):
> sensor.sfpfsense:
> icon: mdi:router-wireless
> sensor.hp_printer:
> icon: mdi:printer
> sensor.sfpc06:
> icon: mdi:desktop-classic
> sensor.sonos_one_bureau:
> icon: mdi:speaker
> sensor.hdhomerun:
> icon: mdi:television-classic
> sensor.sfap:
> icon: mdi:wifi
> sensor.sfmediabridge:
> icon: mdi:access-point
> sensor.sfn_nvr:
> icon: mdi:cctv
> sensor.appletv:
> icon: mdi:apple
I’m not sure why, but I can’t get it to work (changing icon color based on state)…
I tried this in customize_glob.yaml:
> "sensor.*_state":
> templates:
> rgb_color: "if (state === 'Online') return [251, 210, 41]; else return [54, 95, 140];"
and I tried this in customize.yaml:
> sensor.sfserver:
> icon: mdi:server
> templates:
> rgb_color: "if (state === 'Online') return [251, 210, 41]; else return [54, 95, 140];"
Nothing seems to work…
I really need help figuring this out…