Complex piston for charging Tesla PowerWall based on forecasted weather


#1

Hey guys,

I’ve got an idea for a piston I think would be handy for many however have no idea where to start.
Firstly I can call variable $weather.forecast.forecast.txt_forecast.forecastday.icon which provides me the following data… [clear, chancerain, clear, nt_clear, clear, nt_clear, partlycloudy, nt_clear]

The output returns 36 entries rather than the 8 in the example above, the first result is for the current hour saying its clear outside, the second value is saying that there will be rain from the next hour (i.e. 5pm-6pm) etc etc.

I’m wanting to somehow pull each of these values into variables, so I have something like
@current_hour - clear
@next_hour - chancerain
@three_hour - thunderstorm
etc etc.

I then need to write some complex if statements, that say if its currently clear and the next hour is clear, but anything between three_hour and six_hour then do this action; which my action will be to charge the power wall so if we lose power I still have battery backup.

I’m sure someone out there has written something that will be more user friendly than my idea, plus I would not know where to start with such a piston so not to get it all confused.

Can anyone help?


#2

Ahh, well, this isn’t exactly what you asked for, but if we were thinking outside the box…

I might consider converting the ‘words’ listed above into ‘numbers’… Kind of a sliding scale, so to speak. Use a notepad, and put all the possible forecast phrases ‘in order’ from "Clear Blue Skies" to "Life Threatening Hurricanes". I would be tempted to group them into 10 or less ‘numerical’ categories… (grouping hurricanes, twisters, cyclones and earthquakes etc. all as number 9, all the way down to ‘clear’ as number 0)

The beauty of going this method is that you can now do math queries (such as greater/less than etc).
For instance:

If hour00 is less than or equal to 1
AND
If hour01 is less than or equal to 1
Then DO Blah blah blah

(in this example, that could cover Clear & Mostly Sunny)

I have done something similar in one of my favorite pistons, but I think I’m going to convert them all to single digits. (0-9)

(contains(wuCurrent,'Snow') ? '90' : 
(contains(wuCurrent,'Hail') ? '80' : 
(contains(wuCurrent,'Thunderstorm') ? '70' : 
(contains(wuCurrent,'Rain') ? '60' : 
(contains(wuCurrent,'Drizzle') ? '50' : 
(contains(wuCurrent,'Fog') ? '35' : 
(contains(wuCurrent,'Overcast') ? '15' : 
(contains(wuCurrent,'Mostly Cloudy') ? '10' : 
(contains(wuCurrent,'Cloud') ? '5' : '0')))))))))

This also let’s you do some fancy coding down the road:

Set variable combinedHours = hour00''hour01''hour02''hour03''hour04''hour05
IF combinedHours is greater than 222444
Then DO Blah blah blah

(This little trick basically checks 6 variables on a sliding scale in 2 lines of code)


#3

I like your thinking… how did you get the original hour00 and hour01 into variables?
Also I won’t be handling things outside of sun hours, so how could i tell the current time and only deal with them between X and Y; actually i think i just answered my second answer


#4

Well, keep in mind that the command:
$weather.forecast.forecast.txt_forecast.forecastday.icon
actually pulls the forecast for today, tonight, tomorrow day, tomorrow night etc

You likely want the command:
$weather.hourly.hourly_forecast.icon
for hourly queries.

I have been unable to find a full list of icon outputs, but here is a partial list to get you going:

clear / nt_clear
partlycloudy / nt_partlycloudy
mostlycloudy
cloudy
rain / nt_rain
chancetstorms / nt_chancetstorms
nt_tstorms

Without a full list of icons, it is tough to make the finalized code, but here is a good starting point for the next 8 hours:

Which yields these variables when run here:

That code is based on this incomplete list:

1 = clear / nt_clear
2 = partlycloudy / nt_partlycloudy
3 = mostlycloudy
4 = cloudy
5 = rain / nt_rain
6 = chancetstorms / nt_chancetstorms
7 = nt_tstorms


#5

An easy alternative (which may work for you) is to pull in the “Probability of Precipitation” instead of the icons. It makes the coding much simpler.

$weather.hourly.hourly_forecast.pop

That command returns the next 36 hours of rain chance. Each data point is a number from 0-100 for the percentage of rain. Such as:

[33, 15, 15, 15, 32, 15, 13, 16, 15, 23, 32, 36, 58, 59, 58, 40, 31, 47, 54, 41, 15, 19, 18, 18, 24, 42, 50, 45, 46, 38, 39, 39, 36, 24, 22, 24]

And of course,
$weather.hourly.hourly_forecast.pop[0] is this hour
$weather.hourly.hourly_forecast.pop[1] is the next hour etc…


#6

Looking at WUnderground page https://www.wunderground.com/hourly/nz/tauranga/IMOUNTMA3?cm_ven=localwx_hour it appears there is a cloud cover column, that would actually be best used but it appears this isn’t available in the webcore API?


#7

The Accu-Weather plugin for webCoRE works brilliantly in that department. It acts like a device, and returns the current cloud coverage in a number from 0-100. (I have not tested it for forecasts though, since I use WUnderground for predictions)

