Help With webCoRE GET Request Values

I am using a webCoRE piston to send a GET request to the USGS's API. It is returning the water temperature for a local river. For whatever reason the value webCoRE is logging is different than the actual value. It's treating it as a whole number and ignoring everything on the right side of the decimal. I can do the same GET request through a script I wrote and it spits out the correct value. Here's the piston:

Might try stepping back and listing out the entire series values string to see if you’re just off a position or 2.

Here's the GET request:

https://waterservices.usgs.gov/nwis/iv/?format=json&indent=on&sites=02035000&parameterCd=00010&siteStatus=active

I'm using value.timeSeries.values.value.value in both my PS script and in webCoRE. The script spits out the correct value. The webCoRE logs show it returning [[[5.4]]] (not sure what's up with the brackets) and then when converting from that value to Fahrenheit it decides to use 5.0 instead.

2/14/2022, 9:51:42 PM +406ms
+5ms	â•”Received event [Home].wc_async_reply = httpRequest with a delay of 0ms, canQueue: true, calledMyself: false
+15ms	â•‘RunTime initialize > 14 LockT > 1ms > r9T > 2ms > pistonT > 1ms (first state access 11 6 8)
+18ms	â•‘Runtime (7048 bytes) initialized in 2ms (v0.3.114.20220203_HE)
+22ms	â•‘â•”Execution stage started
+34ms	â•‘â•‘[[[5.4]]]
+36ms	â•‘â•‘Executed virtual command log (2ms)
+44ms	â•‘â•‘Executed virtual command setVariable (2ms)
+50ms	â•‘â•‘Calculating (decimal)5.0 * (decimal)1.8 >> (decimal)9.0
+53ms	â•‘â•‘Calculating (decimal)9.0 + (decimal)32.0 >> (decimal)41.0
+58ms	â•‘â•‘Executed virtual command setVariable (2ms)

Might consider using some string functions to isolate and then assign to the decimal variable:

1 Like

For whatever reason it decided to start working overnight. I didn't make any changes. It looks like it's now returning the value without the brackets so I guess maybe they were causing this issue? I'll keep your suggestion in mind if I have any other issues. Thanks!

1 Like

Another thought, may be able to use $response.json also...

1 Like

Ugh... I had my pistons mixed up. Long night. This one was still returning the brackets, but your string function seemed to correct that once I realized that index0f was actually indexOf.

Anyhow, I now have a working piston with the correct values AND I learned something new. Thanks!

1 Like

:slight_smile: One of the reasons I wait until after the second cup of coffee before I change something. Glad to be of assistance.

1 Like

Download the Hubitat app