Home-AssistantConfig icon indicating copy to clipboard operation
Home-AssistantConfig copied to clipboard

template warnings under 2021.4.x

Open jonwaland opened this issue 3 years ago • 5 comments

2021-04-09 13:17:00 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'mappingproxy object' has no attribute 'icon' when rendering '{%- for item in states.sensor if (.....

Warning is created in the update_battery_status_group_members automation

jonwaland avatar Apr 09 '21 04:04 jonwaland

Proposed fix https://community.home-assistant.io/t/howto-create-battery-alert-without-creating-a-template-for-every-device/30576/947?u=walaj

jonwaland avatar Apr 09 '21 04:04 jonwaland

@jonwaland That fix seems like it wouldn't be what you want. That fix says if icon isn't defined then it will never add the entity. Something like this would probably be better:

              {%- for item in states.sensor if (
                not is_state_attr(item.entity_id, 'hidden', true)
                and (
                  is_state_attr(item.entity_id, 'device_class', 'battery')
                  or (item.attributes.icon is defined and 'battery' in item.attributes.icon | lower)
                  or (item.entity_id | lower).endswith('_bat')
                  or (item.name | lower).endswith('_bat')
                  ) or (
                    (
                      'battery' in item.entity_id | lower
                      or 'battery' in item.name | lower
                    ) and (
                      item.attributes.icon is not defined
                    ) and (
                      not is_state_attr(item.entity_id, 'battery_alert_disabled', true)
                    ) and (
                      not is_state_attr(item.entity_id, 'restored', true)
                    )
                  )
                )
              -%}
                {{ item.entity_id }}{% if not loop.last %}, {% endif %}
              {%- endfor -%}

tfili avatar Apr 12 '21 20:04 tfili

yup - my mistake - I meant it to be a qualifier for the check - but put it outside. thanks.

So how to get this added to the actual package for others?

jonwaland avatar Apr 13 '21 00:04 jonwaland

It's up to @notoriousbdg. Do you want a PR or do you want to just make the fix.

tfili avatar Apr 13 '21 16:04 tfili

pull request #33 fixes the warnings for me in Home Assistant 2021.11.3 - thanks!

tingox avatar Nov 27 '21 16:11 tingox