LUA script example for http poller

Moderator: leecollings

Post Reply
ajay100
Posts: 72
Joined: Monday 07 August 2017 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: Victoria, Australia
Contact:

LUA script example for http poller

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

Cheers - Andrew
Qcvictor
Posts: 22
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 »

Hi Andrew
Thanks for the script, helpful...
hansake
Posts: 4
Joined: Sunday 09 September 2018 19:07
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: Sweden
Contact:

Re: LUA script example for http poller

Post by hansake »

The applyJsonPath function does not work for me.
See: https://www.domoticz.com/forum/viewtopi ... 91#p218691

Regards
Hans-Åke
User avatar
klaus44
Posts: 8
Joined: Wednesday 20 November 2019 11:33
Target OS: Raspberry Pi / ODroid
Domoticz version: Aktuell
Location: Berlin/Germany
Contact:

Re: LUA script example for http poller

Post 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.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest