Change entity state_color depending on the value of binary_sensor

Hey there!

I’ve been trying to figure this out for several days now, but I guess I am missing something in the docs/forums. I have a self-made calendar sensor that shows the days until various trash categories will be picked up (I live in Germany, trash pickup-is quite complex here). In the dashboard it looks like this:


(= four entity cards stacked horizontally)

The values are delivered to HA via MQTT (so it is not an actual calendar) and are stored as attributes of the sensor. That part seems to work just fine. I’ve also created a binary sensor for each category that switches to “on” as soon as there is only 1 day left until pickup. What I don’t get: How can I use “state_color” to turn on the color highlighting if there is only 1 day left for a category? Is this possible with a regular entity card? Can somebody hint me in the right direction, please? This is driving me nuts!

I’ve tried a lot of variations of this, but it does not work:

type: entity
entity: sensor.abfallkalender
attribute: biotonne
unit: Tage
state_color: true
icon: mdi:biohazard
name: Bio
value_template: '{{ is_state("binary_sensor.biomuell_due", "on") }}'

Thanks for your help!

PS: I’m sure you can tell that I’m very new to Home Assistant (so: Hi!) and I don’t have a very good grasp (yet) on how things work, how all the parts fit together and how I use YAML on the CLI for some and the UI for other things. But I’m sure, I’ll get there!

You can create two conditional cards that change based on the value of the binary sensor. One, which has already been designed, which should be shown only when the binary_sensor == 0. You must add a new one that shows the same card with a changed ‘state_color’ for when the binary_sensor == 1. This for each card on the board.

2 Likes

The entity card doesn’t support a value_template, that’s why it’s not doing what you want.

There’s various custom cards that might give you what you want - things like card mod. They’re very much in the here be dragons category though, aimed at advanced users. The suggestion from oalbaf will be much simpler.

1 Like

That sounds like a very good idea. Thanks a lot!

(I guess, I was hoping that there is some secret attribute to an entity card … but I guess that just is not how it works.)