Using $index from response


#1

I’ve tried all the limited ways that my little mind could figure out (not being a developer does not help) and have come to a complete blank. Hoping that someone on this community can help me with this.

I’m calling on to darksky weather api. In particular their hourly api for weather conditions for precipProbability. The api provides something like the forecast for the next 24 hours. What i would like to do is evaluate $response.hourly.data.precipProbability[$index] and if the value should be more than 0.2 (20%), is to capture the first occorunce that the condition is met and store either the $index value or the corresponding $response.hourly.data.time[$index]

That way i can then assume that there is an X% chance of rain at hh:mm and use that information on something like Echo Speaks when i ask “will it rain?”.

The next part, which is a smaller issue is…how do i convert UNIX time to a format that WC understands?

Thanks in advance!!


#2

web core should parse a UNIX style date string correctly.
ie: it should accept the string
Tue Apr 9 23:34:59 EDT 2019

while not exactly the same this piston shows some of walking a response:
It is often good to do a curl request so that you clearly see the data layout being returned


#3

I played with this one earlier and got the values but I’m having a heck of a time formatting the epoch time to something useful.

(expression) formatDateTime(1555088400,'MMM dd yy, hh:mm') »»» (string) Jan 18 70, 04:58

image

|+3096ms|║║Executed virtual command log (2ms)|    |---|---|
|+3162ms|║║precipProbability at: 1555077600 : 0 Greater than or equal to 20%: No|
|+3164ms|║║Executed virtual command log (2ms)|
|+3231ms|║║precipProbability at: 1555081200 : 0 Greater than or equal to 20%: No|
|+3232ms|║║Executed virtual command log (2ms)|
|+3301ms|║║precipProbability at: 1555084800 : 0.01 Greater than or equal to 20%: No|
|+3303ms|║║Executed virtual command log (1ms)|
|+3368ms|║║precipProbability at: 1555088400 : 0.01 Greater than or equal to 20%: No|
|+3370ms|║║Executed virtual command log (2ms)|
|+3373ms|║╚Execution stage complete. (3262ms)|
|+3374ms|╚Event processed successfully (3374ms)|

#4

Do you have to do something like:

define
datetime mydateTime
end define;

set variable mydateTime = {datetime(1555077600)} ;

or some such?


#5

I was actually just messing with it again in the Eval console and still not finding the correct combo.

(expression) formatDateTime(datetime(1555077600),'MMMMM dd, yyyy @ h:mm a') »»» (string) January 18, 1970 @ 4:57 PM
(expression) formatDateTime(1555077600,'MMMMM dd, yyyy @ h:mm a') »»» (string) January 18, 1970 @ 4:57 PM

image


#6

try this in evaluation console:

{formatDateTime({$utc},‘MMM dd YY’)}


#7

After a bazillion trials…


#8

You’re a legend!!! Thanks for that.

To capture the first occurence of when precipProbability is more that 0.2, i created a Variable and set Variable=Variable+string((decimal($response.hourly.data[$index].precipProbability)>=0.2?'1':'0'))"," - this is so that it list it down. Then using indexOf to find the first occurrence of ‘1’ (needed to divide the value by 2 due to the comma).

I could then drill down to get the exact value for both precipProbability and time using that variable.

Thanks again!!