-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathscript_time_weewx.lua
169 lines (149 loc) · 6.95 KB
/
script_time_weewx.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
-- Title: script_device_weewx.lua
-- Date: 2019-02-04
-- Original author: domcars0
-- Modified by: Creasol https://www.creasol.it
-- This script read the xml file generated by weeWX with meteo sensors values
-- More info at https://www.creasol.it/support/domotics-home-automation-and-diy/128-usb-weather-station-connected-to-raspberry-pi-and-domoticz
-- <weewx>
-- <data realtime="temp">8.5<!--outsideTemp--></data>
-- <data realtime="hum">73.2<!--outsideHumidity--></data>
-- <data realtime="inTemp">19.5<!--outsideTemp--></data>
-- <data realtime="inHum">53.2<!--outsideHumidity--></data>
-- <data realtime="barometer">1025.5<!--Pressure--></data>
-- ......
-- </weewx>
--
--
commandArray = {} -- reset commandArray, an associative array that will contain the list of commands for Domoticz.
-- ------------------------------- Config --------------------------------
-- DEBUG: comment the following line (-- return) to enable parsing of this file, but first you have to modify the next section!
-- return commandArray
-- MODIFIFY THE FOLLOWING SECTION specifying the idx of each variable that you have created in Domoticz
local debug=0 -- 1=log verbose information. 0=do not log anything
local wind_sensor_name="Wind (roof)" -- name of wind sensor
local outdoor_device_idx = 43 -- Domoticz idx of outdoor sensors (Temperature+Humidity+Pressure)
local indoor_device_idx = 44 -- Domoticz idx of indoor sensors (Temperature+Humidity)
local wind_device_idx = 45 -- Domoticz idx of wind sensor
local rain_device_idx = 46 -- Domoticz idx of rain sensor
local aux_device_idx = 255 -- Domoticz idx of aux sensors, if available. If not available, specify 255 (to disable it)
local infilename="/tmp/weewx/domoticz.xml" -- set to the local domoticz.xml file generated by weewx
local infileurl="" -- set to "" if weewx file is local
-- local infilename="" -- set to "" if weewx file is downloaded from another website
-- local infileurl="http://www.weewxsite.com/domoticz.xml" -- URL of the file generated by weewx
-- --------------------------- End of Config -----------------------------
local filename = "/tmp/weewx/domoticz_converted.xml"
local infile
if (infilename~='') then
infile=io.open(infilename,"r")
if (infile~=nil) then
-- input file exists
io.close(infile)
os.execute('sed s:,:.: '..infilename..' |sed s:N/A:0: > '..filename) -- convert file translating , in .
if (debug==0) then os.remove(infilename) end
else
-- input file does not exist: return (waiting that new file will be generated by weewx
return commandArray
end
elseif (infileurl~='') then
-- remote file: should be downloaded using wget, and converted
os.execute('wget '..infileurl..' -O - | sed s:,:.: > '..filename)
end
local line , tempdevice = ''
local temperature,humidity,pressure,inhumidity,intemperature,auxhumidity,auxtemperature,rain,rainrate,wind,winddir,windgust,windchill = 0
local windcomp = 'N'
for line in io.lines(filename) do
if string.find(line,"\"temp\"") then
temperature=tonumber(string.match(line, "%-?%d+.?%d*"))
if (debug>0) then print('temp='..temperature) end
elseif string.find(line,"\"hum\"") then
humidity=tonumber(string.match(line, "%d+"))
if (debug>0) then print('humidity='..humidity) end
elseif string.find(line,"\"inTemp\"") then
intemperature=tonumber(string.match(line, "%-?%d+.?%d*"))
if (debug>0) then print('intemperature='..intemperature) end
elseif string.find(line,"\"inHum\"") then
inhumidity=tonumber(string.match(line, "%d+"))
if (debug>0) then print('inhumidity='..inhumidity) end
--[[
elseif string.find(line,"\"auxTemp\"") then
auxtemperature=tonumber(string.match(line, "%-?%d+.?%d*"))
if (debug>0) then print('auxtemperature='..auxtemperature) end
elseif string.find(line,"\"auxHum\"") then
auxhumidity=tonumber(string.match(line, "%d+"))
if (debug>0) then print('auxhumidity='..auxhumidity) end
]]
elseif string.find(line,"\"barometer\"") then
pressure=tonumber(string.match(line, "%d+"))
if (debug>0) then print('pressure='..pressure) end
elseif string.find(line,"\"rainrate\"") then
rainrate=100 * tonumber(string.match(line, "%d+.?%d*"))
if (debug>0) then print('rainrate='..rainrate) end
elseif string.find(line,"\"Rain\"") then
rain=tonumber(string.match(line, "%d+.?%d*"))
if (debug>0) then print('rain='..rain) end
elseif string.find(line,"\"wind\"") then
wind=tonumber(string.match(line, "%d+"))
if (debug>0) then print('wind='..wind) end
elseif string.find(line,"\"Winddir\"") then
winddir=string.match(line, "%d+")
if (debug>0) then print('winddir='..winddir) end
elseif string.find(line,"\"Windgust\"") then
windgust=tonumber(string.match(line, "%d+"))
if (debug>0) then print('windgust='..windgust) end
elseif string.find(line,"\"Windcomp\"") then
windcomp=string.match(line, "Windcomp\">([NESW0]+)<!--")
if (debug>0) then print('windcomp='..windcomp) end
elseif string.find(line,"\"WindChill\"") then
windchill=tonumber(string.match(line, "%-?%d+.?%d*"))
if (debug>0) then print('windchill='..windchill) end
end
end
--[[
-- Si la vitesse du vent est nulle winddir et windcomp garde la valeur précédente
if ( wind == 0 or wind == nil ) then
winddir,windcomp = prev_wind:match("([^;]+);([^;]+)")
wind = 0
end
]]
-- A l'initialisation du device domoticz on peut avoir des valeurs farfelues
if winddir == nil then
winddir = 0
end
if windcomp =='0' then
windcomp = 'N'
end
if windchill == nil then
windchill = 0
end
if windgust== nil then
windgust= 0
end
-- Conversion de win et wingust (domoticz attend 10 * Winspeed [m/s] -- weewx nous donne Winspeed [km/h]
wind = math.ceil(wind / 0.36)
windgust = math.ceil(windgust / 0.36)
-- Raspberry room
if not ( inhumidity == nil or intemperature == nil ) then
tempdevice = indoor_device_idx..'|0|'..intemperature..';'..inhumidity..';0'
commandArray[1]={['UpdateDevice'] = tempdevice }
end
-- Outdoor place where Meteo station is placed
if not ( humidity == nil or temperature == nil or pressure == nil ) then
tempdevice = outdoor_device_idx..'|0|'..temperature..';'..humidity..';0;'..pressure..';0'
commandArray [2] = {['UpdateDevice'] = tempdevice }
end
-- Rain
if not ( rainrate == nil or rain == nil ) then
tempdevice = rain_device_idx..'|0|'..rainrate..';'..rain
commandArray [3] = {['UpdateDevice'] = tempdevice }
end
-- Wind
if not ( temperature == nil ) then
tempdevice = wind_device_idx..'|0|'..winddir..';'..windcomp..';'..wind..';'..windgust..';'..temperature..';'..windchill
commandArray [4] = {['UpdateDevice'] = tempdevice }
end
-- Aux sensor, if supported by the weather station
if not ( auxhumidity == nil or auxtemperature == nil or aux_device_idx == 255 ) then
tempdevice = aux_device_idx..'|0|'..auxtemperature..';'..auxhumidity..';0'
commandArray [5] = {['UpdateDevice'] = tempdevice }
end
return commandArray