Getting a sub array of a string array (Weather API)


#1

Function - $weather.hourly.hourly_forecast.wx returns a string array of the hourly weather conditions for the next 36 hours. I would like to see if “Snow” is in that string, but only for the next 12 hours… not 36.

Is there a way to return a subarray of only values 0-11? Or am I going to have to use 12 statements and reference each member of the array?
if `$weather.hourly.hourly_forecast.wx[0]
or
if $weather.hourly.hourly_forecast.wx[1]
…etc?

Thank you


#2

You’ll probably have to loop through it…

image


#3

You could insert the 12 hours into one variable, and then search that one variable to see if it contains the word ‘Snow’.

Basically, all in two lines like this:

The boolean variable will return true if ‘Snow’ is in the forecast.


It is still summer, so my test returned false:


#4

Thanks for the help, great examples, but I’ve taken this in a different direction. I’m firing a piston off at a certain time and in a while loop, getting the hourly precipitation total and adding it to a variable, waiting an hour and doing it again until a certain time.

Problem I’m having, is it doesn’t seem to be saving the value to the variable (ignore most of the logic, just trying to get testing values with data).

But my logs are showing that they are getting a value of 10, which I expect to be added to the variable, but the variable is staying at 0

+0ms ╔Received event [MyHome].time = 1537466328332 with a delay of -1260ms
+198ms ║Snow Total 0
+328ms ║10.0
+366ms ║Setting up scheduled job for Thu, Sep 20 2018 @ 1:58:52 PM EDT (in 4.993s), with 1 more job pending
+379ms ╚Event processed successfully (380ms)

What am I doing wrong? Am I setting up my expression wrong?


#5

You initialized the variable to 0, so it will be 0 each time the piston runs. Usually, I add a logic in the beginning to checkif variable is greater than 0, if true, then I do variable = variable + new_data, else variable = new_data


#6

Just for future reference, it helps others if a new piston (topic) goes into a new thread.
(I am confused how miles of visibility relates to the amount of snow on the ground)


You have no code in your piston related to this…


The code:
$weather.conditions.current_observation.visibility_mi
Usually returns a decimal from 0-10 showing how many miles away we can see


#7

I’m just using it for testing purposes, its summer, so there won’t be any snow totals. Visibility gives me values I can play with.