I have update it to provide a custom json from a file with this:
Code: Select all
-- Example of JSON parser handling data with the following structure
local open = io.open
local function read_file(path)
local file = open(path, "rb") -- r read mode and b binary mode
if not file then return nil end
local content = file:read "*a" -- *a or *all reads the whole file
file:close()
return content
end
local s=read_file("/home/pi/domoticz/scripts/lua_parsers/example.json")
-- Update some devices (index are here for this example)
local id = domoticz_applyJsonPath(s,'.id')
local s = domoticz_applyJsonPath(s,'.temperature')
print(id .. temperature)
domoticz_updateDevice(id,'',s)
Code: Select all
{"id": 13,"name": "outside","temperature": 12.50}