Customize template icon & color for a binary sensor (trend)

Hi,

I try to have templates on color & icon for a binary sensor (trend one).
Based on several posts (eg: Need help with sensor icon color based on state) , I added the following in my customize.yaml and made many variation of it.
I confirm that the state is indeed “on” or “off” from dev tools.

But it does not work.

Any idea or suggestion for further investigation ?

binary_sensor.hall_temp_rising:
  templates:
    icon: "
      if (state === 'on')  return 'mdi:thermometer-chevron-up';
      if (state === 'off') return 'mdi:thermometer-chevron-down';
      return 'mdi:thermometer';"
    icon_color: "if (state === 'on') return 'rgb(255,0,55)'; return 'rgb(0,191,255)';"

try:

binary_sensor.hall_temp_rising:
  templates:
    icon: >
      if (state == 'on')  return 'mdi:thermometer-chevron-up';
      if (state == 'off') return 'mdi:thermometer-chevron-down';
      return 'mdi:thermometer';
    icon_color: >
      if (state == 'on') return 'rgb(255,0,55)'; 
      return 'rgb(0,191,255)';

not sure why you would have a binary_sensor with 3 possible states for the icon?

Does this rely on custom-ui to be installed?

Or is it a feature of home assistant I was totally unaware of?

Same issue, nothing changed. Thank you for the proposal.
Good remark for the “3 possible states”: the “else” case is to manage startup case where the value is “Unknown” as the Trend platform requires at least 2 points.

Nothing special, just home assistant.

a but you do need custom-ui for this to work. templates in customize and icon_color are only supported using custom-ui

There are at least three topics I’ve read that use this template trick that don’t mention custom-UI at all! No wonder @csacre was not aware it was required.

Indeed, I didn’t knew about. I suppose you refer to https://github.com/andrey-git/home-assistant-custom-ui

I don’t see it under HACS, will check to do the installation.

Thank you!

Use the customizer: custum_ui: local version, see

Import of extra_html_url (of the top of my head) is deprecated and no longer supported in nowadays HA. And since it is no longer maintained, there is no need to use the server variant either…