-
Notifications
You must be signed in to change notification settings - Fork 0
/
Heating.lua
62 lines (52 loc) · 2.24 KB
/
Heating.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
return {
on = {
timer = { 'every minute' }
},
logging = {
level = domoticz.LOG_FORCE,
marker = "Heating"
},
execute = function(domoticz, timer)
if (not domoticz.devices('Heating Automation').active) then return end
local temp = domoticz.devices('Xiaomi Temperature').temperature
local outsideTemp = domoticz.devices('Weather').temperature
local time = os.date("*t")
local plug = domoticz.devices('SP1 Plug 3')
local isDay = time.hour >= 10 and time.hour <= 21
local isNight = not isDay
local temperatureSetPoint = domoticz.devices('Temperature Set').setPoint
local outsideCorrection = 0;
if (outsideTemp > 25) then
outsideCorrection = -1.2;
elseif (outsideTemp > 20) then
outsideCorrection = -0.8;
elseif (outsideTemp > 15) then
outsideCorrection = -0.5;
elseif (outsideTemp > 10) then
outsideCorrection = -0.2;
end
local tempDeviation = 0.2
local nightDelta = 1.5
local dayMaxTemp = temperatureSetPoint + outsideCorrection + tempDeviation
local nightMaxTemp = dayMaxTemp - nightDelta
local dayMinTemp = temperatureSetPoint + outsideCorrection - tempDeviation
local nightMinTemp = dayMinTemp - nightDelta
local maxTemp = dayMaxTemp
local minTemp = dayMinTemp
if (isNight) then
maxTemp = nightMaxTemp
minTemp = nightMinTemp
end
if (((domoticz.devices('State').state == 'Home') or (domoticz.devices('State').state == 'Sleep'))
and (temp < minTemp) and not plug.active) then
domoticz.log('plug.active'..tostring(plug.active), domoticz.LOG_DEBUG)
plug.switchOn().checkFirst()
domoticz.log('Heating on, temp '..temp..' C, min '..minTemp..'С max '..maxTemp..'С.', domoticz.LOG_FORCE)
end
if ((temp > maxTemp) and plug.active) then
domoticz.log('plug.active'..tostring(plug.active), domoticz.LOG_DEBUG)
plug.switchOff().checkFirst()
domoticz.log('Heating off, temp '..temp..' C, min '..minTemp..'С max '..maxTemp..'С.', domoticz.LOG_FORCE)
end
end
}