lovelace-card-mod: 'if config.entity is none' template doesn't work
My Home Assistant version: 2021.6.6
My lovelace configuration method (GUI or yaml): YAML What I am doing:
trying to have a conditional badge, templating on existence of the config.entity
- entity: sensor.state_badge
card_mod:
style: |
:host {
display: {% if config.entity is none %}none{%endif%}
}
Also tried {% if not config.entity %}
and {% if config.entity not is defined %}
What I expected to happen:
don’t display the badge if the entity doesn’t exist (yet)
What happened instead:

Minimal steps to reproduce:
# The least amount of code possible to reproduce my error
- entity: sensor.state_badge
card_mod:
style: |
:host {
display: {% if config.entity is none %}none{%endif%}
}
# End of code
Error messages from the browser console:
Unhandled Promise Rejection: TypeError: null is not an object (evaluating 'this.shadowRoot.querySelector')
though the above error also shows on correct badges, and I have reported that in another issue
please also see a community post.
as an example:
card_mod:
style: |
:host {
display: {% if states('binary_sensor.updater') == 'off' %} none {% endif %}
}
works perfectly.
By putting an X in the boxes ([]) below, I indicate that I:
-
Understand that this is a channel for reporting bugs, not a support forum (https://community.home-assistant.io/).
-
Have made sure I am using the latest version of the plugin.
-
Have followed the troubleshooting steps of the “Common Problems” section of https://github.com/thomasloven/hass-config/wiki/Lovelace-Plugins.
-
Understand that leaving one or more boxes unticked or failure to follow the template above may increase the time required to handle my bug-report, or cause it to be closed without further action.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 23 (6 by maintainers)
Thank you, surrounding it with if statement fixed it. Don’t know why I didn’t think of that. Thank you so much for your help!
https://github.com/thomasloven/lovelace-card-mod/issues/257#issuecomment-1446227419
this is even more fun: