Hi all, hopefully a simple one. I use custom button cards in my dashboard. I have a door sensor that the state shows as ‘on’ or ‘off’. I am looking to have the button card show alternate text (i.e. Closed instead of On, or Open instead of Off)
here is my code
and here is the current button, note it says off instead of closed
Any ideas from all the smart people on this community?
thanks
thanks @koying. Ok this is very weird, its already a device class of door. So i looked at the device as per your instructions, in the native device info its showing ‘open’ and ‘closed’ but i have to use ‘on’ and ‘off’ in the yaml when creating the button card? its a ring door sensor coming through via MQTT. I am still a bit of a novice at this point so dont know why its coming through as on and off instead of open and closed. Tried changing my yaml to closed but it does not recognise that?
In yaml, and templates in general, switches and binary sensors states are always “on” and “off”.
Depending on their classes, that will translate to, e.g., “opened” and “closed” for display purposes, but not if you are using the entity state in a template in cards supporting this.
You could use a conditional card to show a button hardcoded to say “Closed” and another conditional card to say “Open”. Here’s an example of this I did today, it’s using lovelace_gen but the pattern is applicable to your use case.
Use state_display as i mentioned above, it’s as simple as that.(should be)
There are lots of examples on this forum(i.e " Fun with Custom:Button Card", and the main Topic for the Custom:button_card)
state_display: |
[[[
if (entity.state == 'on') return 'Search and you will find'; return 'Nothing';
]]]
Note: For most such sensors and switches i don’t show “state”, as i can see that by the color and/or icon