LUA script example for http poller

Post Reply
ajay100
Posts: 30
Joined: Monday 07 August 2017 15:01
Target OS: Raspberry Pi
Domoticz version: 3.9560
Location: Victoria, Australia
Contact:

LUA script example for http poller

Post by ajay100 » Monday 11 June 2018 9:41

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 746 times
The file current.json is generated by weewx and is saved in /home/pi/weewx/public_html

Cheers - Andrew

Qcvictor
Posts: 36
Joined: Wednesday 08 April 2015 3:13
Target OS: Linux
Domoticz version: Beta
Location: Canada
Contact:

Re: LUA script example for http poller

Post by Qcvictor » Monday 11 June 2018 12:16

Hi Andrew
Thanks for the script, helpful...

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests