Code : Tout sélectionner
-- 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://192.168.0.153/weewx/domoticz.xml -O /home/jeeper/domoticz/scripts/lua/domoticz.xml')
local filename = "/var/www/html/weewx/domoticz.xml"
local temperature = ''
local humidity = ''
local pressure = ''
for line in io.lines(filename) do
if string.find(line,"\"temp\"") then
temperature=string.match(line, "%-?%d+,?%d*")
print("Temperature: "..tostring(temperature))
end
if string.find(line,"\"hum\"") then
humidity=string.match(line, "%d+")
print("Humidity: "..tostring(humidity))
end
if string.find(line,"\"barometer\"") then
pressure=string.match(line, "%d+")
print("Pressure: "..tostring(pressure))
end
end
-- Update device id 1, nval 0 sval temp;hum;hum-stat;baro;baro-stat
tempdevice='1|0|'..temperature..';'..humidity..';0;'..pressure..';0'
print(tempdevice)
commandArray['UpdateDevice'] = tempdevice
return commandArray
Si, comme je le disais précédemment, la température contient bien une virgule, il faudra la remplacer par un point, par exemple en mettant
Code : Tout sélectionner
temperature = temperature:gsub(",", ".")