[UPDATED] - Weather Switch - Turn on a switch in response to weather

Guys

Here is a little app that takes data from a WU driver and will control a switch based upon thresholds set
I wrote this because I had a need to close some windows if it gets too windy
e.g if WU wind report is above 5mph then turn off the window relay.

You can perform action based upon:

      "Alert"
      "Chance of Rain",
      "Dewpoint",
      "Forecast Conditions",
      "Forecast High",
      "Forecast Low",
      "Humidity ",
      "Illuminance",
      "Rain Rate",
      "Rain in Last Hour",
      "Rain Today",
      "Rain Tomorrow",
      "Rain The Day After Tomorrow",
      "Pressure",
      "Solar Radiation",
      "Sunrise",
      "Sunset",
      "Temperature",
      "Max Temperature Today",
      "Min Temperature Today",
      "Temperature Feels Like",
      "Max Inside Temperature Today",
      "Min Inside Temperature Today",
      "UV Radiation",
      "UV Harm Index",
      "Wind Direction",
      "Wind Gust",
      "Wind Speed"

Either turn a switch on or off.

I have tested as much as I can as my local WU station does not give me all the data
But if you try it and find any bugs please let me know.

It's a parent/child app so install them both and 'Load' the parent then save it before reopening the parent to create multiple children

Parent: V1.1.0
Child: *V2.6.0

You can find the apps here:
https://github.com/CobraVmax/Hubitat/tree/master/Apps/Weather%20Switch

And my tweaked version of the WU driver written by @mattw here:
https://github.com/CobraVmax/Hubitat/tree/master/Drivers/Weather

Cautionary Note:
If you need to edit any child app then please open the parent then edit the child from there
If you just open the child sometimes it errors when you save or doesn't return correctly to the apps page

Please note:
Actions will not take place unless something changes - i.e. a reading must change before it's registered with the app
e.g.
If you set the app to switch when the wind goes above 5mph and currently it is showing 6mph then the switch will not change. As soon as the next reading comes in (providing it has changed and is above the threshold) then it will change the switch


Updated 26/09/2018

Added a new trigger 'Alert' so you can now switch on/off by matching a word or phrase


Updated 30/08/2018
It's been a while since an update
Added additional triggers:
'Temperature',
'Max Temperature Today',
'Min Temperature Today',
'Max Inside Temp Today',
'Min Inside Temp Today',
'Chance of Rain'",

Andy

5 Likes

@Cobra
Hi Andy.
Thanks for all your work on this.
Unfortunately its throwing an error for me.
Here is how it is defined in the app.


Weather Underground is polling every 5 minutes and is getting the illuminance level.

The Switch Defined is not turning on and the logs for the switch are showing this.
image
Hope this all makes sense. Let me know if you need anything else.
Thanks again.

Hahah!
Illuminance was one of the things I couldn’t test as I couldn’t find one that reported near me

I’ll have a look now

Andy

Bob
there was a typo that I had missed
Fixed code uploaded to GitHub or if you wish you can just edit the typo out…

Look at line 175

                       actionNow(Illuminance, vt1)

it should be:

             	        actionNow(Illuminance, evt1) 

Notice the missing ‘e’ from the previous one

Andy

1 Like

Hi Andy.
Amended the code as directed, and hey presto, the switch turned on.
Brilliant. :smile:
Now for some testing.

2 Likes

Great!
Glad we got it working :slight_smile:
Please let me know if you find anything else

Andy

Just an update for you.
I provided a few Virtual Switches and tied them in to a few child weather apps.
All of them turned off as the lux level fell.
Great job Andy.

1 Like

Bob, That’s great to hear.
A few additions in the pipeline which I find useful and maybe you will too…

Presence - Only switch on/off if you are at home (or not)
Time - only switch between certain times
Days - Only work on specified days (or all)

I’m also working on the driver to supply a bit more info (and be able to switch with that info)
Unfortunately when I’m done you will only be able to use my modified driver rather that the original written by @mattw but I’m only adding rather than taking away.

I have a PWS arriving tomorrow which connects to WU so I’m hoping this will give me everything to test and be a bit more accurate (as it will be in my garden)

Andy

1 Like

A few updates…

App
Added ‘Wind Gust’ as a trigger
Added the ability to apply restrictions to prevent/allow the app to switch

Presence
Time Period
Days

Driver
Cleaned up capitalisation/naming
Added ‘Wind Gust’

Added ability to select the following units

Pressure (mb or in)
Distance/Speed (mi or km)
Precipitation (in or mm)

