NWS API - Pipe alerts into your e-ink weather display!

With all this wild weather about recently, I decided to update my e-ink display to include watches and warnings. This is based on continuing development of my display Obligatory WeatherFlow e-ink Display shameless plug, I know.

Rain/storm data is setup on my display to be dynamic. The total rain and duration will appear only for the day, the lightning strike data for 3 hours, and the weather alerts until they expire. Here’s an example with hard-set data in the python:

storm

The NWS API, from their website, is free to use for personal use! All you need to find if your appropriate county code and plug it in on the end of this API call https://api.weather.gov/alerts/active?zone=" From there, I wrote code around it to pick out watches and warnings. I really do not care about Special Weather Statements, I’ll see those on my phone anyway. Here’s the code I used - if any developers see any mistakes, feel free to let me know. I am new to python and this was my first real project! I do have a couple other selections in there for later use commented out:

        #Get Severe weather data from NWS
        response = requests.get("https://api.weather.gov/alerts/active?zone=YOURIDHERE")
        nws = response.json()

        try:
            alert = nws['features'][int(0)]['properties']
            event = alert['event']
            #urgency = alert['urgency']
            #severity = alert['severity']
        except IndexError:
            print('No NWS Alerts')
            alert = None

        if alert != None and (event.endswith('Warning') or event.endswith('Watch')):
            string_event = event

Later on I make it dynamic:

#Severe Weather Mod
try:
     if string_event != None:
        alert_file = 'warning.png'
        alert_image = Image.open(os.path.join(icondir, alert_file))
        template.paste(alert_image, (335, 255))
        draw.text((385, 263), string_event, font=font23, fill=black)
except NameError:
    print('No Severe Weather') 

When the threat clears, it calls off the NWS data, the try except statement does it’s job and the warning triangle/message will fall off. Standard look to follow in reply. Still limited by newbie status.

If anyone has questions, comments, or feedback let me know!

2 Likes

No rain or storm view:

out

1 Like

Now you’re just showing off…
(nice!)

2 Likes

I don’t think I’ve earned my stripes enough to show off yet :rofl: - I just fumbled my way through it

1 Like

If you put a github repo with your full modified/enhanced code up I’d think multiple folks would greatly appreciate it.

I’m certainly hoping to try to take a pass at this one when the rainy season returns here in a month. Have a 2.9" e-ink but not the bigger one. I’m wondering if a battery-powered variant on a picoW might even work.

Crazy thought I had here is to listen for the WF UDP and try to clone part of the fabulous wfpiconsole using realtime data every minute or few…

2 Likes

Ok I’m really hoping I did this right. I get to claim newbie mistakes if so, right?

https://github.com/OG-Anorine/Tempest-7.5-E-Paper-Display

I cleaned out a lot of the unused code and added variables to set the station ID, API token, and how to get the appropriate NWS county code (which not going to lie, is convoluted as all get out)

If anything looks amiss, please let me know and I’ll do my best to address it!

1 Like

My epaper display arrives tomorrow so I’ll give it a try and let you know. Thanks !

2 Likes

yeah - yours doesn’t display anything at all on the 2-color at all even with the edits made. There’s no evidence it’s telling the screen to do anything…but that’s ok because the original you based it on blows up worse

Your code to download forecast and the readings works great (thanks!) but the display never displays.

I did verify that the C and python demos work fine and I definitely have the 7in5_V2 version.

Looking into it. Stay tuned.

It took me a few stabs to get the display to work correctly. Are you running the code as root? ie sudo python weather.py?

The code will require root access to print to the screen correctly. If you are, run it manually - there could be a couple prereqs are are missing and I should be able to help hash that out and get the git updated accordingly.

naaah - no joy running as sudo (which should never be needed anyway). Same results. As I said, all the demos work fine as user ‘pi’ so anything written similarly should too. I’ll poke around.

There was a thread on the original post that I worked from that had the following items (edited from the original listing):

sudo apt update && sudo apt upgrade

sudo apt install git python3 python3-pip pigpio python3-pigpio

sudo pip3 install spidev RPi.GPIO Pillow

