Script to update WeeWx with WF API data

Since we know that WeatherFlow processes Rain Check after the day’s over, and since I noticed in testing that lightning strike data doesn’t seem to always be correct coming from UDP, I wrote this Python script to retrieve a days worth of data from the WeatherFlow API as a CSV file and update the WeeWx database with the API data. The API data has one row in the file per minute (more or less - sometimes there’s minutes missing), so the script aggregates data as appropriate for the individual minute rows to update the one 5-min row in WeeWx. (Ex. there’s 0.01mm of rain each minute from 2:31 to 2:35 - it will sum it to 0.05mm and update the one WeeWx row for 2:35 with that value. Note some other fields are min, max, or average.)

The fields it updates are:
1. lightning_strike_count = Total number of lightning strikes during the 5 minute time period
2. lightning_distance = Average Lightning Distance during the 5 minute time period
3. rain = Amount of rain in millimeters during the 5 minute time period
4. rainrate = Amount of rain if received over an hour period (rain * 12)
5. rainBatteryStatus = Precipitation Type (0=None; 1=Rain; 2=Hail)
6. signal7 = Closest (Min) Lightning Distance during the 5 minute time period
7. signal8 = Furthest (Max) Lightning Distance during the 5 minute time period

A few notes:
1. I’ve only tested this with my own Tempest. You may get different results than I do. So, make sure you test it on a test copy of your database. Never test in production!!!
2. You’ll need to know your Tempest Device ID. MAKE SURE YOU PUT YOUR DEVICE ID IN DOUBLE QUOTES ON ROW 35. If you don’t have a Tempest, you’ll need to adjust the column values for your non-Tempest csv file layout.
3. I store the lightning min/max distance because I thought some day I’d try to recreate a graph like in the Tempest Smart Weather app. Haven’t yet though, but didn’t want to lose the data since it’s in the CSV file.
4. I used some WeeWx fields that I personally wasn’t using. You may choose to use different ones.
5. There’s no routine to delete the daily CSV files from the folder, so they’ll accumulate over time. You’ll want to manually clean these out over time. I move them off the pi as backup somewhere else every so often.
6. I set this up in cron to run every day around 6am. Remember, you’ll need to also have WeeWx rebuild your daily summaries due to the new data after each time. See this link with instructions on how to force it to rebuild just one day of dailies.

Lastly, I’m sure anyone more familiar with Python than I am could find all kinds of better ways to code what I’m doing. I’ve literally never used Python before (my first Python script ever! Yay!), and just threw this together yesterday and today and learned Python as I went. So be gentle with me!


This would be a great starting point for the frequently requested “how can I download all my historical data” feature so many people ask for. Keep going !!!

1 Like