Change sensor icon based on state on/off

thanks!

on GitHub https://github.com/andrey-git/home-assistant-custom-ui/issues/97#issuecomment-362862129 @fanaticDavid mentioned this also, and ive made changes accordingly successfully:

28

don’t understand though how the template could change the actual state? thought it only read the state and changed the way it displayed that?

Cheers,
Marius

1 Like

I’m not sure if it changes the underlying state on Hass, it might just change the state that the JavaScript sees. So maybe just client side state is overridden which would affect all JavaScript templates (and possibly other frontend logic) but not Hass itself.

1 Like

confusing after all:
thiught i had clinched it, again the device-tracker show Offline while in fact being online. Even the state machine is wrong now…

541220

binary sensor and ping see it correctly.

Hi @Mariusthvdb,

not exactly on topic here, but I noticed that you have lock icons on some switches in your screenshots. What are they for? I have been looking for a way to NOT accidentally press a switch in Home Assistant, is that what they represent?
And thanks for the solution to the state-dependent sensor icon change, that’s also very useful!

indeed, that s what they are for, at least in my setup.
You can do that without the lock, but the delay is still there, so I find that bit counter intuitively. The lock makes it clear (as is shown by your guess… :wink: )

called confirmable controls: home-assistant-custom-ui/docs/features.md at master · andrey-git/home-assistant-custom-ui · GitHub

@andrey has made them available even on the light sliders, which is of extreme good use on a handheld device. Before one couldn’t slide the page without switching the lights, now thats no issue whatsoever anymore.

Cheers!
Marius

Does anyone know if it’s possible to change icon_color based on attribute instead of state? (maybe @Mariusthvdb you can help/add an example of this to your amazing examples file?)
Like…

climate.livingroom:
  templates:
    icon_color: if (state.attr('this.entity','hvac_mode') == 'cooling') return '#25FE5C';

I feel like the above should be possible but it’s not working, so I thought it might be my syntax

try:

climate.livingroom:
  templates:
    icon_color: >
      if (attributes.hvac_mode == 'cooling') return '#25FE5C';
      return 'grey';

the grey is to guard the template, always use a guard…
note: this only works if you have installed the modernized custom-ui.

1 Like