Templates and Badge icons

I use a template sensor to show the number of lights on in custom button …but would also like to be able to add that template as a badge icon in a (mushroom) template card

this particular line of code

{{ states(‘sensor.number_lights_on’) }}

currently presents itself as this

image

so no number details at all…even though a number of lights are reported on this custom button card

image

and when I place the same template code into the Dev Tools template sections, it returns the correct number

So I am clearly not using the correct syntax but I am struggling to find out what it should be.

Can anyone please give the correct pointers?

I have other badges working fine but they are is is_states and they are pointing to a specific outcome…so I know it has to be different

TIA for anything you might be able to suggest

The Mushroom Template Car only supports badge icons. A (obviously poor, because limited to 9 lights on) workaround would be to use mdi:numeric-1 - mdi:numeric-9 based on the states of your sensor.

wont lie you’ve lost me a bit there

:grinning_face_with_smiling_eyes:

I mean something like that:


type: custom:mushroom-template-card
primary: whatever
secondary: whatever
icon: mdi:lightbulb-outline
entity: sensor.your_sensor
badge_icon: |-
  {{ 'mdi:numeric-' ~ states(entity) if states(entity)|int(0) < 9 else
  'mdi:numeric-9-plus' }}

1 Like

knocked up a test card and still returns blacnk badge icon

starting to think not possible…and not the end of the world as I have it showing fine on custom button cards…just thought there might be a way around it

Your code isn’t correct, you need to put sensor.number_lights_on in quotes

1 Like

If you use sensor.number_lights_on as main entity in the Mush Card, you can copy my example as it is. Mush Cards use the entity variable.

1 Like

that did it…amazing how much different two little characters can have…both your suggestions now worked but of course can only mark one as the solution…thank you so much…you sir are a genius…