I have a binary_sensor indicating if an update is available to a lightbulb or not. On my frontend it’s displayed as either “on” or “off”, as binary sensors do, which is not intuitive regarding the availability of an update.
I’m trying to customize it to something like “yes/no” or “available/not available”. I know of device classes, but none seems to display anything like that. Also even if some did, it might not do so next time, so I thought I’d asked for a general way of customzing the states.
Hi there, there are multiple methods to achieve this, You can use custom components like custom button card to do this in lovelace. There are also other custom lovelace integrations that make this possible.
But instead of that we can create a template sensor in home assistant which will show available as state when the binary sensor is on and unavailable otherwise. This template sensor should look like this.
Please make sure you change the binary_sensor entity id to yours. If you tell me how you operate this binary sensor, we may even be able to remove it by making the template accordingly.
adding a sensor works. But since I have a couple of lights, I have to add sensor for each light, right? That’s why I’d hoped I could just overwrite the value somehow with lovelace.
I’ll look into custom button cards.
Thanks!
Btw: regarding removing the binary_sensor, I suppose I’d just write whatever sets the binary sensor as a condition in the value template of the sensor instead of refereing to the binary sensors state. But in this case it is not an option since the binary sensors are entities from zigbee2mqtt.
Ok, with two bulbs thats feasible, but with 7 or 8 it would’t practically work this way, since there would be about 200 to 300 combinations I would have to account for. Or am I missing something?
In that case the best thing would be to use nodered which can compile all these into a single payload for the sensor in any combination by using the function node.
Always use states() method when you can and avoid state objects. i.e. states('binary_sensor.light1') instead of states.binary_sensor.light1.state.
if you’re going to use state objects, use them properly. I.e. if you want the state, you have to express that when you access it. states.binary_sensor.light1.state, not states.binary_sensor.light1
If you’re checking an on/off state, use is_state instead of states() or the states object. i.e. is_state('binary_sensor.light1', 'on')
if you have multiple lights (more than 2) this template will get cumbersome to deal with. Just make a list of lights and filter out what’s off.