piitaya / lovelace-mushroom

Build a beautiful Home Assistant dashboard easily

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug]: Template not rendering in template card

caraar12345 opened this issue Β· comments

Current Behavior

The template doesn't consistently render. It usually just shows the template text itself.

Expected Behavior

The template renders to show 0 guest devices connected, 1 guest device connected or X guest devices connected.

Steps To Reproduce

type: custom:mushroom-template-card
primary: guest_ssid
secondary: >-
  password

  {% set dev_count = states.device_tracker | selectattr('state', 'eq', 'home') |
  selectattr('attributes.essid', 'eq', "guest_ssid") | list | count %}{% if
  dev_count == 1 %}{{dev_count}} guest device connected{% else %}{{dev_count}}
  guest devices connected{% endif %}
icon: mdi:wifi-lock
multiline_secondary: true
  • Set up a template card using this YAML (YAML not necessary, just easier to share).

Environment

  • OS: macOS 12.3.1
  • Browser: Safari 15.4 / Home Assistant Companion App for macOS / Chrome 102.0.5005.61
  • Version: v1.9.0 (HACS)
  • Hassio: 2022.6.3
  • Template attributes from: UniFi Network

It doesn't really matter what I use. Not been able to find a match between when it does render and when it doesn't though.

Anything else?

Screenshot 2022-06-07 at 19 51 54

Hello πŸ™‚ It's an error with your template. You can test it here.

Hello πŸ™‚ It's an error with your template. You can test it here.

Hmmm ... that's entirely what I would have expected. But for some reason, it fails in the template tester, but not always in the Template Card !!??

Regardless, doesn't seem to be a Mushroom thing. Thank you anyway πŸ™

image

image

Maybe you must check if the attribute exist before selectattr? I'm not a Jinja template expert πŸ˜…

Lol nor am I unfortunately. I think it's because device_tracker doesn't exclusively cover the UniFi entities so it might be something about whether it comes across a UniFi entity first or not. Will have a play!

Cheers and sorry again 😊

Just to close the loop, this is the cursed thing I've had to produce to make sure it works πŸ˜‚

It did not work...

{% set devices = [] %}
{% for entity in states.device_tracker %}
  {% if 'essid' in entity['attributes'].keys() %}
    {% if 'guest_ssid' in entity['attributes'].values() %}
      {% set devices = devices + [entity] %}
    {% endif %}
  {% endif %}
{% endfor %}

{% set dev_count = devices | list | count  %} 


{% if dev_count == 1 %}
  {{dev_count}} guest device connected
{% else %}
  {{dev_count}} guest devices connected
{% endif %}