You can try this by loading the ST app on your phone, and going to:
Market Place > Smart Apps > Climate Control > AccuWeather Connect


#8

Thanks for the tip may try it, however like your example with rain percentage for next 36 hours, would be good to use their cloud percentage too; any idea how i get in contact with who ever manages that portion to see if it can be added?


#9

AccuWeather forecasts leave much to be desired… but you could easily query the 36 hour rain forecast via WUnderground, and current cloud cover via AccuWeather all in the same piston.

I have never seen a cloud cover forecast in API format anywhere, but it would be useful.


#10

I just imported your piston and I think it will do exactly what i want; based on a calculation of the results.
For instance its a fully clear day here and each hr integer is 1 at the moment, so I can say if the sum = 8 its going to be a clear day, so just self consume battery and let it charge from solar, however if the value is between 15-20 then charge the battery at hour 4 etc etc… will need to give it some thought and have a play.

How is the piston values updated, do you have to call the piston at a certain time to get the values, or does it just update every hour?

I need to do my forecasting at 11am to decide what im going to do for the next 6 hours hence why i ask.


#11

If you imported my piston (kxrh), then yes, I did not put a trigger in there. It will not run until something runs it. Let me know if you need a hand with that.


#12

So i found the cloud cover, its not documented on their wiki, but you use ‘sky’ i.e. $weather.hourly.hourly_forecast.sky


#13

So i’ve made what looks to be quite a complex piston

One thing I need to somehow add is checking the ‘spot price’ variable every 5 minutes within the hour period.
For instance you will see the times 11am, 12, 13, 14, 15 the else statement checks to make sure the spot price is less than 80. Rather than just checking on the hour, I need it to check every 5 minutes; if the spot price is higher than 80 then execute the consume piston else continue with its actions… Am i better off adding another statement between 11am-4pm that has a timer run every 5 minutes to check this and action it?


#14

Just in addition to the above, my end game is the following…
7am - 11am is peak time power pricing, so consume from battery
11am - 5pm is off-peak power pricing, expect solar to charge the battery but if cloudy i need to charge from the grid to ensure my battery is near 100% before 5pm.
5pm - 11pm is peak time power pricing again so consume battery
11pm - 7am charge from the grid so the battery is full for the 7am run again.

Each time the system is running in “Charge” (from grid) make sure the spot price is less than 80 (meaning my power price is less than $0.18c, if i don’t add this check, pricing could be at $0.50c or even greater which would defeat the whole point of this exercise :stuck_out_tongue:

Many thanks in advance


#15

Thank you so much for this! This is awesome!

@icepicknz, can you share the link where you found that code? I would love to dig thru it to see if there are any other undocumented snippets.


#16

So from your breakdown, it looks like the only time there will be multiple possibilities, is between 11am - 5pm. All other hours of the day you only want one outcome. If this is correct, then please be aware with your current setup, you are only getting data from WUnderground once a day at 10:45am each morning. Since @weather.....sky is a forecast, it changes quite a bit throughout the day.

I would be tempted to move the 7am, 5pm and 11pm into a separate piston, and let this one focus on the complexities from 11am - 4:55pm. Then you could do something like this:

Every 5 minutes
Do
    IF $hour24 is between 11 and 16
    Then Execute piston "webCoRE \ Forecasted Weather
    End IF
End Every

(Yes, that code points to, and executes itself)

The rest of the piston should be outside of the top “Every” block, and have zero triggers. Such as:

With location
Do
    Set variable {hr0} = @weather.hourly.hourly_forecast.sky[0]
    Set variable {localTesla} = (($hour24 - 10) * 5) + 45
End With

IF 
    variable hr0 is greater than 40
    and
    variable {@tesla_PW_SOE} is less than {localTesla}
    and
    variable {@spot_price} is less than 80
Then
    Execute piston "webCoRE \ Tesla Powerwall Charge
End IF

Those 6 lines of code should do everything you want.

My fancy code on line two:
(($hour24 - 10) * 5) + 45
basically makes your threshold automatically change throughout the day.
11am = 50
12pm = 55
1pm = 60
2pm = 65
3pm = 70
4pm = 75


#17

I went to http://api.wunderground.com/api/100ad2bd673b106a/hourly/q/NZ/Tauranga.json and noticed the icon and other variables described in the wiki, so just tried sky :stuck_out_tongue:


#18

$weather.hourly.hourly_forecast.sky

I have tried this code 4 times randomly today, and it was 45-70 points different than AccuWeather’s cloud coverage. I am hoping it is cloud coverage, but I need to watch this for awhile to make sure. (so far, it is not looking good)


#19

Ahhh amazing, I thought there must be an easier way than writing so many statements, i will test that out.

Today the weather is reporting 60+% cloud (im not at the property today to verify) but its kicking out 7kw/h so will have to tweak when i can visually see how accurate underground cloud cover is; will be back home tomorrow then will amend my scripts, but so far today its working well :slight_smile:


#20

Yea, I guess I should have asked you to clarify your full intentions before making those earlier recommendations.