custom-components / weatheralerts

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

Alert being shown when there is none - Timeout error #37

Closed collinsjoshw closed 4 years ago

collinsjoshw commented 4 years ago

Version of the custom_component 0.1.1

Describe the bug An active alert is being shown while there is none. Looks like there is a timeout error after enabling debug logging.

Log

2020-04-20 08:16:08 ERROR (MainThread) [custom_components.weatheralerts.sensor] [TimeoutError] 
2020-04-20 08:16:08 WARNING (MainThread) [homeassistant.components.sensor] Platform weatheralerts not ready yet. Retrying in 30 seconds.
2020-04-20 08:16:12 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.weatheralerts_1_active_alerts fails
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 279, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 474, in async_device_update
    await self.async_update()
  File "/usr/src/homeassistant/homeassistant/components/template/sensor.py", line 224, in async_update
    self._state = self._template.async_render()
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 221, in async_render
    return compiled.render(kwargs).strip()
  File "/usr/local/lib/python3.7/site-packages/jinja2/environment.py", line 1090, in render
    self.environment.handle_exception()
  File "/usr/local/lib/python3.7/site-packages/jinja2/environment.py", line 832, in handle_exception
    reraise(*rewrite_traceback_stack(source=source))
  File "/usr/local/lib/python3.7/site-packages/jinja2/_compat.py", line 28, in reraise
    raise value.with_traceback(tb)
  File "<template>", line 1, in top-level template code
TypeError: 'NoneType' object is not iterable
jlverhagen commented 4 years ago

Thanks for the report. I believe the issue you describe with the old alerts not clearing stems from the timeout issue. The timeout issue is most likely a problem with the weather.gov site being too slow to respond or having other server issues. If the weatheralerts integration can't download the alerts feed due to a weather.gov web site error or slow response time, the previous successfully downloaded alerts will persist until the next successful alerts download triggers an update. This prevents important alerts from disappearing and reappearing every time the weather.gov alerts feed has issues, which is apparently quite often.

To fix this, I will try to add some additional logic to the YAML code to prevent expired alerts from being displayed and counted.

stale[bot] commented 4 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.

jlverhagen commented 4 years ago

Bumping this, to keep the issue open until it's fixed.

stale[bot] commented 4 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.

jlverhagen commented 4 years ago

I will be pushing a release in the next few days with updates to the YAML packages that should address the issue of expired alerts still being displayed if the weather.gov alerts feed has issues and the old alerts hang around until the alerts feed is working again. If you are not using the YAML packages, you will have to post a reply here with the YAML or JINJA template code you are using and I will see if I can suggest some edits to make it behave like the YAML package template sensors.

collinsjoshw commented 4 years ago

I am using the YAML packages. Look forward to the update. It hasn't been as bad lately with the lack of alerts, but sure to start again once thunderstorm season is in full swing.

jlverhagen commented 4 years ago

OK, I just have to commit the YAML packages and finish the documentation update and I'll push out the next release. The YAML packages should be able to turn off the alert sensors that have passed the ends time, or expires time if ends time is not available, if the weather.gov alert API is experiencing an outage. And the alert count sensor will also keep proper count as well. I finally verified and (hopefully) fixed a cause of constant repeated notifications. Then I had some trouble trying to implement a dynamic timeout feature that seemed to cause some instability within the lovelace UI, so I only added a timeout increase during the initial platform setup.

jlverhagen commented 4 years ago

This issue should now be resolved. Just be sure to manually download and install the YAML packages after updating the weatheralerts integration (the YAML packages don't update or install via HACS), and then restart Home Assistant. The YAML packages will use the new 'endsExpires' attribute to turn the individual alerts states to 'off' if the main weatheralerts sensor is unavailable due to weather.gov API server outages. The 'endsExpires' attribute will be set equal to the 'expires' alert attribute datetime if the 'ends' alert attribute is null, otherwise it will be set equal to the 'ends' alert attribute datetime.