Pillow will really be the #1 item here as it is what modifies the template to write to the screen. If that is already installed, what errors do you get when running manually?

I added try/except blocks around lots of things that had no data for me (lightning/rain). Otherwise no errors, just nothing occurring on the screen.

But I got it working by replacing the waveshare libs in your repo with the ones from the waveshare example code. Also made a lot of changes for debugging and making picking 2 vs. 3 color screens much easier, and moved things you need to edit to top of file, and the like with very clear ‘start editing here’ and ‘stop editing here’ comments ala:

#---- start editing here ----
# TODO: these should be in an external file we read in

# TempestWX URL with API Token and Station ID
station = '12345''
token = '12345678-1234-1234-1234-123456789012'

# set this to 1 for two-color, 0 for three-color hardware
TWOCOLOR=1

# api.weather.gov alerts zone URL
#.  (this is NE WA State which has red-flag warnings currently)
API_WEATHER_GOV_ALERTS_URL="https://api.weather.gov/alerts/active?zone=WAC071" 

# set to 1 for debugging messages throughout
DEBUG=1

# set to 1 for debugging screen open/close minimal writes
DEBUG_SCREEN=0

#----  stop editing here ----

And stuff like:

if TWOCOLOR:
    from waveshare_epd import epd7in5_V2
    epd = epd7in5_V2.EPD()
else:
    from waveshare_epd import epd7in5b_V2
    epd = epd7in5b_V2.EPD()

and


    if TWOCOLOR:
        epd.display(epd.getbuffer(h_image))
    else:
        epd.display(epd.getbuffer(h_image), epd.getbuffer(h_red_image)) #Comment/Remove from the comma on if using a 2 color screen

And so on.

Kinda funny seeing weather info for my old station which doesn’t really exist for almost 3 years now. I have a defined WF station id and associated api key but no sensors nor even a hub any more so I have no idea where it’s getting its data from.

Seems to run nicely - I waited through a few 300 sec updates which seem to work. I’ll let it run a few hours to check on stability.

I’ll fork your repo and send you a pull request tomorrow so you can see diffs.

1 Like

That is so awesome! It’s nice to see other’s insight into project like this. Since I’m new to all this and fumbling my way through, the feedback is invaluable to me!!! I’m excited to see the fork! Thanks for running with the project!

Just temporarily stashed in a frame we had available…obviously need to do a more permanent job with matting or else find a frame that fits better.

4 Likes

Awesome! One of the things I have on my list to do is centering of the warnings. The rigidness of the absolute values doesn’t meet my standards for fit/finish. As soon as I have some spare cycles that will be the next update.

Ruh Roh - guess I better check on the icons/images in this thang !!!

Haha!! You got the meme - there’s a windy2.png in there that you can overwrite windy.png to set it to normal :shushing_face:

Just as a FYI for weewx users…

I’m working on a fork of @anorine’s very nice WF-centric project to weewx-ize it and remove all references to anything WeatherFlow. My derived variant uses a weewx skin to generate updated input data and also uses the NWS for forecasts and alerts. Presumably this will let you use this nice dashboard on any station type weewx supports.

If anybody has interest, PM me.

I’ll clean my variant up and announce it and a github link on the weewx-user google group when it’s all documented and tested enough to be ready for a semi-production quality release…

2 Likes

For the weewx users out there - my fork is good enough for others to try if you’re so inclined. Github repo is (here) if you want to go pure weewx for your ePaper display.

Differences from @anorine’s upstream:

  • uses your local weewx for data
  • uses NWS for alerts and forecasts
  • no api keys or accounts anywhere needed
  • has a config file rather than needing to touch the python script
  • lots of refactoring and commentary in the code
  • added precise measurements for cutting a mat that fits vs. a 5x7 frame
  • a continually evolving to-do file as I think of stuff

Lastly - I do have some example WeatherFlow stuff under the ‘doc’ tree mainly for me. Still thinking of (re)adding the WF stuff from upstream into my refactored variant but no guarantees there.

@anorine’s upstream app already works kinda great as is for WF users :slight_smile:

3 Likes

Thanks @vinceskahan!! I really appreciate your feedback!