custom-components / weatheralerts

A sensor that gives you weather alerts from alerts.weather.gov.
MIT License
123 stars 15 forks source link

Errors and warnings in log #52

Closed dcf1999 closed 2 years ago

dcf1999 commented 2 years ago

Version 0.1.2

Describe the bug I keep getting errors and warnings in my system log. I have two locations I’m monitoring. I downloaded the weather_alerts1.yaml and changed the name to the location I’m monitoring (Vilas.yaml) and did the same thing for the second location (Malta.yaml). I modified the sensor names in each file to corespondent to the weatheralerts sensor in HA (also renamed to the location) and get the errors below. I get them for both locations.

Log Logger: homeassistant.helpers.template Source: helpers/template.py:1791 First occurred: 8:01:00 AM (50 occurrences) Last logged: 8:18:20 AM

Template variable error: list object has no element 0 when rendering '{% if (states('sensor.weatheralerts_malta') != 'unavailable') and (state_attr('sensor.weatheralerts_malta', 'alerts')[0] != null) or ((states('sensor.weatheralerts_malta') == 'unavailable') and (as_timestamp(state_attr('sensor.weatheralerts_malta', 'alerts')[0].endsExpires) - as_timestamp(now()) > 0)) %} on {% else %} off {% endif %}' Template variable error: list object has no element 1 when rendering '{% if (states('sensor.weatheralerts_malta') != 'unavailable') and (state_attr('sensor.weatheralerts_malta', 'alerts')[1] != null) or ((states('sensor.weatheralerts_malta') == 'unavailable') and (as_timestamp(state_attr('sensor.weatheralerts_malta', 'alerts')[1].endsExpires) - as_timestamp(now()) > 0)) %} on {% else %} off {% endif %}' Template variable error: list object has no element 3 when rendering '{% if (states('sensor.weatheralerts_malta') != 'unavailable') and (state_attr('sensor.weatheralerts_malta', 'alerts')[3] != null) or ((states('sensor.weatheralerts_malta') == 'unavailable') and (as_timestamp(state_attr('sensor.weatheralerts_malta', 'alerts')[3].endsExpires) - as_timestamp(now()) > 0)) %} on {% else %} off {% endif %}' Template variable error: list object has no element 2 when rendering '{% if (states('sensor.weatheralerts_malta') != 'unavailable') and (state_attr('sensor.weatheralerts_malta', 'alerts')[2] != null) or ((states('sensor.weatheralerts_malta') == 'unavailable') and (as_timestamp(state_attr('sensor.weatheralerts_malta', 'alerts')[2].endsExpires) - as_timestamp(now()) > 0)) %} on {% else %} off {% endif %}' Template variable error: list object has no element 4 when rendering '{% if (states('sensor.weatheralerts_malta') != 'unavailable') and (state_attr('sensor.weatheralerts_malta', 'alerts')[4] != null) or ((states('sensor.weatheralerts_malta') == 'unavailable') and (as_timestamp(state_attr('sensor.weatheralerts_malta', 'alerts')[4].endsExpires) - as_timestamp(now()) > 0)) %} on {% else %} off {% endif %}'


This error originated from a custom integration.

Logger: custom_components.weatheralerts.sensor Source: custom_components/weatheralerts/sensor.py:228 Integration: weatheralerts First occurred: 8:15:50 AM (10 occurrences) Last logged: 8:17:50 AM

[WIZ005,WIC125] Still no update (ClientConnectorError) [ILZ011,ILC037] Still no update (ClientConnectorError)


Logger: homeassistant.helpers.template Source: helpers/template.py:1291 First occurred: 8:01:00 AM (888 occurrences) Last logged: 8:15:20 AM

