{"data":{ "id":"12000059","type":"1","detector":"SI29BG","cpm":9,"temperature":27.75,"uptime": 1360190}}
I managed to decode the values and import them into Domoticz
I want to read 5 values for 5 minutes, sum the 5 values and divide the sum by 5, and import that average into Domoticz
This is the code i made.
Code: Select all
local idxCpm = 425 --idx of the CPM count
local idxUptime = 426 -- idx of Uptime
local cpm = " "
local uptime = " "
-- local cpmTot
commandArray={}
json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")()
local jsondata = assert(io.popen('curl http://192.168.178.20/j'))
local jsondevices = jsondata:read('*all')
jsondata:close()
local jsonCPM = json:decode(jsondevices)
cpm = jsonCPM.data.cpm
uptime = jsonCPM.data.uptime
-- cpmTot = cpmTot + cpm
time = os.date("*t")
if ((time.min % 5)==0) then
-- cpm = cpmTot/5
commandArray[1] = {['UpdateDevice'] = idxCpm .. '|0|' .. cpm}
commandArray[2] = {['UpdateDevice'] = idxUptime .. '|0|' .. uptime/60} -- uptime in minutes
-- cpmTot = 0
end
return commandArray
The problem is in cpmTot which I cannot declare or use , it has to be a float I guess
I hope someone can tell me what I do wrong and how to correct it.