-- Temp control
local scriptVar = 'tempControl3'
return
{
on =
{
timer =
{
'every minute', -- domoticz events based on timers are triggered once a minute max.
},
customEvents = -- used to increase frequency to once every 30 seconds.
{
scriptVar,
}
},
logging = {
level = domoticz.LOG_DEBUG, -- If set to domoticz.LOG_ERROR you will only see something if dzVents encountered an error
-- So best to start with domoticz.LOG_DEBUG until your script works as expected.
marker = scriptVar,
},
data = {
lowTemperature = { initial = true },
},
execute = function(dz, item)
if item.isTimer then
dz.emitEvent(scriptVar).afterSec(30) -- this will trigger the customEvent in the On section and therewith increase the frequency to every 30 seconds
end
local insideTemperature = dz.devices('TempInside').temperature
local outsideTemperature = dz.devices('TempOutside').temperature
local stfan = dz.devices('FanIn')
local safan = dz.devices('FanOut') -- this second use of 'switch' as varname does overwrite the previous one.
local stfanIsOff = stfan.state == 'Off'
local safanIsOff = safan.state == 'Off'
local lowerTemperature = 25
local higherTemperature = 45
local comingFromLow = dz.data.lowTemperature
local temperatureInRange = insideTemperature > lowerTemperature and insideTemperature < higherTemperature
dz.data.lowTemperature = insideTemperature < lowerTemperature -- remember coming from low
if stfanIsOff and safanIsOff and temperatureInRange and comingFromLow then -- between 25-45 and coming from < 25 ==>> switchOn
if insideTemperature < outsideTemperature then stfan.switchOn()
elseif insideTemperature > outsideTemperature then safan.switchOn()
end
elseif not temperatureInRange then -- > 24 or < 20 switchOff
if not stfanIsOff or not safanIsOff then
safan.switchOff()
stfan.switchOff()
end
if insidetemperature > higherTemperature then -- No longer coming from low
dz.data.lowTemperature = false
end
end
end
}
After I manualy switch on fans and temperature(inside) falls below 25 degrees script can switch off, but there is no way to automaticaly switch them on after reaching 25 degrees
The setup is:
2 temperature sensors, and 2 fans ... the trick is that need to compare temperatures inside room and outside not to pump warmer air inside room in that case need to run fan pumping air from basement
rmacuda wrote: ↑Thursday 27 May 2021 19:00
I tried to adopt one of script to my purposes:
First: please do not crosspost. Crossposts will be deleted by a moderator.
If you need to debug a script a first step is always to look at log (and add some debug log statements when helpful)
Please try below script a couple of runs and share the produced loglines. Also explain what you expected to happen against what the script does (or does not)
-- Temp control
local scriptVar = 'tempControl3'
return
{
on =
{
timer =
{
'every minute', -- domoticz events based on timers are triggered once a minute max.
},
customEvents = -- used to increase frequency to once every 30 seconds.
{
scriptVar,
}
},
logging = {
level = domoticz.LOG_DEBUG, -- If set to domoticz.LOG_ERROR you will only see something if dzVents encountered an error
-- So best to start with domoticz.LOG_DEBUG until your script works as expected.
marker = scriptVar,
},
data = {
lowTemperature = { initial = true },
},
execute = function(dz, item)
if item.isTimer then
dz.emitEvent(scriptVar).afterSec(30) -- this will trigger the customEvent in the On section and therewith increase the frequency to every 30 seconds
end
dz.utils.dumpTable(dz.data)
local s = {}
s.insideTemperature = dz.devices('TempInside').temperature
s.outsideTemperature = dz.devices('TempOutside').temperature
local stfan = dz.devices('FanIn')
local safan = dz.devices('FanOut') -- this second use of 'switch' as varname does overwrite the previous one.
s.stfan = stfan.state
s.safan = safan.state
s.stfanIsOff = stfan.state == 'Off'
s.safanIsOff = safan.state == 'Off'
s.lowerTemperature = 25
s.higherTemperature = 45
s.comingFromLow = dz.data.lowTemperature
s.temperatureInRange = s.insideTemperature > s.lowerTemperature and s.insideTemperature < s.higherTemperature
dz.data.lowTemperature = s.insideTemperature < s.lowerTemperature -- remember coming from low
if s.stfanIsOff and s.safanIsOff and s.temperatureInRange and s.comingFromLow then -- between 25-45 and coming from < 25 ==>> switchOn
dz.log('------------ 1 ', dz.LOG_DEBUG)
if s.insideTemperature < s.outsideTemperature then
dz.log('------------ 2 ', dz.LOG_DEBUG)
stfan.switchOn()
elseif s.insideTemperature > s.outsideTemperature then
dz.log('------------ 3 ', dz.LOG_DEBUG)
safan.switchOn()
end
elseif not s.temperatureInRange then -- > 24 or < 20 switchOff
dz.log('------------ 4', dz.LOG_DEBUG)
if not s.stfanIsOff or not s.safanIsOff then
dz.log('------------ 5 ', dz.LOG_DEBUG)
safan.switchOff()
stfan.switchOff()
else
dz.log('------------ 6 ', dz.LOG_DEBUG)
end
else
dz.log('------------ 7 ', dz.LOG_DEBUG)
end
dz.utils.dumpTable(s)
dz.utils.dumpTable(dz.data)
end
}
waaren wrote: ↑Thursday 27 May 2021 20:27
If you need to debug a script a first step is always to look at log (and add some debug log statements when helpful)
Please try below script a couple of runs and share the produced loglines. Also explain what you expected to happen against what the script does (or does not)
Hi I've returned to somewhat my initial script and found that problem is in 'commingFromLow' logic .. in fact I also needed some hysteresis to avoid frequent on/offs near cut temperature so lets say:
I need to run one of fans when temperature reaches lest say 27 degrees but to avoid on/off actions beetween 26.9 and 27.1 degrees I needed to set offTemprature at 26 degrees. I also check if outside temperature is not higher than inside -then run InFan in other case i run OutFan.
So I tried this script and it is somehow working
-- Temp control
local scriptVar = 'tempControl3'
return
{
on =
{
timer =
{
'every minute', -- domoticz events based on timers are triggered once a minute max.
},
customEvents = -- used to increase frequency to once every 30 seconds.
{
scriptVar,
}
},
logging = {
level = domoticz.LOG_DEBUG, -- If set to domoticz.LOG_ERROR you will only see something if dzVents encountered an error
-- So best to start with domoticz.LOG_DEBUG until your script works as expected.
marker = scriptVar,
},
-- data = {
-- lowTemperature = { initial = true },
-- },
execute = function(dz, item)
if item.isTimer then
dz.emitEvent(scriptVar).afterSec(30) -- this will trigger the customEvent in the On section and therewith increase the frequency to every 30 seconds
end
local insideTemperature = dz.devices('TempInside').temperature
local outsideTemperature = dz.devices('TempOutside').temperature
local stfan = dz.devices('FanIn')
local safan = dz.devices('FanOut') -- this second use of 'switch' as varname does overwrite the previous one.
local stfanIsOff = stfan.state == 'Off'
local safanIsOff = safan.state == 'Off'
local onTemperature = 27
local offTemperature = 26
-- local comingFromLow = dz.data.lowTemperature
-- local Temperature = insideTemperature > lowerTemperature and insideTemperature < higherTemperature
-- dz.data.lowTemperature = insideTemperature < lowerTemperature -- remember coming from low
if insideTemperature > onTemperature then -- between 25-45 and coming from < 25 ==>> switchOn
if safanIsOff and insideTemperature < outsideTemperature then safan.switchOn()
elseif stfanIsOff and insideTemperature > outsideTemperature then stfan.switchOn()
end
elseif insideTemperature < offTemperature and ( not stfanIsOff or not safanIsOff ) then -- > 24 or < 20 switchOff
if not stfanIsOff then
stfan.switchOff()
end
if not safanIsOff then
safan.switchOff()
end
-- if insideTemperature > higherTemperature then -- No longer coming from low
-- dz.data.lowTemperature = false
-- end
end
end
}
This seems to work