Template warning: 'int' got invalid input 'unavailable' when rendering template '{% if states('sensor.weatheralerts_malta')|int > 4 or (states('sensor.weatheralerts_malta') == "unavailable" and states('sensor.weatheralerts_malta_alert_5') == "on") %} {{ states.sensor.weatheralerts_malta.attributes.alerts[4].title }} {% else %} None {% endif %}' but no default was specified. Currently 'int' will return '0', however this template will fail to render in Home Assistant core 2022.1 Template warning: 'int' got invalid input 'unavailable' when rendering template '{% if states('sensor.weatheralerts_malta')|int > 4 or (states('sensor.weatheralerts_malta') == "unavailable" and states('sensor.weatheralerts_malta_alert_5') == "on") %} {{ states.sensor.weatheralerts_malta.attributes.alerts[4].zoneid }} {% else %} None {% endif %}' but no default was specified. Currently 'int' will return '0', however this template will fail to render in Home Assistant core 2022.1 Template warning: 'int' got invalid input 'unavailable' when rendering template '{% if states('sensor.weatheralerts_malta')|int > 4 or (states('sensor.weatheralerts_malta') == "unavailable" and states('sensor.weatheralerts_malta_alert_5') == "on") %} {% if states.sensor.weatheralerts_malta.attributes.alerts[4].NWSheadline != "null" %} {{ states.sensor.weatheralerts_malta.attributes.alerts[4].NWSheadline | regex_replace('[\'','') | regex_replace('\']','') }}
{% endif %}
{{ states.sensor.weatheralerts_malta.attributes.alerts[4].description | regex_replace('\n\n','

') | regex_replace('\n',' ') | regex_replace('*','\n') | regex_replace('

','\n\n') }}
{% if states.sensor.weatheralerts_malta.attributes.alerts[4].instruction != None %} {{ states.sensor.weatheralerts_malta.attributes.alerts[4].instruction | regex_replace('\n\n','

') | regex_replace('\n',' ') | regex_replace('*','\n') | regex_replace('

','\n\n') }}
{% endif %}
Where : {{ state_attr('sensor.weatheralerts_malta', 'friendly_name') }}
Effective: {{ states.sensor.weatheralerts_malta.attributes.alerts[4].effective }} {%- if states.sensor.weatheralerts_malta.attributes.alerts[4].ends != None %}
Ends: {{ states.sensor.weatheralerts_malta.attributes.alerts[4].ends }} {%- endif %}
Expires: {{ states.sensor.weatheralerts_malta.attributes.alerts[4].expires }} {% else %} None {% endif %}' but no default was specified. Currently 'int' will return '0', however this template will fail to render in Home Assistant core 2022.1 Template warning: 'int' got invalid input 'unavailable' when rendering template '{% if states('sensor.weatheralerts_malta')|int > 4 or (states('sensor.weatheralerts_malta') == "unavailable" and states('sensor.weatheralerts_malta_alert_5') == "on") %} Attention!!! Weather alert for {{ state_attr('sensor.weatheralerts_malta', 'friendly_name') }}. A {{ states.sensor.weatheralerts_malta.attributes.alerts[4].title }}. {{ states.sensor.weatheralerts_malta.attributes.alerts[4].NWSheadline | regex_replace('[\'','') | regex_replace('\']','') | capitalize }}. {% else %} None {% endif %}' but no default was specified. Currently 'int' will return '0', however this template will fail to render in Home Assistant core 2022.1 Template warning: 'int' got invalid input 'unavailable' when rendering template '{% if states('sensor.weatheralerts_malta')|int > 4 or (states('sensor.weatheralerts_malta') == "unavailable" and states('sensor.weatheralerts_malta_alert_5') == "on") %} {{ states.sensor.weatheralerts_malta.attributes.alerts[4].description | regex_replace('\n\n','

') | regex_replace('\n',' ') | regex_replace('*','\n') | regex_replace('

','\n\n') }} {% if states.sensor.weatheralerts_malta.attributes.alerts[4].instruction != None %} {{ states.sensor.weatheralerts_malta.attributes.alerts[4].instruction | regex_replace('\n\n','

') | regex_replace('\n',' ') | regex_replace('*','\n') | regex_replace('

','\n\n') }} {% endif %} {% else %} None {% endif %}' but no default was specified. Currently 'int' will return '0', however this template will fail to render in Home Assistant core 2022.1


Logger: homeassistant.components.template.template_entity Source: components/template/template_entity.py:140 Integration: Template First occurred: 8:01:00 AM (20 occurrences) Last logged: 8:15:20 AM

TemplateError('UndefinedError: list object has no element 0') while processing template 'Template("{% if (states('sensor.weatheralerts_malta') != 'unavailable') and (state_attr('sensor.weatheralerts_malta', 'alerts')[0] != null) or ((states('sensor.weatheralerts_malta') == 'unavailable') and (as_timestamp(state_attr('sensor.weatheralerts_malta', 'alerts')[0].endsExpires) - as_timestamp(now()) > 0)) %} on {% else %} off {% endif %}")' for attribute '_attr_native_value' in entity 'sensor.weatheralerts_malta_alert_1' TemplateError('UndefinedError: list object has no element 1') while processing template 'Template("{% if (states('sensor.weatheralerts_malta') != 'unavailable') and (state_attr('sensor.weatheralerts_malta', 'alerts')[1] != null) or ((states('sensor.weatheralerts_malta') == 'unavailable') and (as_timestamp(state_attr('sensor.weatheralerts_malta', 'alerts')[1].endsExpires) - as_timestamp(now()) > 0)) %} on {% else %} off {% endif %}")' for attribute '_attr_native_value' in entity 'sensor.weatheralerts_malta_alert_2' TemplateError('UndefinedError: list object has no element 2') while processing template 'Template("{% if (states('sensor.weatheralerts_malta') != 'unavailable') and (state_attr('sensor.weatheralerts_malta', 'alerts')[2] != null) or ((states('sensor.weatheralerts_malta') == 'unavailable') and (as_timestamp(state_attr('sensor.weatheralerts_malta', 'alerts')[2].endsExpires) - as_timestamp(now()) > 0)) %} on {% else %} off {% endif %}")' for attribute '_attr_native_value' in entity 'sensor.weatheralerts_malta_alert_3' TemplateError('UndefinedError: list object has no element 3') while processing template 'Template("{% if (states('sensor.weatheralerts_malta') != 'unavailable') and (state_attr('sensor.weatheralerts_malta', 'alerts')[3] != null) or ((states('sensor.weatheralerts_malta') == 'unavailable') and (as_timestamp(state_attr('sensor.weatheralerts_malta', 'alerts')[3].endsExpires) - as_timestamp(now()) > 0)) %} on {% else %} off {% endif %}")' for attribute '_attr_native_value' in entity 'sensor.weatheralerts_malta_alert_4' TemplateError('UndefinedError: list object has no element 4') while processing template 'Template("{% if (states('sensor.weatheralerts_malta') != 'unavailable') and (state_attr('sensor.weatheralerts_malta', 'alerts')[4] != null) or ((states('sensor.weatheralerts_malta') == 'unavailable') and (as_timestamp(state_attr('sensor.weatheralerts_malta', 'alerts')[4].endsExpires) - as_timestamp(now()) > 0)) %} on {% else %} off {% endif %}")' for attribute '_attr_native_value' in entity 'sensor.weatheralerts_malta_alert_5'

dcf1999 commented 2 years ago

It all works fine. I get the notifications. It’s just annoying seeing the errors and warnings in the log.

mjnovotny82 commented 2 years ago

Another Wisconsinite using weatheralerts... or an Illinoisian??? Awesome either way! I'm between Milwaukee & Sheboygan along Lake Michigan.

I was getting the similar errors and it was working fine, too. I severely modified some of code logics to prevent the errors in the logs and added some custom stuff (icons, sounds, lights, extras for Tornado Warning / Tornado Emergency, etc.) for me. I've attached my yaml as a text file for referencing.

weatheralerts.yaml.txt

dcf1999 commented 2 years ago

Born and raised Wisconsinite but fib now for my job lol. Family has a place up north. Will hopefully be there a lot this weekend to sled.

I’ll look over the file. I’m pretty new to HA but not new to coding. I’m having trouble understanding how everything in HA interacts and how to code it. So far it’s over my head. I moved from Smartthings and it’s a big learning curve.

I too would like to modify it and trigger an automation for tornado warnings and such.

mjnovotny82 commented 2 years ago

I'm about 5 months into HA and I agree strong learning curve but well worth it. I'm not into the Github for saving files, never learned it... maybe one day. Let me know and I can zip up my files for my Lifx lights, sounds, etc.

dcf1999 commented 2 years ago

I used your code and it cleared up all the errors except for one.


Logger: homeassistant.helpers.entity Source: helpers/entity.py:549 First occurred: January 12, 2022, 4:32:45 PM (2 occurrences) Last logged: January 12, 2022, 4:32:45 PM

Entity sensor.weatheralerts_vilas (<class 'custom_components.weatheralerts.sensor.WeatherAlertsSensor'>) implements device_state_attributes. Please report it to the custom component author. Entity sensor.weatheralerts_malta (<class 'custom_components.weatheralerts.sensor.WeatherAlertsSensor'>) implements device_state_attributes. Please report it to the custom component author.


It even clears up some other errors that I didn’t know were related. Thanks for the file. I’m going to go through it and might modify it to fit some other needs.

I don’t know if this is overboard, but I want to create a binary sensor that turns on/off if there is a tornado warning. Then an automation that triggers in response to that binary sensor.

mjnovotny82 commented 2 years ago

I used your code and it cleared up all the errors except for one.

Awesome, glad it help out.

Logger: homeassistant.helpers.entity Source: helpers/entity.py:549 First occurred: January 12, 2022, 4:32:45 PM (2 occurrences) Last logged: January 12, 2022, 4:32:45 PM

Entity sensor.weatheralerts_vilas (<class 'custom_components.weatheralerts.sensor.WeatherAlertsSensor'>) implements device_state_attributes. Please report it to the custom component author. Entity sensor.weatheralerts_malta (<class 'custom_components.weatheralerts.sensor.WeatherAlertsSensor'>) implements device_state_attributes. Please report it to the custom component author.

It even clears up some other errors that I didn’t know were related. Thanks for the file. I’m going to go through it and might modify it to fit some other needs.

Be careful if you're going to modify any of the custom_components files and you are subscribed to them via HACS, etc. Those files usually get overwritten if an author pushes an update.

I don’t know if this is overboard, but I want to create a binary sensor that turns on/off if there is a tornado warning. Then an automation that triggers in response to that binary sensor.

The binary sesnor may not be needed if you check in each of the the 5 alert sensors (sensor.weatheralerts_1_alert_1, sensor.weatheralerts_1_alert_2, etc. replacing what your sensor names are) in another automation, but it wouldn't hurt either. I have noticed that sometimes there is a 30-60 seconds of unknown/unavailable status timeout in the History bar graphs when the script detects a NWS update which it may turn off and then back on the binary sensor. The original yaml file from the author seemed to do that more before I'm implementing my changes.

I'm constantly tweaking the yaml file I posted. This past weekend was an example, which you have the changes... My HA showed "Winter Weather Advisory" in alert_1 and then updated to "Special Weather Statement" in alert_1 and move "Winter Weather Advisory" to alert_2 but I didn't get an alert... maybe because the "Winter Weather Advisory" ID was the same and didn't trigger the automation. I added more logic to detect changes in any of the 5 alert fields and trigger if there was any additions, ID updates, etc., but I didn't detect if sensor.weatheralerts_1_active_alerts integer changed value. I believe the default logic was if sensor.weatheralerts_1_active_alerts was >= 1 or something like that.

Best of luck!

jlverhagen commented 2 years ago

Thanks @mjnovotny82 for sharing your yaml. I have included some of those changes in the package update to address the template related errors. These errors and warnings should now be resolved with v0.1.5.

Coolie1101 commented 2 years ago

These errors and warnings should now be resolved with v0.1.5.

Still seeing the same errors as in the OP with v0.1.5 and shows up 8045 times

Template variable error: list object has no element 1 when rendering '{% if (states('sensor.southern_westchester') != 'unavailable') and (state_attr('sensor.southern_westchester', 'alerts')[1] != null) or ((states('sensor.southern_westchester') == 'unavailable') and (as_timestamp(state_attr('sensor.southern_westchester', 'alerts')[1].endsExpires) - as_timestamp(now()) > 0)) %} on {% else %} off {% endif %}'
2:16:44 PM – (ERROR) helpers/template.py - message first occurred at April 27, 2022, 9:53:32 PM and shows up 8045 times
Template variable error: list object has no element 2 when rendering '{% if (states('sensor.southern_westchester') != 'unavailable') and (state_attr('sensor.southern_westchester', 'alerts')[2] != null) or ((states('sensor.southern_westchester') == 'unavailable') and (as_timestamp(state_attr('sensor.southern_westchester', 'alerts')[2].endsExpires) - as_timestamp(now()) > 0)) %} on {% else %} off {% endif %}'
Template variable error: list object has no element 3 when rendering '{% if (states('sensor.southern_westchester') != 'unavailable') and (state_attr('sensor.southern_westchester', 'alerts')[3] != null) or ((states('sensor.southern_westchester') == 'unavailable') and (as_timestamp(state_attr('sensor.southern_westchester', 'alerts')[3].endsExpires) - as_timestamp(now()) > 0)) %} on {% else %} off {% endif %}'
Template variable error: list object has no element 4 when rendering '{% if (states('sensor.southern_westchester') != 'unavailable') and (state_attr('sensor.southern_westchester', 'alerts')[4] != null) or ((states('sensor.southern_westchester') == 'unavailable') and (as_timestamp(state_attr('sensor.southern_westchester', 'alerts')[4].endsExpires) - as_timestamp(now()) > 0)) %} on {% else %} off {% endif %}'

This is the part that's causing the error: (as_timestamp(state_attr('sensor.southern_westchester', 'alerts')[1].endsExpires)

Seems that the error occurs if there isn't any element above [0].

jlverhagen commented 2 years ago

I believe the errors you are seeing are due to using an older version of the template file, or a template file that hasn't been fully updated to match the current version. Do a search in your current template file for this bit of code:

== 'unavailable') and (as_timestamp(state_attr('

You will probably find four lines containing that code. Double check the current version on github for the changes needed to fix those lines in your template file, and that should stop those errors. If you need help updating your customized template file, attach it to a reply here and I'll take a look at it.

Coolie1101 commented 2 years ago

You will probably find four lines containing that code.

Indeed I do.

The new package is totally different, quite alot of changes to be made.

Update: All good now, thanks for following up.