I’m new to HS and hope someone can help me out with this issue. I have a lovelace card, with a custom senor I created for a device (TRV) and I want the sensors icon color to change depending on the state of the sensor.
I have a TRV which outputs a State > Attribute > hvac_action. The hvac_action attribute can be either:
“heating” (if the thermostat is calling for the heating to be turned on) or
“idle” (if the thermostat is satisfied wants the heating to be turned off)
These attributes are not exposed to home assistant as a sensor by default so I cannot show what the TRV is calling for in a lovelace dashboard.
What I did was create a senor by doing the following:
In configuration.yaml add the following code:
sensor: !include sensors.yaml
Make new file > sensors.yaml in HS config root
Created a new sensor “trv_hvac_action” to display if the TRV hvac_action attribute is “heating” or “idle” - added the code below to sensors.yaml:
The new sensor “trv_hvac_action” works fine in that when the TVR is “heating” it displays “heating”, and when “idle” it displays “idle”. I would also like the icon to be shown as yellow when “heating” and blue when “idle”. I have attached pictures below showing this with a light switch which does change color (would just like the default blue for “off” and yellow for “on”).
The icon I’m using is: mdi:lightbulb-outline
Hope this makes sense and thanks in advance for any help!!
Option A: Create a binary_sensor template with device_class: heat. Then use state_color: true in lovelace. This route is more configuration, but it’s using all built in and ‘easy to use’ functions of home assistant.
Option B: Use card_mod to color the icon based on the state of your current sensor. This route tends to be more advanced and it requires custom card mod, but it’s less configuration.
Your value template is incorrect, and the states will be Normal & Heat. Binary sensors are on or off, nothing else. For device_class: heat, on is Heat off is Normal. You won’t be able to get it to say Idle & Heating.