Haiku past day(s) precipitation?

js19707

Active Member
I like the idea of the RainAdvisory flag used by HaikuHelper and i've updated my HAI's sprinkler automation rules to consult that weather forecast information.

i had originally planned to install a rain sensor which would also interrupt sprinkler schedules for a few days following a rain. but i never got around to running the wire to install the rain sensor. As a stop gap measure, I added logic to skip sprinkler watering based upon a 'Rain Delay' button. i currently (manually) press the Rain Delay button when there is rain but it's obviously a pretty kludgey arrangement. i was also pressing the Rain Delay button when rain was imminent but HH's setting of the RainAdvisory flag eliminates that need.

all that having been said, it would be great if HH had the ability to report the past day's (or potentially past 2-3 days') precipitation. i see that information on weather.com's current weather reporting (past 24 hours precipitation reported in inches of rain and snow).

how hard would it be to incorporate the ability to set a flag with a value representing the # of inches of precipitation in the past day? if HH did that, i might not ever have to bother with the rain sensor and it might be useful for folks who for one reason or another can't or won't install one.
 
Yes, it can be done. Great suggestion. I will see what API we can use. By the way, I am sure it can already be done via scripting ;-)
 
For the US you can get the precipitation gage value for any range of days via APIs here (you can get your site value via the same web site):

http://waterdata.usg...ieval_info#Help

Example for 1 day for a site:

http://waterservices...0800&period=P1D


Example for 7 day for a site:

http://waterservices...0800&period=P7D

You can easily process the JSON value in javascript and set any flag you like to it :)

Update: Not sure if these include the precipitation data or not, as I am not that familiar with the service itself. But either way the example below gives you a starting point. You probably need to find an API you can use from your location that provides XML or JSON output that you can use. The code below will work with some adjustments. As you can see its quite easy to retrieve data using HaikuHelper. However, locating the data seems to be the tricky part.

Update 2: It looks like you can get the information using the Weather Underground APIs.
 
Here's an example:

Code:
var apiReq;
 
syncPrecipitation();
setTimeout('syncPrecipitation', 6*60*60*1000); // Every 6 hours
 
function syncPrecipitation() {
	apiReq = new XMLHttpRequest();
	apiReq.open('GET', 'http://waterservices.usgs.gov/nwis/dv?format=json&sites=06090800&period=P1D');
	apiReq.onload = jsonLoaded;
	apiReq.send();
}
 
function jsonLoaded() {
	if(!controller.isConnected) return;
 
	var response = JSON.parse(apiReq.responseText);
	
	helper.alert('reading = ' + response.value.timeSeries[1].values[0].value[0].value)
 
	// You will have to convert the value to something you can store in a flag or a few flags
	// Or you can just use HaikuHelper to set a flag telling the controller whether to run the
	// sprinklers or not based on logic you can add to this sample script
 
	// Set flag along the lines of:
	// controller.unitWithName('MyPrecipFlag').setValue(value);
}
 
Back
Top