greenhouse circulating fan
Posted: Tuesday 29 September 2020 9:07
hello everyone
a circulating fan should work for 5 minutes and stop working for 15 minutes in a greenhouse, only when the exhaust fan is off for some time, i.e. 20 minutes. By the way, the code below is a "time" event, running every minutes
i don't understand why this simple code doesn't work. Can u plz help me

a circulating fan should work for 5 minutes and stop working for 15 minutes in a greenhouse, only when the exhaust fan is off for some time, i.e. 20 minutes. By the way, the code below is a "time" event, running every minutes
i don't understand why this simple code doesn't work. Can u plz help me
Code: Select all
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=hour, min=minutes, sec=seconds}
difference = os.difftime (t1, t2)
return difference
end
--------------------------------------------------------
commandArray = {}
Smart = tonumber(uservariables['Smart'])
if Smart == 0 then --zero means smart system should be inactive
return commandArray
end
crtoggle = tonumber(uservariables['crtoggle']) --a parameter
if devicechanged['fan1'] == 'On' then
commandArray['circule1'] = 'Off'
elseif otherdevices['fan1'] == 'Off' then
if timedifference(otherdevices_lastupdate['fan1']) > 1200 then
if otherdevices['circule1'] == 'On' then
if crtoggle == 5 then
commandArray['circule1'] = 'Off'
crtoggle = 0
end
crtoggle = crtoggle + 1
else
if crtoggle == 15 then
commandArray['circule1'] = 'On'
crtoggle = 0
end
crtoggle = crtoggle + 1
end
end
end
commandArray['Variable:crtoggle'] = tostring(crtoggle)
return commandArray