[RELEASE] Precipitation and Weather Monitor for National Weather Service Data (USA Only)

Could others using this driver take a look at their State Variables and tell me if the number of those retained exceeds the driver setting per this example.

On mine these records keep building up. I've looked at the code and the logs and it attempts to remove these state variables but they don't actually get removed on my system.

Other having the same issue?

Doing a ClearAll works but the removeExpired does not.

I just installed the app/driver via HPM. It looked like everything installed correctly and I was able to create the virtual device but I can't get it to pull data. I'm using ICAO code KGME. I checked the log and I keep getting the following error on refresh:

groovyx.net.http.HttpResponseException: status code: 404, reason phrase: Not Found on line 338 (method refresh)

refresh(): A data refresh has been initiated.

Has anyone had this issue? Or know what I'm doing wrong?

404 means "Not found" -- that the URL it's trying to fetch is not finding a page. It probably means you entered the Airport Code incorrectly. "K" + your desired Airport.

Yep, no airport with code KGME

Use the link to the Wikipedia page on the OP for a list of valid codes.

1 Like

That was it. I was supposed to use KMGE. Tpyed it correctly and it is working now. Thanks for the help.

Gary - I have an enhancement request in the event you are making updates. Is it possible to add an additional variable in the preferences for the time window to calculate the watering threshold (instead of just yesterday)?

FYI there is an update to version 1.0.2 to correct a bug where the old records were not getting purged and kept piling up in state. If you don't look at the driver you may not have noticed but this update should keep the number of retained records at the number specified in Data Retention Period in Hours. * within settings.

Does not change functionality, just improves appearance.

I've been meaning to ask, is there a reason the minimum is 48 hours? I don't care about that much history and I'm trying to preserve memory...

Sorry, not really doing feature adds at the moment, just bug fixes. My development energies are going into Tile Builder at the moment. There will be a new module released in the next few days which may be a good way of displaying the NWS data.

Yes, it calculates total rainfall for today and yesterday by adding up the rainfall amounts for each hour. If less than 48 hours of data were kept then rainfall totals for the prior day could be inaccurate.

Ah. Well, to be honest I only use this driver to give me the current weather observation for the closes NWS station. Don't use the other info so that's why. I wouldn't mind a fork of it if I was smart enough to do it.

It's not a big program (700 lines) so it would be pretty easy to bypass all of the other stuff. Never too late to start programming and this would be mostly deleting what is already there.

I'd probably just add a boolean option like "Collect Rainfall Data" and use an if statement to bypass the necessary sections. Then change the number of hours to retain to something like 2.

I might do it. Truth is I programmed full-time from 1980 until 2000 or so when I moved into management and lost touch. Fortran, Assembly, C, C++, Java etc. But, rusty doesn't begin to describe it. But, I think it's a worthy project. Thanks for the inspiration Gary.

Things have changed a lot since then but logic is still logic. I think you'll really enjoy it. If you want to make it an enhancement anyone can use, then I'd be happy to post it out so it's available to everyone through HPM.

One thing I'd absolutely use is chat gpt. It is a great resource. I asked to explain a piece of code from the driver and you can see it's response. You can also ask it to write code but it's not always correct.

I'll give you a hand if you get stuck.

explain this function: def purgeExpiredRecords(retainList){
log ("purgeExpiredRecords", "Purging expired records!", 1)
int maxRecords = 31 * 24
int i = 0
while ( i < maxRecords ){
variable = "R-${i}"
def value = state."${variable}"
if (value != null ){
//log.info ("State Variable ${variable} exists and value is: ${value} " )
//So there is state variable by this name. Let's see if it is in the retainList
if ( retainList.toString().contains(variable) == true ){
log ("purgeExpiredRecords", "Preserved record: " + variable , 1)
}
else {
state.remove(variable)
log ("purgeExpiredRecords", "Purged record: " + variable , 1)
}
}
//A small pause to stop the driver from hogging all the resources as this is an intensive loop otherwise.
pauseExecution(10)
i++
}
}

ChatGPT
The provided function, purgeExpiredRecords, is designed to remove expired records from a state based on a given retainList. Here is a breakdown of how the function works:

It begins by logging a message indicating that the purging of expired records is starting. The log message is printed with a severity level of 1.

The variable maxRecords is set to the value of 31 multiplied by 24, which equals 744. This represents the maximum number of records to be checked.

A loop is initiated with the variable i starting at 0. The loop continues as long as i is less than maxRecords.

Inside the loop, a new variable named variable is assigned a string value in the format "R-${i}", where ${i} represents the current value of i.

The function attempts to retrieve the value of the state variable named ${variable}. The state object is assumed to be a container for storing variables.

If the retrieved value is not null, it means that a state variable with the name ${variable} exists.

The function checks if the retainList contains the variable by converting retainList to a string and using the contains method. If the retainList does contain the variable, a log message is printed indicating that the record is preserved. Otherwise, the state variable ${variable} is removed, and a log message is printed indicating that the record has been purged.

After processing each record, the function pauses execution for 10 units of time. This pause helps prevent excessive resource usage during the intensive loop.

The variable i is incremented by 1, and the loop continues until i reaches maxRecords.

In summary, the purgeExpiredRecords function iterates over a range of record names and checks if each record exists in the retainList. If a record is not in the retainList, it is removed from the state.

1 Like

Great driver! Just what I was looking for. Quick question - I added the device to a dashboard and specified “weather” as the template.

It shows Humidity, Temp, and Wind Direction labels but no data. The data are shown on the device itself, as well as the device list (I selected temperature as the display value).

Is there something else I need to do, or will the data populate on the dashboard after a while?

That template is probably expecting certain attribute names/data types. You can put on individual attributes but that takes up extra space. This scenario is why I created Tile Builder which lets you add a variety of attributes within a single attribute. For example:
image

You can use the module called Multi Attribute Monitor and you can read about it here.

I finally got around to utilizing my own driver to control my sprinklers.

I found this to perform the on\off scheduling.

and I've added some capabilities to the upcoming version of Tile Builder Grid to be able to present sprinkler data on the dashboard without having a smart sprinkler system.

image

Should be able to save some money on water this summer and the whole thing only cost me $50 for the 8 port Tasmota relay and an enclosure.

1 Like

I have switched from the OWM driver to this one. I didn't want to switch to the new API and give them CC info. This driver provides everything I need, and I think will be more accurate for my local weather as a local regional airport is only about 10 miles from my house.

So thanks for this.

1 Like

IMPORTANT
Last night the NWS changed the URL for retrieving this data along with some minor formatting. I have a fix and some other small changes I was already working on running on my system at home. I just need to let it run for a few days to make sure I'm happy with it and then I will push it out for all to use.

In the meantime this error will generate an error when trying to retrieve the most up to date information and your numbers will not be correct.

1 Like

I updated the URL in the driver. Seems like the basic data is good now. This should hold me until you get everything worked out.

Data is actually off a bit in terms of the interval but good enough for now.