Weather Alert Docs?

Posted on
Wed Oct 11, 2023 10:12 am
NOVAmike offline
Posts: 4
Joined: Feb 16, 2023

Weather Alert Docs?

Greetings,

I found the NOAA Weather docs very useful for the Weather Station device type but I'm at a loss understanding the Weather Alerts type. I've logged the result of str() on the device and while interesting, it doesn't tell me much about what to expect in the various device state strings.

I'm wondering things like:

What are the possible values for "category", "certainty" and "severity"?
What is the sort order from alert1 to alert5 when multiple alerts exist at the same time? Date/time posted? Date/time effective? Severity? No particular order?

On a hunch that all of this is ultimately defined by NOAA I looked at their docs on the various data feeds they offer but haven't found a match.

Is there documentation somewhere for an Alerts device type like there is for the Station type?

My goal is to estimate the likelihood of a storm-caused electrical grid failure looking forward about 1h to 8h so I can modulate my solar battery system's backup reserve percentage. If a bad storm is likely I was more backup reserve in case the grid does fail. If a grid loss is unlikely I want to lower the backup reserve so I have more battery capacity for Time Of Use optimizations.

Thanks for any pointers.
-Mike

Posted on
Wed Oct 11, 2023 2:59 pm
DaveL17 offline
User avatar
Posts: 6759
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Weather Alert Docs?

The weather alert device interrogates the following NOAA API endpoint:

Code: Select all
https://api.weather.gov/alerts/active?point={lat},{long}
where you replace {lat} and {long} with your lat/long values (from the device config dialog). If you enter that (completed) URL into a browser, you should see the XML output from the API. This is all the possible information that the plugin device (could) display. In the current version, the device doesn't display 100 percent of this information.

NOVAmike wrote:
What are the possible values for "category", "certainty" and "severity"?

The API doesn't specify all the possible values for the category key, but you may find what you're looking for in the documentation here: https://www.weather.gov/documentation/services-web-alerts

The possible certainty values are: Observed, Likely, Possible, Unlikely, Unknown
The possible severity values are: Extreme, Severe, Moderate, Minor, Unknown

NOVAmike wrote:
What is the sort order from alert1 to alert5 when multiple alerts exist at the same time? Date/time posted? Date/time effective? Severity? No particular order?

The device can report up to five simultaneous alerts. The states are populated in the order that they're delivered in the API.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Sun Oct 22, 2023 4:06 pm
wideglidejrp offline
User avatar
Posts: 555
Joined: Jan 15, 2012
Location: Danbury, CT

Re: Weather Forecasts

The custom states for the weather forecast includes this afternoon and tonight. It does not include tomorrow. If I want to announce tomorrow's forecast every night, do I need to have a trigger for each day?

John R Patrick
Author of
Home Attitude

Posted on
Sun Oct 22, 2023 5:26 pm
DaveL17 offline
User avatar
Posts: 6759
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Weather Alert Docs?

wideglidejrp wrote:
The custom states for the weather forecast includes this afternoon and tonight. It does not include tomorrow. If I want to announce tomorrow's forecast every night, do I need to have a trigger for each day?

That's right. At the moment, the states are provided as: "This Afternoon", "Tonight", and "Monday" which is what the NOAA forecast API provides. If you want to find out what the "Tomorrow" forecast is, you'll need to determine what today is, add one day, and get that day's name. Something like this:

Code: Select all
import datetime as dt

today = dt.datetime.today()  # get today's datetime object
tomorrow = today + dt.timedelta(days=1)  # add 1 day
forecast_device = indigo.devices[258069669].states  # get all the device states
tomorrow_period = [period for period, name in forecast_device.items() if name == f"{tomorrow:%A}"][0]  # find the period name for the appropriate full day name '%A is the datetime format specifier for the day's full name.

forecast_text = forecast_device['forecast_detailed_' + tomorrow_period[-2:]]
indigo.server.log(f"Tomorrow's forcast is: {forecast_text}")
Doing it this way, you wouldn't need to create a trigger for each day, you could use the same trigger each day. This is a fairly brute force way to do this; there is probably a more elegant way.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Sat Feb 17, 2024 11:11 am
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Weather Alert Docs?

