Page 1 of 1

Reading Data from Efergy array json to domoticz

Posted: Sunday 26 November 2017 23:07
by harryn
I have an efergy engage system that reads the electricity usage of some of my devices in the house.
There are 5 meters. Each meter has a SID number. I am getting the following json data from the api but I do not know how to get the data into domoticz via dzvents. I ahve created 5 virtual sensors and 1 hardware device called efergy but I have now idea how to get the data to be stored the right positions

json string:

[{"cid":"PWER","data":[{"1511728303000":8990}],"sid":"779204","units":"kWm","age":17},{"cid":"PWER","data":[{"1511728311000":466}],"sid":"774874","units":"kWm","age":9},{"cid":"PWER","data":[{"1511728306000":395}],"sid":"778807","units":"kWm","age":14},{"cid":"PWER","data":[{"1511728317000":8049}],"sid":"771971","units":"kWm","age":3},{"cid":"PWER","data":[{"1511728305000":27}],"sid":"773905","units":"kWm","age":15}]

current code in dzvents

execute = function(domoticz)
--domoticz.log('Device ' .. device.name .. ' was changed', domoticz.LOG_INFO)
local getData = true
if getData then
local url = 'curl "http://www.energyhive.com/mobile_proxy/ ... ergyAPIkey..'"'
domoticz.log('Requesting new data from Efergy...', domoticz.LOG_DEBUG)
--domoticz.log('URL used: '..url, domoticz.LOG_DEBUG)
local jsondata = assert(io.popen(url))
local efergydevice = jsondata:read('*all')
jsondata:close()
--domoticz.log('Json data: '..efergydevice, domoticz.LOG_DEBUG)
package.path = package.path ..";./scripts/lua/?.lua;" -- This can be removed when using dzVents 2.3.1 or later
local jsonparser = require('JSON')
local efergyAPIData= jsonparser:decode(efergydevice,true)
if not efergyAPIData then
domoticz.log('Could not read EfergyAPIData ', domoticz.LOG_ERROR)
return
end
domoticz.log('Efergy API json data file has been read', domoticz.LOG_DEBUG)
--domoticz.log(efergyAPIData, domoticz.LOG_DEBUG)
for i=1,5 do
for j=1,2 do
domoticz.log(efergyAPIData['data'][j],domoticz.log_DEBUG)
end
end
-- local heatPumpWatt=efergyAPIData[1][2]
domoticz.log('Heat Pump data'.. heatPumpWatt, domoticz.LOG_DEBUG)
end
end

Anyone could help with reading this array ?