Open EdLeckert opened 10 months ago
With the proposed change in place, the sensor.nws_alerts
entity remained stable throughout the alert period in spite of the fact that the API briefly returned errors numerous times beginning at about midnight. The repeated alert notifications from this bouncing of the service in the middle of the night would have been very annoying.
The change I am proposing is to essentially cancel the entity's update in the case of this specific error, as if the fetch attempt had never happened.
The entity's history:
The error log:
Home Assistant Core
2023-11-04 00:05:26.281 WARNING (MainThread) [custom_components.nws_alerts] Error fetching most recent data from NWS
2023-11-04 00:16:29.049 WARNING (MainThread) [custom_components.nws_alerts] Error fetching most recent data from NWS
2023-11-04 00:17:29.054 WARNING (MainThread) [custom_components.nws_alerts] Error fetching most recent data from NWS
2023-11-04 01:06:33.213 WARNING (MainThread) [custom_components.nws_alerts] Error fetching most recent data from NWS
2023-11-04 01:21:33.059 WARNING (MainThread) [custom_components.nws_alerts] Error fetching most recent data from NWS
2023-11-04 01:23:33.357 WARNING (MainThread) [custom_components.nws_alerts] Error fetching most recent data from NWS
2023-11-04 01:27:35.260 WARNING (MainThread) [custom_components.nws_alerts] Error fetching most recent data from NWS
2023-11-04 02:06:38.214 WARNING (MainThread) [custom_components.nws_alerts] Error fetching most recent data from NWS
2023-11-04 02:09:39.246 WARNING (MainThread) [custom_components.nws_alerts] Error fetching most recent data from NWS
2023-11-04 05:04:14.284 WARNING (MainThread) [custom_components.nws_alerts] Error fetching most recent data from NWS
2023-11-04 05:08:15.221 WARNING (MainThread) [custom_components.nws_alerts] Error fetching most recent data from NWS
2023-11-04 08:02:49.109 WARNING (MainThread) [custom_components.nws_alerts] Error fetching most recent data from NWS
It appears that there was a PR to address this several years ago as #7, but those changes have been lost along the way.
Errors returned from the NWS API cause the integration state to become "unavailable" until the next successful data fetch. At a poll frequency of one minute, this intermittent behavior can happen frequently.
The logged error is:
The data returned from the NWS API is something like:
If this happens when no alerts are active it is hardly noticed. However, if an alert is active, any templates looking for a state (count) of ">0" will no longer evaluate to True. In my case, this sets my
alert
entity back toidle
, causing automations to declare the alert "expired", only to declare a "new" alert a minute later when the API again responds with good data. When notifications are issued each time this happens, especially in the middle of the night, it can be extremely annoying.I will propose a potential solution for this by way of a PR. If anyone has a workaround for this problem I would love to hear it.