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:

Schermafbeelding 2021-06-29 om 10 00 31

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)

Most upvoted comments

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!

this is even more fun:

              animation: {% if is_state(config.entity,'on') %}
                         {% set perc = state_attr(config.entity,'percentage')|int %}
                         {% set base = 'rotation infinite linear, colorize 5s linear forwards 1' %}
                         {% if perc <= 15 %} 4s {{base}};
                         {%- elif perc <= 33 %} 3s {{base}};
                         {%- elif perc <= 67 %} 1.5s {{ base}};
                         {%- else  %} 0.75s {{base}};
                         {% endif %}
                         {% else %} none;
                         {% endif %}