HTTP Request Get - Capture Response to more than one variable

I am just starting with Reactor and would like to convert my LUA code into Reactor sensors. I have successfully added a ‘Notify’ when my solar panels stop producing (RCD trip).

I also upload current temperature and solar live output to PVOutput.com and would like to be notified when this upload fails.

I get the temperature from an API call to wunderground.com. In the LUA code this returns two variables (wstatus and wresult).

local wurl = "https://api.weather.com/v2/pws/observations/current?stationId=ILOUGHBO8&format=json&units=m&apiKey=<MyAPIKey>"
local wstatus,wresult = luup.inet.wget(wurl, 5)

I hoped I could migrate this to Reactor with HTTP Request Get. However I cannot see a way to get Reactor to accept the two returned variables?

If not possible, I could use the ‘Run LUA’ Activity to get the returned variables, but cannot see how to then use the variables as a condition to initiate a ‘Notify’ activity within the same Reactor sensor?

Any help gratefully received
Thanks Malcolm

Off topic, but I have to ask: does this happen often?

While you wait for @rigpapa to chime in, it occurs to me that his other plug-in, SiteSensor, might stand a better chance at satisfying your requirements. Its primary focus is on sending GET/POST requests and parsing multiple variables from the response.

I’m not saying Reactor can’t accomplish what you’re after, but it’s entirely possible that it is limited to a single variable assignment in this case. Not sure. Either way, it works great with SiteSensor, so I wanted to suggest you at least consider that alternative.

No, every few months.

Last time I did not notice for several days, hence my requirement for a ‘Notification’.

Sometimes there is a reason (power outage, lightning etc.), other times, no apparent cause.

Malcolm

Hmm, I’ve never seen that problem on my own system, but it might indeed be tough to notice…

…although I do continuously log the output, I may not look at it for a while.

You can use an HTTP Request action to load a variable with the JSON response, which will be a string at that point. The unstringify() function will convert it to a table, and from there, you make other expressions to extract the data from the table. You don’t need SiteSensor for this, but you certainly could do it that way.

See the documentation

1 Like

Thanks rigpapa, I didn’t know that approach.

The reason I wanted to get at both variables. If there is an error in say the API key, I am not sure ‘wresult’ is returned or if it is what is it’s value. Whereas the ‘wstatus’ definitely returns non zero. So I was going to use the ‘wstatus’ as a positve indication of failure.

I had seen SiteSensor referenced in the documentation, and did not realise it was your plugin! I didn’t pursue it as I wanted to keep the number of plugins down, if it could be done natively in a Reactor sensor.

Malcolm

1 Like