Code: Select all
--lua script to parse json data (in this case from weewx) to http/https poller virtual hardware
--Sample json data
--[[
"stats": {
"current": {
"outTemp":"12.3",
"windchill":"12.3",
"heatIndex":"12.3",
"dewpoint":"7.9",
"humidity":"74",
"insideHumidity":"61",
"barometer":"1024.9",
"windSpeed":"0",
"windDir":"202",
"windDirText":"SSW",
"windGust":"4",
"windGustDir":"202",
"rainRate":"0.0",
"insideTemp":"17.4"
}
}
]]
local outTmp_id = 44
local outTHB_id = 45
local wnd_id = 46
local inTHB_id = 47
-- Retrieve the content
s = request['content'];
-- Note the hierarchy .stats.current for the json
local outTemp = domoticz_applyJsonPath(s,'.stats.current.outTemp')
local humidity = domoticz_applyJsonPath(s,'.stats.current.humidity')
local forecast = 0
local barometer = domoticz_applyJsonPath(s,'.stats.current.barometer')
local windDir = domoticz_applyJsonPath(s,'.stats.current.windDir')
local windDirText = domoticz_applyJsonPath(s,'.stats.current.windDirText')
local windSpeed = domoticz_applyJsonPath(s,'.stats.current.windSpeed')
local windGust = domoticz_applyJsonPath(s,'.stats.current.windGust')
local windchill = domoticz_applyJsonPath(s,'.stats.current.windchill')
local insideHumidity = domoticz_applyJsonPath(s,'.stats.current.insideHumidity')
local insideTemp = domoticz_applyJsonPath(s,'.stats.current.insideTemp')
domoticz_updateDevice(outTmp_id,'',outTemp)
domoticz_updateDevice(outTHB_id,'',outTemp .. ";" .. humidity .. ";" .. forecast .. ";" .. barometer .. ";" .. forecast)
domoticz_updateDevice(wnd_id,'',windDir .. ";" .. windDirText .. ";" .. windSpeed .. ";" .. windGust .. ";" .. outTemp .. ";" .. windchill)
domoticz_updateDevice(inTHB_id,'',insideTemp .. ";" .. insideHumidity .. ";" .. forecast .. ";" .. barometer .. ";" .. forecast)
--Debugging - check the current value in Domoticz
--s_3 = otherdevices['Sonos']
--s_4 = otherdevices['Sonos 2']
--print('1: '..s_3)
--print('2: '..s_4)
The file current.json is generated by weewx and is saved in /home/pi/weewx/public_html
Cheers - Andrew