Added the ability to disable the majority of the logging

I have also added the ability to receive extreme weather alerts (which I was unable to test as I can’t find any!)

I have updated Github with the new files and the first post with the current version numbers

Andy

I'm trying to turn a switch on when the high is above 80, but the switch isn't flipping to on. Am I doing something wrong?

Yep!
trusting an idiot to code! :slight_smile:

Ok found an issue where data was sent from the driver as a string not an integer.. fixed now so it should work ok.

This is why it's called a beta :slight_smile:

Thanks for your patience
You need to update the child app and the driver code

I have updated Github with the new files and the first post with the current version numbers

Andy

@bobbles
@homeauto2112

Thanks very much guys for testing this.
@homeauto2112 if you retest the Forcast High I’d be grateful

So… what to do now (if it’s all working which I think it is now)?

I’m thinking about adding extra ‘actions’
For example:

  • play an mp3 (or a message/forecast when we get TTS)
  • send an SMS or ‘PushOver’ message

Do you think these might be useful?
Any other ideas?

Andy

Great app! Thanks.

This may be a bridge too far or simply outside your intended scope, but here's my problem:

For irrigation, I want to know the precipitation for [1] two days ago, [2] yesterday, [3] forecast for today and [4] forecast for tomorrow. Based upon that data, make a decision. Apparently, the free WU API doesn't give the historical data. I was thinking about using a webCoRE piston to collect, on a daily basis, each day's actual precipitation and sum it on a rolling basis. On any given day, this would give me (t-2)+(t-1)+t; then I just need a best-available forecast to add to the sum.

Could Weather Switch do this? I'd need to be able to give the app a threshold for go/nogo; or deliver the sum to a rule or piston for decision making.

1 Like

@CAL.hub
This is REALLY outside the scope of this app … but…

As you say WU doesn’t give you historical data for free

Using ‘Precip_Today’ could probably get the precipitation for two days by saving it into a variable that is reset to 0 every two days
You could use 2x an amended 'Forecast_Conditions ’ to look for the keyword ‘rain’ which would tell you about today and tomorrow

Then you just need to work out logic for a go/nogo - shouldn’t be too hard

e.g.
if it has rained for the last two days and/or it will rain tomorrow or the next day - nogo
OR…
do something with number weighting…
e.g. 10 points for each day it rains or is expected… anything over 30-40 - nogo

The action is easy then…
if go - turn on a virtual switch
if nogo turn it off

I think this would need a whole new app…

Andy

1 Like

@CAL.hub
Other things to think about…

How much rain yesterday is enough to score the 10 points? - 1", 2" more/less?
This would need to be configurable
and of course you wouldn’t know how much rain is coming tomorrow or the next day… that would just have to be yes/no

Interesting problem though…
Living in the UK we don’t ever have to think about irrigation here! :slight_smile:
Do a lot of people use irrigation in the US?

Andy

I’m in Florida and irrigation is prevalent. We get regular thunderstorms most every afternoon in the summer, but if they don’t come, then the scorching heat can really set a lawn back. And, of course, there are dry months where it’s still fairly warm.

It’s all good!! I just loaded the new WU driver and the Child app. Testing now.

It still appears to not work. I set my Forecast Hi virtual switch to off. Then I deleted both the Forecast High and Forecast Low apps. I then created a new Forecast High child app:

Here's the live logging after I created the app:

However the virtual switch remains off. * I was able to get the virtual switch to change to on once, when I turned the "trigger active*" switch was turned off. However I'm unable to replicate that no matter how I set the threshold relative to WU or how I change the "trigger active" switch.

On another note, when I go back into the child app, click the "next" button and then click the "done" button, it takes me back to the first page of the child app and not back to the main Apps menu.

Thank you for putting this together. I need the forecast highs and lows to drive some of my apps so this is really appreciated!!

and, just to add to your madness, I think I found two more things. When I load your custom WU driver, I don't have the option of selecting WU in SmartTiles, and when I select "poll" I receive the following error:

Ok…
I’ll answer the second bit first
When editing the apps I’ve found that if you edit them directly it can sometimes cause the problem
If you open the parent then edit the child from there it should work ok.

The WU driver I use has had some of the commands stripped out so I don’t get double entries under ‘Current States’
To use SmartTiles it is probably looking for the capabilities I stripped out.
I’ll create a second driver which you can use on a second virtual to use with smarttiles (it will just show the double entries)
I’ll let you know when this is done.

OK… the main problem
1st - Can you please let me know which versions of everything you are using?
Forecast High & low were working for me when I tested them

Andy