Vote here:
This will give you chaging icons but not colours
- platform: template
sensors:
washing_machine:
friendly_name: Washing Machine
entity_id: binary_sensor.washing_machine
value_template: >
{% if is_state('binary_sensor.washing_machine', 'on') %}
Running
{% else %}
Stopped
{% endif %}
icon_template: >
{% if is_state('binary_sensor.washing_machine', 'on') %}
mdi:restart
{% else %}
mdi:restart-off
{% endif %}
Nice, one way to change the colour would be to use custom-ui
For one of mine, I needed colour change so downloaded the icons from MDI, edited it in photoshop to be the correct colours (in this case red and green), saved them as PNGs in WWW folder and used entity_picture_template instead of the icon template. Bit of a faff but that’s why we like HA !
Still probably easier than installing and using custom-ui.
Just noticed on MDI that you can use advanced export and colour it there before dowloading it
Yes i know the custom ui but think it is a bit too much just for the icon change.
Could you show an example of your entity_picture_template?
Something like this, need to change the colour of the icon using advanced export from MDI as PNGs and put them in the WWW folder
- platform: template
sensors:
washing_machine:
friendly_name: Washing Machine
entity_id: binary_sensor.washing_machine
value_template: >
{% if is_state('binary_sensor.washing_machine', 'on') %}
Running
{% else %}
Stopped
{% endif %}
entity_picture_template: >-
{% if is_state('binary_sensor.washing_machine', 'on') %}
/local/restart_green.png
{% else %}
/local/restart_red.png
{% endif %}
I have tried this now and it Works
However the size of the icon differs a bit from the original mdi icon. What size have you choosen so it fits? I chose 24x24
I also see that the colors has to be adjusted to fit the default ones from HA.
Can’t really remember, I know it was a lot of trial and error scaling with Photoshop to get it to look the same. I only use picture elements cards now so I can use other icons than MDI.
I will try something thanks
I’ve just discovered this:
I am using it to change icon colour based on state. For example, icon changing from green to red when door unlocked:
type: entities
title: Front Door Lock
show_header_toggle: false
style: |
ha-card {
background: var(--background-card-color);
}
#states div:nth-of-type(1) {
--paper-item-icon-color: [[ if(lock.assa_abloy_yale_conexis_l1_sd_l1000_ch_locked == "unlocked", "red", "green)) ]];
}
entities:
- entity: lock.assa_abloy_yale_conexis_l1_sd_l1000_ch_locked
name: Lock
How about the custom button card?
- type: custom:button-card
entity: cover.garage
icon: mdi:garage
color_type: icon
label_template: >
return 'Garage is currently: '
+ (states['cover.garage'].state ==='closed'
? '<span style="color: #00FF00;">closed</span>'
: '<span style="color: #FF0000;">open</span>')
show_label: true
state:
- value: 'open'
color: red
name: Open
- value: 'closed'
color: green
name: Closed
show_state: false
tap_action:
action: call-service
service: input_boolean.toggle
service_data:
entity_id: input_boolean.garagedoor
Thanks but the OP just wanted to change an icon in an entity card and when you use icon template, it doesn’t change colour with state, he wanted a way to do that
I guess this is only for lovelace, which I don´t use. At least for now
I have managed to modify the icons so the size now fits and it looks great.
I have used your examplein an attempt to change the label of a binary sensor derived from the raspberry Pi4 GPIO according to the following code:
- platform: rpi_gpio2
invert_logic: true
ports:
12: Security System
- platform: template
sensors:
alarm_security_system_status:
friendly_name: Alarm System
entity_id: binary_sensor.security_system
value_template: >
{% if is_state('binary_sensor.security_system', 'off') %}
UNSET
{% else %}
SET
{% endif %}
Although the binary sensor seems to generate the appropriate on-off status, I’m unable to get the customized label output. The binary_sensor.alarm_security_system_status still outputs on or off. Appreciate any hint to solve the issue.
It has to be a sensor
, not a binary_sensor
. A binary_sensor
will always be on
or off
. A sensor
can have about any value want.
Just move your template to the sensor
configuration (and I know, the sensor
designation under the binary_sensor
is a bit confusing… - it’s the same thing under the sensor
configuration…). You can also eliminate the entity_id
line, as HA knows to monitor that for changes because it’s in the template.
Thanks a lot for putting me into the right direction. Moved to sensor directory and deleted the entity_id. I over concentrated on binary_sensor for reasons of ability to change state of icon color. Managed to accomplish the same under sensor configuration by using the following lovelace configuration. All working as intended now. Again, thanks for your help.
- type: entities
entities:
- entities:
- entity: sensor.alarm_security_system_status
name: false
entity: binary_sensor.security_system
name: Alarm System
icon: 'mdi:alarm-panel-outline'
state_color: true
toggle: false
show_state: false
type: 'custom:multiple-entity-row'
Glad that worked out!