custom-components / weatheralerts

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

Errors - list object has no element 0 #42

Closed drjjr2 closed 3 years ago

drjjr2 commented 3 years ago

Version of the custom_component

v0.1.3

Describe the bug Multiple errors in the log - list object has no element 0. This repeats for elements 0-4

Log

2020-12-08 07:45:47 ERROR (MainThread) [homeassistant.components.template.template_entity] TemplateError('UndefinedError: list object has no element 0') while processing template 'Template("{% if (states('sensor.weatheralerts_1') != 'unavailable') and (state_attr('sensor.weatheralerts_1', 'alerts')[0] != null) or ((states('sensor.weatheralerts_1') == 'unavailable') and (as_timestamp(state_attr('sensor.weatheralerts_1', 'alerts')[0].endsExpires) - as_timestamp(now()) > 0)) %} on {% else %} off {% endif %}")' for attribute '_state' in entity 'sensor.weatheralerts_1_alert_1'

jlverhagen commented 3 years ago

Thanks for the report. With the current state of the template code in the YAML package, this is an expected error. It just means the template is being processed, but the weather alerts object array isn't available at that exact moment the template is being processed. It will occur during Home Assistant startup if the template code in the YAML package is processed before the WeatherAlerts integration is fully loaded. I believe it will also occur if the weather.gov alerts API is too slow to respond or it is experiencing an API outage. I was going to add some alert object array checks in the template, but decided not to do that since it would make the template significantly larger and much more difficult to follow and maintain than it already is.

These should be harmless errors. If you are experiencing any other WeatherAlerts or Home Assistant problems you feel might be caused by theses errors, please let me know what those issues are so I can investigate further.

I'm planning to upgrade WeatherAlerts (early 2021) and will rewrite the YAML packages to be much simpler. The simpler YAML packages will eliminate those template errors.

drjjr2 commented 3 years ago

Awesome. Thanks for the explanation.

On Sat, Dec 12, 2020 at 6:59 PM Jason Verhagen notifications@github.com wrote:

Thanks for the report. With the current state of the template code in the YAML package, this is an expected error. It just means the template is being processed, but the weather alerts object array isn't available at that exact moment the template is being processed. It will occur during Home Assistant startup if the template code in the YAML package is processed before the WeatherAlerts integration is fully loaded. I believe it will also occur if the weather.gov alerts API is too slow to respond or it is experiencing an API outage. I was going to add some alert object array checks in the template, but decided not to do that since it would make the template significantly larger and much more difficult to follow and maintain than it already is.

These should be harmless errors. If you are experiencing any other WeatherAlerts or Home Assistant problems you feel might be caused by theses errors, please let me know what those issues are so I can investigate further.

I'm planning to upgrade WeatherAlerts (early 2021) and will rewrite the YAML packages to be much simpler. The simpler YAML packages will eliminate those template errors.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/custom-components/weatheralerts/issues/42#issuecomment-743928879, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQT75OLUEWJGNG3FLCWWUP3SUQGWLANCNFSM4USAJCUA .

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.