Help newbie water his garden

I currently have one device. A Zwave Dome valve and is installed and working manually through the iOS app.

I have 8 timers for garden and lawn and this one valve will be shut off for the day if things are wet enough already or high probability of rain.

I’d prefer not add sensors. And use past precipitation and forcast deciding if valve should be on for the day.

I bought the smartthings because I thought “it” was smart. Apparently I have to make it smart by coding it.


Is there a plug in I can use or buy that does anything close?

I know how to code. But I bought the dumb easy box so I drag and drop and answer some questions. But that doesn’t seem to be the case.

I did start an app from “when it rains” template and changed it to use a valve instead of window sensor.

The code for “if it rains” is nearly useless. It just looks for key works in current forecast.

But how do I open or close the valve?
And what is a better source for weather data (including past precipitation ideally).

Try Spruce, by Plaid systems. It has sensors, but you don’t have to use them. Without them, the provided SmartApp is still pretty smart, not only adjusting for rainfall (as measured by a nearby Weather Underground station), but also based on outside temperature forecasts plus length of the day (seasonal adjustments).

They have two versions - one configured and managed entirely within a SmartApp, and another managed by a WebApp…

1 Like

The only way to make it easy to to add sensors or use and Weather Underground IFTTT.

I think I managed to write the code to do it.

It basically looks at past days precipitation, if exceeds threshold, closes valve for the current day.

def scheduleCheck()
        def response = getWeatherFeature("yesterday", zipcode)
        if (response)
            def daily = response?.history?.dailysummary?.first()
            if (daily)
                def rainInches = daily?.precipi
                if (rainInches && rainInches.isFloat())
                    if (rainInches.toFloat() > threshold)
                        sendMessage("Valve: Closed Rain: $rainInches > $threshold")
                        sendMessage("Valve: Opened Rain: $rainInches < $threshold")
                    sendMessage("Valve: Opened Error: No Precip Value")
                sendMessage("Valve: Opened Error: No Summary")
            sendMessage("Valve: Opened Error: No Yesterday")
	catch (e)
        sendMessage("Valve: Opened Error: Exception $e")

Well it “was” working.

Last night, after midnight or so, the Precipitation returned a “T” (in the previous day summary).
Going to that’s exactly what was there.
That was no fault of smartthings. But the hourly data looked good, so I went to add backup code in case the total was bogus I’d tally up the days observations myself.
Now today, I get nothing on “yesterday”, “forecast” Still works. But no error.
I’ve seen other folks have problems with “yesterday” on SmartThings.

So to debug further I signed up for a free account on Weather Underground.
And the query for “yesterday” looks fine.
So all I can think of is SmartThings has used up it’s quota for “history” related data.

Ok, I’ll use my own weather underground user “key” and request the URL directly with httpGet.
Since it’s a json file and not a json stream it won’t work on Smartthings (that’s a fairly serious limitation).
Smartthings can’t deal with files on the hub (images are special case that they allow be stored on their server).
It could just read the file into memory just like getWeatherFeature() has to.

So for now I ordered a HomeSeer S2 system. There is already a nice plugin for WeatherUnderGround for the exact same purpose I wanted (Yesterday’s Rain). I also feel a little better running local.

I’ve seen some flaky behavior already due to the round trip lag. Like controlling volume on Bose SoundTouch works half the time. Not that, that is critical I’m worried about other things being laggy or just plain lost.

If anyone knows if I’m way off on my assessment, please explain. Thanks. I won’t return SmartThings unless I see HomeSeer is working better. I would have ordered a HomeSeer in the first place if I knew I had to code anything this basic.

1 Like

