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
| -- script_time_ventilatie.lua
local PipeTemperatureSensor = 'Temp warmwaterleiding (TH16)' --Name of the sensor that only contains temperature
local TriggerTemperature = 45 --temperature of hotwater pipe where fan should start running (was 35)
local LowerTriggerTemperature = 28 --temperature of hotwater pipe where fan should STOP running
local FanSwitch = 'Itho HIGH' --name of switch that controls the fan
local BathroomLightswitch = 'Badkamerlicht (KaKu)' --name of switch of bathroomlight
local FanStandardRuntime = 900 --time (seconds) that fan should run each shower session, 1800 seconds, half an hour
local FanMaxRuntime = 3600 --time (seconds) that fan should run at max before it is stopped (to prevent running endlessly), 3600 seconds, 1 hour
DEBUG_MODE = true --set to 'true' (without quotes) if you want to see more messages in Domoticz log
commandArray = {}
-- Function to get timedifference (in seconds) since fan has started
s1 = otherdevices_lastupdate[PipeTemperatureSensor]
s = otherdevices_lastupdate[FanSwitch]
-- returns a date time like 2013-07-11 17:23:12
year = string.sub(s, 1, 4)
month = string.sub(s, 6, 7)
day = string.sub(s, 9, 10)
hour = string.sub(s, 12, 13)
minutes = string.sub(s, 15, 16)
seconds = string.sub(s, 18, 19)
year1 = string.sub(s1, 1, 4)
month1 = string.sub(s1, 6, 7)
day1 = string.sub(s1, 9, 10)
hour1 = string.sub(s1, 12, 13)
minutes1 = string.sub(s1, 15, 16)
seconds1 = string.sub(s1, 18, 19)
t1 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
t2 = os.time{year=year1, month=month1, day=day1, hour=hour1, min=minutes1, sec=seconds1}
t = os.time()
difference = os.difftime (t, t1)
difference1 = (os.difftime (t, t2))
print (tonumber(difference))
verschil = tonumber(difference1)+tonumber(difference)
function timedifference (s)
year = string.sub(s, 1, 4)
month = string.sub(s, 6, 7)
day = string.sub(s, 9, 10)
hour = string.sub(s, 12, 13)
minutes = string.sub(s, 15, 16)
seconds = string.sub(s, 18, 19)
t1 = os.time()
t2 = os.time{year=year, month=month, day=day, hour=shour, min=sminutes, sec=sseconds}
difference = os.difftime (t1, t2)
return commandArray
end
if DEBUG_MODE == true then
print('<b style="color:Blue">=========== Ventilatiescript start ============</b>')
print('Sensorname: ' .. PipeTemperatureSensor)
print('TriggerTemperature ' .. TriggerTemperature)
print('Ondergrens ' .. LowerTriggerTemperature)
-- print('Huidige leidingtemperatuur: ' .. sTemp)
print('Naam fanschakelaar ' .. FanSwitch)
print('Lichtschakelaar badkamer ' .. BathroomLightswitch)
print('Nalooptijd ' .. FanStandardRuntime)
print('Max looptijd fan ' .. FanMaxRuntime)
print('Fan ingeschakeld ' .. verschil .. ' seconden geleden')
print('<b style="color:Blue">=========== Ventilatiescript start ============</b>')
end
difference = timedifference(otherdevices_lastupdate[FanSwitch])
--Turn fan off if someone is showering, turn fan off if conditions become valid
if otherdevices[BathroomLightswitch] == 'On' and otherdevices[FanSwitch] == 'Off' and otherdevices_temperature[PipeTemperatureSensor] >= tonumber (TriggerTemperature) then --someone is showering, turn fan on
commandArray[1]={[FanSwitch]='On'}
print('<b style="color:Blue">Badkamerlicht is aan, fan is uit, leiding warm genoeg ---> fan aanzetten</b>')
elseif otherdevices[FanSwitch] == 'On' and otherdevices_temperature[PipeTemperatureSensor] <= tonumber (LowerTriggerTemperature) and (verschil > FanStandardRuntime) then --fan is running but pipe has cooled down below minThreshold and fan has been running for 30min, turn fan off
commandArray[1]={[FanSwitch]='Off'}
print('<b style="color:Blue">Fan is aan, maar warmwaterleiding afgekoeld en fan heeft nalooptijd erop zitten ---> Fan uitzetten</b>')
elseif otherdevices[FanSwitch] == 'On' and (verschil > FanMaxRuntime) then --Fan has exceeded max runtime, turn fan off
commandArray[1]={[FanSwitch]='Off'}
print('<b style="color:Blue">Fan is aan, maar maximum draaitijd is verstreken ---> Fan uitzetten</b>')
end
return commandArray |