Dujith
(Charles Evers)
August 16, 2021, 1:16pm
1
I am trying to get hot water running icon and 1 for the off state.
After tinkering around i read and found out that state_icons is not allowed in mqtt and i would have to use a customize for that.
Now in my sensors yaml file i have this:
- platform: mqtt
name: "Hot_Water"
state_topic: "opentherm-thermostat/cv-dhw-active/get"
value_template: "{{ value }}"
And in my customize.yaml this:
sensor.Hot_Water:
state_icons:
"off": "mdi:water-pump-off"
"on": "mdi:water-pump"
friendly_name: "Hot Water"
The customize.yaml is loaded in my configuration file.
#Homeassistant
homeassistant:
customize: !include customize.yaml
Bit stumped now as it now just shows an eye in the entity card
123
(Taras)
August 16, 2021, 1:24pm
3
Where in the Customization documentation did you find a description for an option called state_icons
?
All it has is an option called icon for specifying a single icon.
ardysusilo:
MQTT sensor platform supports icon.
Same as for Customization, it is for a single icon.
Dujith
(Charles Evers)
August 16, 2021, 1:24pm
4
Icons do work yes and used them before. But i want an icon depandant on the state.
When i use state_icons it warns me its not allowed in the editor.
123
(Taras)
August 16, 2021, 1:26pm
5
Why do believe state_icons
is a valid option?
Not really sure if this is the best way to do it, but you can try creating template sensor based on sensor.hot_water
-
According to the documentation, it supports icon template.
Edit: removing my previous post as it is an incorrect suggestion.
123
(Taras)
August 16, 2021, 1:55pm
7
If you want to extend the capabilities of Customization, such as allowing the use of templates to determine the icon, consider using custom-ui :
# Some examples using custom-ui.
This is an excerpt of my own package, and can be used
directly if you copy it to your own homeassistant structure and activate packages. Of
course other methods work also, like pointing to a dedicated customize file, and
referencing that in your configuration.yaml
Note that the triple `===` which is used throughout the community and examples on the
original repo are not necessary. `==` suffices. Secondly, always use a guard for unexpected states.
Of course this holds for Jinja templates in HA too...
The guard is used by setting the `else` clause, which in the examples below are on the
last lines, starting with 'return'. Dont need to use the word `else` itself, though it
will be valid if you do.
Lastly, remember to delimit the lines with a `;` .
Why use custom-ui? 2 huge reasons:
# Icon color
This file has been truncated. show original
In addition to templating the icon for any entity, it also lets you template the icon’s color.
Using custom-ui, your templated icon would look something like this:
binary_sensor.hot_water:
templates:
icon: >
if (state == 'on') return 'mdi:water-pump';
if (state == 'off') return 'mdi:water-pump-off';
1 Like
Dujith
(Charles Evers)
August 16, 2021, 1:58pm
8
After delving deeper into this. The custom-ui seems the best option for me now.
Trying to wrap my head around HA and i get stumped by stuff like this. It will come in time.
Ty for your help (@ardysusilo too)
Dujith
(Charles Evers)
August 16, 2021, 2:01pm
10
I misread. Seems the topic was about the custom-ui. Learning all the time…
123
(Taras)
August 16, 2021, 2:06pm
11
Be advised that if you are reading about the original Custom UI, it is no longer supported in Home Assistant.
Mariusthvdb created a modified version that supports a subset of the many features found in the original version. Any posts that are dated prior to 2020 are probably referring to the original version and may be misleading given that the original no longer works.
Let us know if the suggestion to use custom-ui works for you.
finity
August 16, 2021, 3:05pm
12
And even if what you were trying to do thru customization was possible then what you were using wouldn’t have worked anyway.
all entity_id’s are in lower case.
you had this:
sensor.Hot_Water:
....
which is not correct.
it should have been this:
sensor.hot_water:
...
just for future reference…
Dujith
(Charles Evers)
August 16, 2021, 3:36pm
13
@finity
corrected that yes. That was down to my own habit of capitalizing.
@123
Couldnt get it to work at first, but after looking at the js in VS i noticed a few small indentation errors.
After fixing those it loaded in and now it works: