I'm working on lua script to extract the current conditions from weewx and show them in Domoticz but I just can't work out how to pass variables to UpdateDevice.
I'm sure I'm just missing a subtlety of lua's type handling.
Here's the full script but the problem lines are at the bottom
Code: Select all
-- Title: script_device_weewx.lua
-- Date: 09-01-2016
-- this script reads the weewxpws xml file and uploads current data to virtual device
commandArray = {}
os.execute('wget http://server1/weewx/XML/weewx_pws.xml -O /home/phil/domoticz/scripts/lua/weewx_pws.xml')
local filename = "/home/phil/domoticz/scripts/lua/weewx_pws.xml"
local line = ''
local temperature = 0
local humidity = 0
local pressure = 0
local tempdevice = ''
for line in io.lines(filename) do
if string.find(line,"\"temp\"") then
temperature=line
end
if string.find(line,"\"hum\"") then
humidity=line
end
if string.find(line,"\"barometer\"") then
pressure=line
end
--print(line)
end
-- Update device id 23, nval 0 sval temp;hum;hum-stat;baro;baro-stat
tempdevice='23|0|'..temperature..';'..humidity..';0;'..pressure..';0'
--force print as string
print(string.format("%s",tempdevice))
-- none of these work
--commandArray['UpdateDevice'] = "23|0|" .. temperature .. ";" .. humidity .. ";0;" .. pressure .. ";0"
--commandArray['UpdateDevice'] = '23|0|'..temperature..';'..humidity..';0;'..pressure..';0'
--commandArray['UpdateDevice'] = tempdevice
-- only this one updates the device
commandArray['UpdateDevice'] = '23|0|6.4;99;0;983.1;0'
return commandArray
2016-01-09 22:13:00.184 LUA: 23|0|6.3;99;0;982.8;0
but however I try to post the information to the device it just keeps setting everything to 0
Any ideas. As far as I can see I'm following the example scripts on the wiki pages in the ways i've tried.
Phil