finity69x2 / nws_alerts

An updated version of the nws_alerts custom integration for Home Assistant
88 stars 29 forks source link

State attributes for sensor.nws_alerts_zone exceed maximum size of 16384 bytes. #95

Open rct opened 1 week ago

rct commented 1 week ago

Not sure if this is an issue, FYI, or something for discussion: Currently there are 10 (!) alerts by zone, so the combined attribute becomes too big to store:

WARNING (Recorder) [homeassistant.components.recorder.db_schema] State attributes for sensor.nws_alerts_zone exceed maximum size of 16384 bytes. This can cause database performance issues; Attributes will not be stored

Also an FYI, NWS alerts by zone is currently yielding 10 alerts (Zones are `NYC103,NYZ081,NYZ213), where zone alerts by coordinates is yielding only 3. There's a lot of overlap/redundancy in the zones attribute..

I'm not sure how useful it is to have the alert text stored in the database. Possibly this is something that should be configured to be ignored by recorder.

finity69x2 commented 1 week ago

Yeah, if there are a lot of alerts that is going to happen and there isn't anything the integration can do about that.

As far as the zone/coordinates overlap keep in mind that there might be users who use only one or the other and not both. So there is an expectation that there should logically be an overlap. Again, not something the integration can do anything about.

as to the recorder, you can exclude the entire entity from being recorded in the recorder but I'm pretty sure it's not possible to just exclude the attributes. I'm pretty sure it's all or nothing.

rct commented 1 week ago

As far as the zone/coordinates overlap keep in mind that there might be users who use only one or the other and not both. So there is an expectation that there should logically be an overlap.

Sorry for making things confusing, the 10 alerts is ONLY in the by zone entity/service. IIRC, I'm using the default choice of 3 zones NYC103,NYZ081,NYZ213. I wasn't talking about the overlap of running both services.

For the Zone entity/service: There are 8 'Coastal Flood Advisories' and 2 'Rip Current Statements".
The by coordinates entity/service has only: only 2 'Coastal Flood Advisories' and 1 'Rip Current Statement'.

I've been running them in parallel to compare and figure out which I'd rather use long term.

rct commented 1 week ago

Have you come across anything that describes the update/replacement/expiration process? Looks like I started to dig into this in Oct 2022, but don't remember how far I got.

Here are the URLs for the 10 alerts:

egrep -i https: hass-10-alerts-2024-09-20.txt  | sort | uniq -c
      1     https://api.weather.gov/alerts/urn:oid:2.49.0.1.840.0.31f6bbb0ce2bea7c506f7e828e7e407cb8fd6eb3.005.1
      1     https://api.weather.gov/alerts/urn:oid:2.49.0.1.840.0.31f6bbb0ce2bea7c506f7e828e7e407cb8fd6eb3.005.2
      1     https://api.weather.gov/alerts/urn:oid:2.49.0.1.840.0.31f6bbb0ce2bea7c506f7e828e7e407cb8fd6eb3.005.3
      1     https://api.weather.gov/alerts/urn:oid:2.49.0.1.840.0.31f6bbb0ce2bea7c506f7e828e7e407cb8fd6eb3.005.4
      1     https://api.weather.gov/alerts/urn:oid:2.49.0.1.840.0.31f6bbb0ce2bea7c506f7e828e7e407cb8fd6eb3.007.1
      1     https://api.weather.gov/alerts/urn:oid:2.49.0.1.840.0.31f6bbb0ce2bea7c506f7e828e7e407cb8fd6eb3.007.2
      1     https://api.weather.gov/alerts/urn:oid:2.49.0.1.840.0.31f6bbb0ce2bea7c506f7e828e7e407cb8fd6eb3.007.3
      1     https://api.weather.gov/alerts/urn:oid:2.49.0.1.840.0.31f6bbb0ce2bea7c506f7e828e7e407cb8fd6eb3.009.1
      1     https://api.weather.gov/alerts/urn:oid:2.49.0.1.840.0.31f6bbb0ce2bea7c506f7e828e7e407cb8fd6eb3.009.2
      1     https://api.weather.gov/alerts/urn:oid:2.49.0.1.840.0.31f6bbb0ce2bea7c506f7e828e7e407cb8fd6eb3.011.1

It looks like there may be 4 versions of 2.49.0.1.840.0.31f6bbb0ce2bea7c506f7e828e7e407cb8fd6eb3.005.1, 3 versions of 840.0.31f6bbb0ce2bea7c506f7e828e7e407cb8fd6eb3.007.1 etc. (The last component is 1,2,3,4).

In the alerts .2, .3, and .4 there is a property: properties.parameters.expiredReferences that looks like it refers to an older version:

$ jq .properties.parameters.expiredReferences  < urn%3Aoid%3A2.49.0.1.840.0.31f6bbb0ce2bea7c506f7e828e7e407cb8fd6eb3.005.2
[
  "w-nws.webmaster@noaa.gov,urn:oid:2.49.0.1.840.0.f098333f951f08579b2c1098aa26a9dcb0e5ce75.004.2,2024-09-19T17:06:00-04:00"
]

$ jq .properties.parameters.expiredReferences  < urn%3Aoid%3A2.49.0.1.840.0.31f6bbb0ce2bea7c506f7e828e7e407cb8fd6eb3.005.3
[
  "w-nws.webmaster@noaa.gov,urn:oid:2.49.0.1.840.0.f098333f951f08579b2c1098aa26a9dcb0e5ce75.004.1,2024-09-19T17:06:00-04:00"
]

$ jq .properties.parameters.expiredReferences  < urn%3Aoid%3A2.49.0.1.840.0.31f6bbb0ce2bea7c506f7e828e7e407cb8fd6eb3.005.4
[
  "w-nws.webmaster@noaa.gov,urn:oid:2.49.0.1.840.0.f098333f951f08579b2c1098aa26a9dcb0e5ce75.004.3,2024-09-19T17:06:00-04:00 w-nws.webmaster@noaa.gov,urn:oid:2.49.0.1.840.0.dad6d734b2e00c61cbca651ddde0f83613a40124.003.3,2024-09-19T12:26:00-04:00 w-nws.webmaster@noaa.gov,urn:oid:2.49.0.1.840.0.52154e0e2e4552d627462198224666822f48fa04.005.3,2024-09-19T06:27:00-04:00 w-nws.webmaster@noaa.gov,urn:oid:2.49.0.1.840.0.5cb4516a0545c71e0ea25aa19457243fd4cdcd4b.002.3,2024-09-19T05:09:00-04:00 w-nws.webmaster@noaa.gov,urn:oid:2.49.0.1.840.0.136a7169d510a8ccb67982438fa57cd5055cdf16.004.3,2024-09-18T16:42:00-04:00 w-nws.webmaster@noaa.gov,urn:oid:2.49.0.1.840.0.2a03517952e726e214f13cd383e5db02785a152f.004.2,2024-09-18T05:25:00-04:00 w-nws.webmaster@noaa.gov,urn:oid:2.49.0.1.840.0.b638d4f06d518bf1e6a34466d0ce888a6c245ed7.003.1,2024-09-17T15:29:00-04:00 w-nws.webmaster@noaa.gov,urn:oid:2.49.0.1.840.0.4e4cd96e684cbfb9b45c68edcea1f2aab5da1a28.002.1,2024-09-17T04:12:00-04:00 w-nws.webmaster@noaa.gov,urn:oid:2.49.0.1.840.0.e2bf75f172ef910918b3065e64f78979d435625d.001.1,2024-09-16T17:40:00-04:00"
]

but I don't see how they relate to each other yet. Here's a diff between .005.1 and .005.2

$ diff urn%3Aoid%3A2.49.0.1.840.0.31f6bbb0ce2bea7c506f7e828e7e407cb8fd6eb3.005.1 urn%3Aoid%3A2.49.0.1.840.0.31f6bbb0ce2bea7c506f7e828e7e407cb8fd6eb3.005.2
10c10
<     "id": "https://api.weather.gov/alerts/urn:oid:2.49.0.1.840.0.31f6bbb0ce2bea7c506f7e828e7e407cb8fd6eb3.005.1",
---
>     "id": "https://api.weather.gov/alerts/urn:oid:2.49.0.1.840.0.31f6bbb0ce2bea7c506f7e828e7e407cb8fd6eb3.005.2",
14c14
<         "@id": "https://api.weather.gov/alerts/urn:oid:2.49.0.1.840.0.31f6bbb0ce2bea7c506f7e828e7e407cb8fd6eb3.005.1",
---
>         "@id": "https://api.weather.gov/alerts/urn:oid:2.49.0.1.840.0.31f6bbb0ce2bea7c506f7e828e7e407cb8fd6eb3.005.2",
16c16
<         "id": "urn:oid:2.49.0.1.840.0.31f6bbb0ce2bea7c506f7e828e7e407cb8fd6eb3.005.1",
---
>         "id": "urn:oid:2.49.0.1.840.0.31f6bbb0ce2bea7c506f7e828e7e407cb8fd6eb3.005.2",
29c29,36
<         "references": [],
---
>         "references": [
>             {
>                 "@id": "https://api.weather.gov/alerts/urn:oid:2.49.0.1.840.0.b4f862ac334abc014aa9edd949d758096878cb1e.005.3",
>                 "identifier": "urn:oid:2.49.0.1.840.0.b4f862ac334abc014aa9edd949d758096878cb1e.005.3",
>                 "sender": "w-nws.webmaster@noaa.gov",
>                 "sent": "2024-09-19T17:24:00-04:00"
>             }
>         ],
32c39
<         "onset": "2024-09-20T20:00:00-04:00",
---
>         "onset": "2024-09-21T08:00:00-04:00",
34c41
<         "ends": "2024-09-21T02:00:00-04:00",
---
>         "ends": "2024-09-21T16:00:00-04:00",
36c43
<         "messageType": "Alert",
---
>         "messageType": "Update",
38,41c45,48
<         "severity": "Minor",
<         "certainty": "Likely",
<         "urgency": "Expected",
<         "event": "Coastal Flood Advisory",
---
>         "severity": "Moderate",
>         "certainty": "Possible",
>         "urgency": "Future",
>         "event": "Coastal Flood Watch",
44c51
<         "headline": "Coastal Flood Advisory issued September 20 at 5:29AM EDT until September 21 at 2:00AM EDT by NWS Upton NY",
---
>         "headline": "Coastal Flood Watch issued September 20 at 5:29AM EDT until September 21 at 4:00PM EDT by NWS Upton NY",
47c54
<         "response": "Monitor",
---
>         "response": "Prepare",
62a70,72
>             "EAS-ORG": [
>                 "WXR"
>             ],
64c74
<                 "/O.NEW.KOKX.CF.Y.0040.240921T0000Z-240921T0600Z/"
---
>                 "/O.EXT.KOKX.CF.A.0007.240921T1200Z-240921T2000Z/"
67c77,80
<                 "2024-09-21T06:00:00+00:00"
---
>                 "2024-09-21T20:00:00+00:00"
>             ],
>             "expiredReferences": [
>                 "w-nws.webmaster@noaa.gov,urn:oid:2.49.0.1.840.0.f098333f951f08579b2c1098aa26a9dcb0e5ce75.004.2,2024-09-19T17:06:00-04:00"

It looks like .500.2 might contain a forward reference to .005.3?

finity69x2 commented 6 days ago

No I've never dug in that far.

I actually only really care about severe weather events. All the other stuff is solely tangentially informational.

I'm not sure how the NWS handles zones vs coordinate alert reporting. But in my mind we are at the will of the NWS API for getting the information they provide to us. There's not a whole lot of processing the integration could (or should) do.

Anything further than just providing the data from the NWS API should be up to the user to implement as they see fit.