Home-AssistantConfig
Home-AssistantConfig copied to clipboard
template warnings under 2021.4.x
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
Proposed fix https://community.home-assistant.io/t/howto-create-battery-alert-without-creating-a-template-for-every-device/30576/947?u=walaj
@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 -%}
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?
It's up to @notoriousbdg. Do you want a PR or do you want to just make the fix.
pull request #33 fixes the warnings for me in Home Assistant 2021.11.3 - thanks!