Page 1 of 1

LUA script example for http poller

Posted: Monday 11 June 2018 9:41
by ajay100
Victor requested the LUA script I'm using in Domoticz to parse weewx weather data. This script lives in /home/pi/domoticz/scripts/lua_parsers.

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)

Here are the hardware device settings in Domoticz:
http_poller_settings_chrome.jpg
http_poller_settings_chrome.jpg (33.24 KiB) Viewed 4282 times
The file current.json is generated by weewx and is saved in /home/pi/weewx/public_html

Cheers - Andrew

Re: LUA script example for http poller

Posted: Monday 11 June 2018 12:16
by Qcvictor
Hi Andrew
Thanks for the script, helpful...

Re: LUA script example for http poller

Posted: Thursday 04 July 2019 14:28
by hansake
The applyJsonPath function does not work for me.
See: https://www.domoticz.com/forum/viewtopi ... 91#p218691

Regards
Hans-Åke

Re: LUA script example for http poller

Posted: Monday 16 December 2019 20:04
by klaus44
Hi

I use the Lua script and it works well.

I have the problem that Weewx passes the sensor data to Lua with a comma, for example. outside temperature: 20,6

In Domoticz, only the first digit is then displayed, for example. 20.0

Domoticz only accepts point values eg 20.6

Is there a way in the Lua Script to convert the comma values to points eg 20.6?

Eg outside temperature 20,6 to 20.6


Would be grateful for a help

My Station is WH3080 and weewx



Edit :

Has solved itself, I have solved the problem, now I have all sensor data with point.