DaveL17 wrote:
That's right. At the moment, the states are provided as: "This Afternoon", "Tonight", and "Monday" which is what the NOAA forecast API provides. If you want to find out what the "Tomorrow" forecast is, you'll need to determine what today is, add one day, and get that day's name. Something like this:
... ...
Doing it this way, you wouldn't need to create a trigger for each day, you could use the same trigger each day. This is a fairly brute force way to do this; there is probably a more elegant way.

Thanks for this snippet. May I offer a small upgrade. This will create a log entry that is easier to read, and something that could be more easily mailed, etc.
Code: Select all
import datetime as dt

today = dt.datetime.today()  # get today's datetime object
tomorrow = today + dt.timedelta(days=1)  # add 1 day
forecast_device = indigo.devices[585809628].states  # get all the device states
tomorrow_period = [period for period, name in forecast_device.items() if name == f"{tomorrow:%A}"][0] 
# find the period name for the appropriate full day name '%A is the datetime format specifier for the day's full name.
max_length = 80

forecast_text = forecast_device['forecast_detailed_' + tomorrow_period[-2:]]

log_string = "Tomorrow's forcast is:\n"
line = 0

for i in range(len(forecast_text)):
    log_string = log_string + forecast_text[i]
    line = line + 1
    if (line >= max_length) and (forecast_text[i] == ' '):
                  # add line break each time pgcd equal 0
        log_string = log_string + '\n'
        line = 0
 
indigo.server.log(log_string)

For example:
Code: Select all
 Feb 17, 2024 at 09:03:20
   Script                          Tomorrow's forecast is:
Rain showers between 10am and 4pm, then showers and thunderstorms. Mostly cloudy.
High near 64, with temperatures falling to around 60 in the afternoon. Southeast
wind 8 to 23 mph, with gusts as high as 26 mph. Chance of precipitation is 100%.
New rainfall amounts between a half and three quarters of an inch possible.

Posted on
Sat Feb 17, 2024 12:15 pm
DaveL17 offline
User avatar
Posts: 6759
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Weather Alert Docs?

berkinet wrote:
This will create a log entry that is easier to read, and something that could be more easily mailed, etc.


Thanks for sharing. FWIW, your script could be simplified a bit by using the textwrap module.

Code: Select all
import textwrap

my_text = "Rain showers between 10am and 4pm, then showers and thunderstorms. Mostly cloudy. High near 64, with temperatures falling to around 60 in the afternoon. Southeast wind 8 to 23 mph, with gusts as high as 26 mph. Chance of precipitation is 100%. New rainfall amounts between a half and three quarters of an inch possible."

indigo.server.log(f"Tomorrow's forecast is:\n{textwrap.fill(my_text, 80)}")

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Sat Feb 17, 2024 2:03 pm
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Weather Alert Docs?

DaveL17 wrote:
... FWIW, your script could be simplified a bit by using the textwrap module.

:oops: I knew there had to be a better way, but couldn't find it. Thanks

Posted on
Thu Feb 22, 2024 1:19 pm
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Weather Alert Docs?

Sooooo... With a little time on my hands, I decided to tweak the reporting script. Rather than trying to figure out when 'tomorrow' is, I just grabbed the first 3 periods. Then, with help from DaveL17, I formatted the output for logging. FWIW, here it us.
Code: Select all
import textwrap

forecast_device = indigo.devices[585809628].states  # get all the device states
max_length = 80

indigo.server.log(f"For Berkeley, California", type='NOAA Weather Forecast')
indigo.server.log(f"{textwrap.fill(forecast_device['forecast_detailed_01'], max_length)}", type=forecast_device['period_name_01'])
indigo.server.log(f"{textwrap.fill(forecast_device['forecast_detailed_02'], max_length)}", type=forecast_device['period_name_02'])
indigo.server.log(f"{textwrap.fill(forecast_device['forecast_detailed_03'], max_length)}\n", type=forecast_device['period_name_03'])
Which produces this.
Screenshot 2024-02-22 at 11.17.23.png
Screenshot 2024-02-22 at 11.17.23.png (183.95 KiB) Viewed 701 times

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 3 guests