-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathirrigation.lua
More file actions
172 lines (140 loc) · 5.47 KB
/
Copy pathirrigation.lua
File metadata and controls
172 lines (140 loc) · 5.47 KB
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
169
170
171
172
-- irrigation dzVents Script
-- Martin Saidl (c) 2023 - 2025
local version = '1.1' -- current version of script
------------------------------------------------------------------------
local LOGGING = false -- true or false LOGGING info to domoticz log.
local NOTIFYING = true -- true or false to enable or disable notification
-- Source devices
local OutsideTempHum = 'Venkovní teplota a vlhkost'
local RainMeter = 'Srážkoměr'
local Switch = 'Zalévání'
local Trigger = 'Zalévání - Start'
local WaterLevel = 'Vodojem kapacita'
-- Destination devices
local Pump = 'Vodojem čerpadlo'
local Blower = 'Vodojem dmychadlo'
-- Constants
-- Maximum time from last update in minutes
local AliveTime = 60
-- Regulation contants in seconds
local AbsoluteTime = 40
local TemperatureTime = 40
--local RepeatCycles = 2
-- Notification
local NotificationMessagePump = 'Probíhá zalévání'
local NotificationMessageBlower = 'Ozonifikace aktivována'
--********
-- FUNCTIONS
--********
local function log(domoticz, text, lvlError)
local lvlLog = domoticz.LOG_INFO
if lvlError ~= nil and lvlError == true then lvlLog = domoticz.LOG_ERROR end
if LOGGING then domoticz.log(text, lvlLog) end
end
-- Geting actual rain conditions
local function actualRainConditions(domoticz)
local iRain = 1
if RainMeter ~= '' and domoticz.devices(RainMeter).lastUpdate.minutesAgo < AliveTime then
local rain = domoticz.devices(RainMeter).rain
local rainRate = domoticz.devices(RainMeter).rainRate
log(domoticz,'Rain today: ' .. rain .. 'mm')
if rain > 0.8 and rain <= 2 then
iRain = 0.5
elseif rain > 2 or rainRate > 0 then
iRain = 0
end
else
log(domoticz,'Rain value is unknown, setting value to 0 mm')
end
return iRain
end
-- Getting actual temperature conditions
local function actualTemperatureConditions(domoticz)
local temp
local iTemp = 0
if OutsideTempHum ~= '' and domoticz.devices(OutsideTempHum).lastUpdate.minutesAgo < AliveTime then
temp = domoticz.devices(OutsideTempHum).temperature
else
temp = 22
log(domoticz,'Temperature is unknown, setting value to 22 °C')
end
if temp > 20 and temp <= 35 then
iTemp = (temp - 20)/15
elseif temp > 20 then
iTemp = 1
end
log(domoticz,'Temperature: ' .. temp .. '°C; Temperature index: ' .. iTemp)
return iTemp
end
-- Testing Water level in tank
local function checkWaterLevel(domoticz)
if WaterLevel ~= '' and domoticz.devices(WaterLevel).lastUpdate.minutesAgo < AliveTime then
if domoticz.devices(WaterLevel).percentage > 5 then
return true
end
end
return false
end
--********
-- Main Loop
--********
return {
logging = {
marker = "irrigation"
},
on = {
timer = {
'at 8:00',
'at 12:00',
'at 16:00',
'at 20:00',
},
devices = {
Trigger,
},
},
execute = function(domoticz, item)
local booster = 1
if domoticz.devices(Pump).state == 'On' then
log(domoticz,'Pump is already ON -> skipping.')
return
end
if (item.isTimer or (domoticz.devices(Trigger).state == 'On')) and (domoticz.devices(Switch).state == 'On') then
--if (domoticz.devices(Switch).state == 'On') then
local now = domoticz.time.hour
log(domoticz,'Actual time hour is: ' .. now)
if now == 8 then
booster = 2
domoticz.devices(Blower).switchOn().forSec(600)
if NOTIFYING then
domoticz.notify(NotificationMessageBlower)
end
elseif now == 20 then
booster = 1.5
domoticz.devices(Blower).switchOn().forSec(600)
if NOTIFYING then
domoticz.notify(NotificationMessageBlower)
end
end
local iRain = actualRainConditions(domoticz)
local iTemp = actualTemperatureConditions(domoticz)
-- Counting "pump on" interval
local interval = (AbsoluteTime + iTemp * TemperatureTime) * iRain * booster
if checkWaterLevel(domoticz) and interval > 0 then
-- Sensor issue protection
if interval > 200 then
interval = 200
end
--domoticz.devices(Pump).switchOn().forSec(interval).repeatAfterSec(15, RepeatCycles)
domoticz.devices(Pump).switchOn().forSec(interval)
--log(domoticz,'Pump is ON for: ' .. RepeatCycles .. ' interval(s) of ' .. interval .. 'seconds.')
log(domoticz,'Pump is ON for: ' .. interval .. ' seconds.')
if NOTIFYING then
domoticz.notify(NotificationMessagePump)
end
else
log(domoticz,'Pump has not been switched on.')
end
end
end
}