Template warning for int. I think I've tried everything to get rid of it

…but obviously I haven’t :slight_smile:

My full template is below but this is my last effort to prevent the warning:

{% if states('sensor.unifi_gateway_alerts') not in ('none', 'unavailable', 'unknown') and
      is_number(states('sensor.unifi_gateway_alerts')) %}
{% for alert in range(0, states('sensor.unifi_gateway_alerts') | int) %}

I’ve tried the obvious too

int(0)

How do I deal with this?


This is the warning:

Template warning: 'int' got invalid input 'unknown' when rendering template '{% for alert in range(0, states('sensor.unifi_gateway_alerts') | int ) %} […etc…] ' but no default was specified. Currently 'int' will return '0', however this template will fail to render in Home Assistant core 2022.1


Full template here:

{% if states('sensor.unifi_gateway_alerts') not in ('none', 'unavailable', 'unknown') and
      is_number(states('sensor.unifi_gateway_alerts')) %}
  {% for alert in range(0, states('sensor.unifi_gateway_alerts') | int) %}
    {% set alert_no = loop.index | string %}
    {% set date_time = as_local(as_datetime(state_attr('sensor.unifi_gateway_alerts', alert_no).datetime)) %}
    **{{ as_timestamp(date_time) | timestamp_custom("%A %-d %b") }}** at **{{ as_timestamp(date_time) | timestamp_custom("%H:%M") }}**
    {% if state_attr('sensor.unifi_gateway_alerts', alert_no).usgipGeo is defined %}
      {% set country = state_attr('sensor.unifi_gateway_alerts', alert_no).usgipGeo.country_name %}
      {% set city = state_attr('sensor.unifi_gateway_alerts', alert_no).usgipGeo.city %}
      {% set lat_lon = state_attr('sensor.unifi_gateway_alerts', alert_no).usgipGeo.latitude ~ ', ' ~ state_attr('sensor.unifi_gateway_alerts', alert_no).usgipGeo.longitude %}
      {% set organisation = state_attr('sensor.unifi_gateway_alerts', alert_no).usgipGeo.organization %}
      {% set signature = state_attr('sensor.unifi_gateway_alerts', alert_no).inner_alert_signature %}
      {% set category = state_attr('sensor.unifi_gateway_alerts', alert_no).inner_alert_category %}
      {% set severity = state_attr('sensor.unifi_gateway_alerts', alert_no).inner_alert_severity %}
      Alert **{{ alert_no }}** of **{{ states('sensor.unifi_gateway_alerts')}}** - Severity: **{{ severity }}**
      Signature: **{{ signature }}**
      Category: **{{ category }}**
      Origin: **{{ organisation }}, {{ city }}, {{ country }}** ({{ lat_lon }})
    {% else %}
      {{ state_attr('sensor.unifi_gateway_alerts', alert_no).msg }}
    {% endif %}

    ---------

  {% endfor %}
{% endif %}


Check petro’s thread:

That if statement should hold it back with bad data. Are you sure that error is still happening?

I am, but I’m no longer at my PC.
I’ll confirm later and provide the evidence.
Or the apology. :roll_eyes: