I have managed to create badges for my hybrid car. Right now it shows a badge when the car is not charging. I would like to make this more advanced in that it should only show the badge when the car is not charging but only if the battery level is below 50%
Test w/o conditions to check if the badge is hidden.
Place whole code into Dev tools → Template and see how it works. May be your conditions are wrong.
I am not getting “is not showing up even that the charger”, isn’t a typo here?
This “charger isnt connected and the battery level is 20%” - is it same as your condition? If yes - then the “display=none” and the badge is supposed to be hidden, right?
I’ve started using the State Badge as a notification for some devices. This is to get my attention. For example, if a door is open, a small icon of the door appears at the top of my dashboard. I got this to work.
What I want now is for my car to appear as an icon (just like the door) when the charging cable is not connected AND the battery level is below, for example, 50%.
When I try in Developer Tools, I get the following response:
This template listens for the following state-changed events:
Good, than your template is correct:
if switch=OFF and level<50% → hide the badge
But probably you needed opposite:
hide the badge if switch=ON or level>=50 ?
{% if is_state('switch.gte_charging','on') or states('sensor.gte_battery_level')|int(0)>=80 %}
display: none;
{% endif %}
We are trying to solve the SIMPLEST task for a few hours.
To debug the code, do what I did - create two test helpers & use them for testing (just to not depend on a real car status):
– input_boolean.test_is_charging (I used switch, this does not matter);
– input_number.test_battery_level (0-100%).
Then again define a rule when the badge should appear:
– if CHARGING or level>=XXX → hide the badge
– if NOT CAHRGING and level<XXX → show the badge
If this is exactly the rule you need - then use my last code:
{% if is_state('input_boolean.test_is_charging','on') or states('input_number.test_battery_level')|int(0)>=80 %}
display: none;
{% endif %}
If you need the opposite rule - use the previous code:
{% if is_state('input_boolean.test_is_charging','off') and states('input_number.test_battery_level')|int(0)<80 %}
display: none;
{% endif %}