Home Forum Community Fibaro Home Center 2 integration Reply To: Fibaro Home Center 2 integration

#6103
Terje Andersen
Participant

For those of you that might be looking into the same challenge:

After a very long time, I have finaly found the solution to import the json string into the Fibaro system.
Each value need it’s own variable.

--[[
%% autostart
%% properties
%% events
%% globals
124 value
--]]

MyId = fibaro:getSelfId()
fibaro:debug(MyId)

local uRad = Net.FHttp("192.168.60.150", 80)
local res, status, errorCode = uRad:GET("/j")
fibaro:debug("status "..status.."; errorCode ".. errorCode.."; res ".. res)

local jsonTable = json.decode(res)
fibaro:debug(jsonTable)

fibaro:setGlobal("uRad_temperature", jsonTable.data.temperature) -- Sensor 1: Temperature
fibaro:setGlobal("uRad_humidity", jsonTable.data.humidity) -- Sensor 2: Humidity
fibaro:setGlobal("uRad_pressure", jsonTable.data.pressure) -- Sensor 3: Pressure
fibaro:setGlobal("uRad_voc", jsonTable.data.voc) -- Sensor 4: VOC (Volatile Organic Compounds)
fibaro:setGlobal("uRad_pm25", jsonTable.data.pm25) -- Sensor 5: PM2.5 (Particulate matter)
fibaro:setGlobal("uRad_ch2o", jsonTable.data.ch2o) -- Sensor 6: Formaldehyde
fibaro:setGlobal("uRad_co2", jsonTable.data.co2) -- Sensor 7: Carbon Dioxide
fibaro:setGlobal("uRad_cpm", jsonTable.data.cpm) -- Sensor 8: Radiation
fibaro:setGlobal("uRad_noise", jsonTable.data.noise) -- Sensor 9: Noise
fibaro:sleep(60*1000)

Tho, will still need to figure out how to make my virtual device work as intended, but this is the solution to import the json string.