I am trying to get a power reading from my energy monitor but am having lots of trouble trying to work out what code i need to use. I need to get a particular piece of info from this response I get.
I don't have any experience in coding don't have much idea, but a nudge in the right direction would be greatly appreciated.
The exact response from the http request is = [{"cid":"PWER","data":[{"1525674668000":746}],"sid":"740893","units":"kWm","age":6}]
my energy monitor is a efergy monitor.
http://www.energyhive.com/content/about/develop is where I got the API details from.
"746" is the value I am trying to retrieve.
When I print (response.data) I get [DEBUG] 16:31:24: [{"cid":"PWER","data":[{"1525674668000":746}],"sid":"740893","units":"kWm","age":6}]
When I print json.decode(response.data) I get [DEBUG] 16:17:02: table: 0x9c41348 -- I don't know what this means
I tested the path here: https://jsonpath.curiousconcept.com/
and can get the watt reading using this code "..data[0]*" in the json path expression field
Scene code i'm using. I just copied and pasted from another forum post by @Lambik to get the http request, I'l make my own code later if i can get this data out.
local http = net.HTTPClient();
http:request("http://www.energyhive.com/mobile_proxy/getCurrentValuesSummary?token=XXXX",
{
options = {
method = "GET",
headers = {
['Authorization'] = 'Bearer xxxxxxxx',
}
},
success = function(response)
--error = function(err) fibaro:debug("Error: " .. err)
local jsonTable = json.decode(response.data)
jsonData = response.data
jsonTable = json.decode(jsonData)
local jsonpower = jsonTable
fibaro:debug(jsonpower)
end
})