Home-AssistantConfig
Home-AssistantConfig copied to clipboard
Template warnings under 2022.2.9
a couple of warnings in 2022.2.9 (and previous 2022.x versions)
2022-02-27 18:00:00 WARNING (MainThread) [homeassistant.helpers.template] Template warning: 'int' got invalid input 'unknown' when rendering template '{% macro battery_level() %} {% for entity_id in states.group.battery_status.attributes.entity_id if (
not (
is_state_attr(entity_id, 'battery_alert_disabled', true)
or is_state_attr(entity_id, 'restored', true)
)
and states(entity_id) is not none
and (
(
(
states(entity_id) is number
or states(entity_id) | length == states(entity_id)| int | string | length
or states(entity_id) | length == states(entity_id)| float | string | length
)
and states(entity_id) | int < states.input_number.battery_alert_threshold_max.state | int
and states(entity_id) | int > states.input_number.battery_alert_threshold_min.state | int
)
or states(entity_id) | lower == 'low'
or states(entity_id) | lower == 'unknown'
or states(entity_id) | lower == 'unavailable'
)
) -%}
{{ state_attr(entity_id, "friendly_name") }} ({{ states(entity_id) }})
{% endfor -%} {% endmacro %} {{ battery_level() }}' but no default was specified. Currently 'int' will return '0', however this template will fail to render in Home Assistant core 2022.1
2022-02-27 18:00:00 WARNING (MainThread) [homeassistant.helpers.template] Template warning: 'float' got invalid input 'unknown' when rendering template '{% macro battery_level() %} {% for entity_id in states.group.battery_status.attributes.entity_id if (
not (
is_state_attr(entity_id, 'battery_alert_disabled', true)
or is_state_attr(entity_id, 'restored', true)
)
and states(entity_id) is not none
and (
(
(
states(entity_id) is number
or states(entity_id) | length == states(entity_id)| int | string | length
or states(entity_id) | length == states(entity_id)| float | string | length
)
and states(entity_id) | int < states.input_number.battery_alert_threshold_max.state | int
and states(entity_id) | int > states.input_number.battery_alert_threshold_min.state | int
)
or states(entity_id) | lower == 'low'
or states(entity_id) | lower == 'unknown'
or states(entity_id) | lower == 'unavailable'
)
) -%}
{{ state_attr(entity_id, "friendly_name") }} ({{ states(entity_id) }})
{% endfor -%} {% endmacro %} {{ battery_level() }}' but no default was specified. Currently 'float' will return '0', however this template will fail to render in Home Assistant core 2022.1
there are also a couple of errors
2022-02-27 17:58:00 ERROR (MainThread) [homeassistant.components.automation.update_battery_status_group_members] update_battery_status_group_members: Error executing script. Invalid data for call_service at pos 1: Entity ID is an invalid entity ID for dictionary value @ data['entities']
2022-02-27 17:58:00 ERROR (MainThread) [homeassistant.components.automation.update_battery_status_group_members] Error while executing automation automation.update_battery_status_group_members: Entity ID is an invalid entity ID for dictionary value @ data['entities']
this is with the fixes in pull request #33 added.
For the int, float warnings you need to add (default=0)
in 28 different places where there is | int
or | float
.
Example:
(
states(entity_id) is number
or states(entity_id) | length == states(entity_id)| int(default=0) | string | length
or states(entity_id) | length == states(entity_id)| float(default=0) | string | length
)
Thanks! Adding that fix also fixed the errors, as the script now produces no warning or errors, and still reports low batteries.