Having contributed heavily to the Spruce integration, I have a couple of suggestions:

  1. Don’t just look back - look forward as well. You don’t want to water if it is going to pour later today or tomorrow
  2. Using the history API will eventually bite you - SmartThings doesn’t own unlimited use of that API, so at some point you will poll it and get back only an error.
  3. Because of #2, I collect the days total rainfall at just before midnight each day, and then create/maintain my own history data.
  4. A value of “T” means “Trace” which is less than 1/10th of an inch. There are other values that WunderGround will return. Simplest is to use numbers if supplied, and to assume zero of the value isn’t a number.
  5. Using the above, you shouldn’t need to use your own user key.
  6. See also jsonSlurper…
1 Like

Thanks for the reply.

re: 1) I had planned to look at “current” and forecast as well. But prior rain was the highest priority me. Does forecast include predicted inches in next 24 hrs?

re: 2) I’ve noticed history is unreliable (been logging it), I wish SmartThings would let you use your own API Key which might resolve that. Couple bad SmartApps might be abusing it for all of SmartThings.

re: 3) I was just coding that now, and looks like it might be fairly easy.

re: 4) I figured out the “T” thing just recently. Saw it in a footnote finally on Underground. Saw it in other peoples code too.

re: 5) I hope so.

re: 6) Will do.

I’ve been playing with HomeSeer and it’s fairly dumb on the Valve state, Support horrible (took 3 days just to get my forum account active). Custom coding, although more powerful, way more tedious and more work for something simple.

Thanks for your response. Really appreciate it.

I think I have it working storing precip for current day in a state variable (at 11:50PM).

So currently it will use previous day precip + current day precip (up until watering time) and if that exceeds threshold it closes the valve. After watering timers fire it has option to open valve again (for a failure state). If something goes wrong I rather fail with valve open.

If all goes well I’ll add forecast precip.

Yes, forecasts include inches and probability. I simply multiply the two…not correct, but effective enough. I made the “skip if is supposed to rain” amount configurable.

Forget about using history - it would cost SmartThings a fortune to get it reliably for their user community. You will almost always get an error, unless you can figure out when the ST API usage counter resets (I don’t think it is 12:01am EST/EDT).

For a couple hundred bucks, you can get Spruce or Rachid or (the other one) controller, and leave it all to their (respective) SmartApps. Spruce doesn’t require sensors for the logic to work (I don’t work for Spruce, by the way…I selected them for my use cases precisely because they let me help design the code - I get exactly what I want, which seems to work for most of their users as well…)

Enjoy the world of IoT!


Thanks, mswlogo for providing the above code. I plan to modify it to turn a relay switch off/on instead of a valve. I have the relay (GoControl FS20Z-1) either opening or closing the connection to a rain sensor on my non-smart irrigation control. I’m new to ST but I’m sure I can make the necessary changes, but I do have a question.

I looked at the APIs on Wunderground but it’s unclear to me what ‘current_observation’ refers to in this code line from getCurrentPrecip() - I don’t see it in the WU documentation:

def rainInches = response?.current_observation?.precip_today_in


Goto Weather UnderGround API and Click “Conditions” in the list on the left.

That will bring you here:

Now in the lower right corner click “Show Response”.

That is a sample of what is returned for “conditions”.

The “feature” from getWeatherFeature() is a JSON file with a large hierarchy of data.
The hierarchy is automatically parsed by getWeatherFeature().

There is a field in the JSON file called current_observation and it automatically becomes an object in the response.

I figured this out by starting out with SmartThings code template “When it’s going to Rain”.

Sometimes they are array’s and you can get the first, last or iterate through them.

You can sign up for your own Key for free at weather underground and use the “Apigee Console” and try queries “live” to see what will be returned.

If you just goto with your ZIP code, everything you can see and get to is available.
However anything “historical” is not reliable with SmartThings getWeatherFeature() which is why I had to record past rain myself, which turned out to be very easy.

One other trick is to use “pws:STATION-ID” for the zip code to get to a specific personal weather station near your house. There is a personal weather station near me that is way more accurate (for current rain fall for the day) than the government one at the airport 20 miles away.

I’ll give it a try - I can pull data from my own wunderground weather station. ::grinning:

Thanks again for your help.