Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template warnings under 2022.2.9 #37

Open
tingox opened this issue Feb 27, 2022 · 2 comments
Open

Template warnings under 2022.2.9 #37

tingox opened this issue Feb 27, 2022 · 2 comments

Comments

@tingox
Copy link

tingox commented Feb 27, 2022

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.

@danielbrunt57
Copy link

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
                )

@tingox
Copy link
Author

tingox commented Mar 1, 2022

Thanks! Adding that fix also fixed the errors, as the script now produces no warning or errors, and still reports low batteries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants