Faecon
(Jo)
August 1, 2023, 8:24am
1
- type: template
entity: sensor.energy_socket_5c2faf0313f6_active_power
icon: >
[[[
if (states['sensor.energy_socket_5c2faf0313f6_active_power'].state > 2) {
mdi:dishwasher-alert
} else {
mdi:dishwasher
}
]]]
I don’t get errors on the code, but it does not work. Where did I go wrong ? (again )
w35l3y
(w35l3y)
August 1, 2023, 8:34am
2
icon: >
{{ "mdi:dishwasher-alert" if states("sensor.energy_socket_5c2faf0313f6_active_power") | int > 2 else "mdi:dishwasher" }}
1 Like
Faecon
(Jo)
August 1, 2023, 8:37am
3
just for info. what is the difference between float and int ?
w35l3y
(w35l3y)
August 1, 2023, 9:58am
4
float
is for when you want decimal numbers
Use Template
from Developer Tools
to make your tests.
Also, you used JavaScript. That’s typically used by some third-party UI components. The backend uses Jinja.
Where did you get that code to begin with?
In this case, there wouldn’t have been any errors: there just wouldn’t be an icon. Basically, all the JS would be text in the icon field, but not in the mdi:...
format, so it just got ignored.
Faecon
(Jo)
August 1, 2023, 10:17am
6
I did. Result was string, and no error. but I dont know what to do when the result is string
Faecon
(Jo)
August 1, 2023, 10:19am
7
Ok. Thanks. I just dont know the difference between the languages. So I copy paste here and there and hope it works…
w35l3y
(w35l3y)
August 1, 2023, 11:17am
8