Rudd-O / homeassistant-meteoswiss

:sun_behind_rain_cloud: :switzerland: Meteo Swiss Integration for Home Assistant (forked from websylv)
83 stars 10 forks source link

Real-time sensor for lightning and hail warnings / reports #57

Open jiiins opened 3 weeks ago

jiiins commented 3 weeks ago

The app's radar can display lightning and hale reports, which can be very useful for automation, like pulling up curtains, closing vents,... It would be great if they could be exposed as sensors (distance?).

daphil012 commented 3 weeks ago

The app's radar can display lightning and hale reports, which can be very useful for automation, like pulling up curtains, closing vents,... It would be great if they could be exposed as sensors (distance?).

Regarding hail altert: My insurance company supports a custom developed solution (which uses swiss meteo information) to alert in case of hail in your region. You need to register but it is free of charge. JFYI

https://meteo.netitservices.com/

Find more information here: https://www.vkg.ch/de/praevention/naturgefahren and https://www.hagelschutz-einfach-automatisch.ch/eigentuemer-verwaltungen.html

jiiins commented 2 weeks ago

Thanks a lot, sounds very interesting! I submitted the application, let's see...

Rudd-O commented 1 week ago

We could add a sensor that emits that warning when the forecast updates but it's not clear to me what the warning sensor should look like, because the format of the warningsOverview in our API URL call is not documented to my knowledge, and I can't find any current warning on the system:

$ curl 'https://app-prod-ws.meteoswiss-app.ch/v1/forecast?plz=671000&graph_startLowResolution=true&warning=true' | jq .
{
  "plz": 671000,
  "currentWeather": {
    "time": 1725801600000,
    "icon": 20,
    "iconV2": 20,
    "temperature": 19.0
  },
  "regionForecast": [
    {
      "dayDate": "2024-09-08",
      "iconDay": 20,
      "iconDayV2": 20,
      "temperatureMax": 20,
      "temperatureMin": 17,
      "precipitation": 43.3,
      "precipitationMin": 38.0,
      "precipitationMax": 74.8
    },

...
      7.7,
      5.9,
      5.5,
      5.6,
      5.7,
      5.7,
      5.6,
      7.8,
      6.9,
      6.3,
      5.8,
      6.8,
      7.7,
      8.7,
      7.0,
      6.4,
      6.6,
      6.9,
      7.7,
      11.0,
      9.5,
      8.8,
      8.7
    ]
  },
  "warningsOverview": []
}

You would have to provide me with the type of the warningsOverview data or good samples of the data so I can add it to hamsclientfork.

Rudd-O commented 1 week ago

FYI the current condition has one of potential states lightning or hail:

image

image

Maybe that's enough for you.

Rudd-O commented 1 week ago

Warnings data obtained but it is insufficient:

image

from URL https://app-prod-ws.meteoswiss-app.ch/v1/plzDetail?plz=390000

Sample data attached:

plzDetail.json

We need to know:

With that resolved, we can create a binary sensor that is of type safety, which could reflect the warning of the highest level (if > 1 with the same level, then the latest one) and sport the following attributes (mostly to be used in templates):

The sensor would only be active (true) when the current UNIX timestamp (UTC) is greater than validFrom.

Alternatively, if a sensor is desired that is not of type binary, but rather an enum type of sensor, we could use warnType to set the sensor type (based on an IntEnum we would provide, whose correspondences to each integer value is documented by MeteoSchweiz):

In case this sensor provides a textual state, this property can be used to provide a list of possible states. Requires the enum device class to be set. Cannot be combined with state_class or native_unit_of_measurement.

The other attributes would be the same.