Brand new to all things home assistant. I’ve got a few zigbee and tasmota devices, mqtt, node red and playing with grafana. But this is about lovelace. There’s a LOT that I haven’t been able to grasp around yaml and its coding but i’m nto sure if thats my problem at the moment or its more of a misunderstanding of where I need to place things.
I found a post called “Fun with Custom:Button-card” and definitily like its capabilities. I’m currently trying to create a few cards that will display my sensors current battery state and change the icon based on power level. This is my whole card.
entity: sensor.front_door_power
type: custom:button-card
name: front door battery
icon: >
{% if states('sensor.front_door_power') < 50 %) mdi:alert-decagram {% else %}
mdi:battery {% endif %}
Lovelace is not telling me any of my formatting is wrong but I’m also not getting the expected result, a basic battery since the state of my front door sensor is currently 80%. I’m not getting an icon at all, but if I remove the code and just set the icon to mdi:battery it correctly shows the icon on the card.
Is my if statement not meant or able to go under the icon field? if so, where should I be doing that and how would I call it back to the card?
@pedolsky thank you so much. That did the trick. Can you either explain or recommend further reading for the code you used? You’re right, I did go the route of jinja but thats cause I saw some other similar styled yaml that used it. How do I determine what language to use?
and thank you for the link. I’ll be sure look at that too.