Page 1 of 1
Turning the relay on depends on the temperature
Posted: Wednesday 02 January 2019 12:33
by Skydesign
Hello.
I am asking you for help in transferring the code from arduino to Domoticz, for example dzVents.
Part of the code:
void loop() {
... temperature reading
if (temp<20) flag20 = true; //if it drops below 20 then it remembers this fact
if (temp>40) flag20 = false; //if it has grown above 40 it will delete
//if it is currently in the range of 20..40 and it was <20 it turns on the output
if (temp>20 && flag20 == true) {
output1 = high; //-- wlacz
} else {
output1 = low; //-- wylacz
}
The idea is to turn on the relay when the sensor reading, eg temperature, is in the range from 20 to 40 but only when the temperature rises from 20 to 40, when the temperature reaches above 40 it is to turn off and turn on when it drops below 20.
Re: Turning the relay on depends on the temperature
Posted: Wednesday 02 January 2019 13:00
by waaren
Skydesign wrote: ↑Wednesday 02 January 2019 12:33
Hello.
I am asking you for help in transferring the code from arduino to Domoticz, for example dzVents.
Part of the code:
void loop() {
... temperature reading
if (temp<20) flag20 = true; //if it drops below 20 then it remembers this fact
if (temp>40) flag20 = false; //if it has grown above 40 it will delete
//if it is currently in the range of 20..40 and it was <20 it turns on the output
if (temp>20 && flag20 == true) {
output1 = high; //-- wlacz
} else {
output1 = low; //-- wylacz
}
The idea is to turn on the relay when the sensor reading, eg temperature, is in the range from 20 to 40 but only when the temperature rises from 20 to 40, when the temperature reaches above 40 it is to turn off and turn on when it drops below 20.
What are the relevant (temperature sensor and output switch) device names, types and subtypes as shown on the domoticz devices tab ?
Re: Turning the relay on depends on the temperature
Posted: Wednesday 02 January 2019 14:11
by Skydesign
waaren wrote: ↑Wednesday 02 January 2019 13:00
What are the relevant (temperature sensor and output switch) device names, types and subtypes as shown on the domoticz devices tab ?
Temperature sensor DS18B20 in Domoticz: name "T1", type "Temp" and subtypes "LaCrosse TX3"
For the relay: name "S1", type "Light / Switch" and subtypes "Switch"
Re: Turning the relay on depends on the temperature
Posted: Thursday 03 January 2019 14:36
by waaren
Skydesign wrote: ↑Wednesday 02 January 2019 14:11
waaren wrote: ↑Wednesday 02 January 2019 13:00
What are the relevant (temperature sensor and output switch) device names, types and subtypes as shown on the domoticz devices tab ?
Temperature sensor DS18B20 in Domoticz: name "T1", type "Temp" and subtypes "LaCrosse TX3"
For the relay: name "S1", type "Light / Switch" and subtypes "Switch"
Can you please test this dzVents script and report your findings ?
Thx.
Code: Select all
-- Temp control
return {
on = {
timer = { "every minute" },
},
logging = {
level = domoticz.LOG_ERROR,
marker = "Temp control"
},
data = {
outsideRange = { initial = 30 },
},
execute = function(dz)
local temperature = dz.devices("T1").temperature
local switch = dz.devices("S1")
local switchIsOff = switch.state == "Off"
local lowerTemperature = 20
local higherTemperature = 40
local comingFromLower = dz.data.outsideRange < lowerTemperature
local temperatureInRange = temperature > lowerTemperature and temperature < higherTemperature
if not temperatureInRange then
dz.data.outsideRange = temperature
end
if switchIsOff and ( temperature < lowerTemperature or ( temperatureInRange and comingFromLower )) then
switch.switchOn()
elseif temperature > higherTemperature and not switchIsOff then
switch.switchOff()
end
end
}
Re: Turning the relay on depends on the temperature
Posted: Thursday 03 January 2019 19:08
by Skydesign
waaren wrote: ↑Thursday 03 January 2019 14:36
Can you please test this dzVents script and report your findings ?
Thx.
Thank you for your work.
I have a problem:
At the beginning I have switch S1 off Temp T1=19 increases to T=22 then S1 changes state to ON the temperature increases to T1=41 and S1 changes to off. It's OK. Then the temperature drops to T1=39, S1 is still off, that's good, but when the temperature goes down and T1=19, S1 changes to ON and that's not good.
Switch S1 should stay in OFF and change state to ON when the temperature rises above 20.
How to solve this problem?
Re: Turning the relay on depends on the temperature
Posted: Thursday 03 January 2019 21:12
by waaren
Hope I understood you correctly this time.
Code: Select all
-- Temp control
return {
on = {
timer = { "every minute" },
},
logging = {
level = domoticz.LOG_ERROR,
marker = "Temp control"
},
data = {
lowTemperature = { initial = true },
},
execute = function(dz)
local temperature = dz.devices("T1").temperature
local switch = dz.devices("S1")
local switchIsOff = switch.state == "Off"
local lowerTemperature = 20
local higherTemperature = 40
local comingFromLow = dz.data.lowTemperature
local temperatureInRange = temperature > lowerTemperature and temperature < higherTemperature
dz.data.lowTemperature = temperature < lowerTemperature -- remember coming from low
if switchIsOff and temperatureInRange and comingFromLow then -- between 20-40 and coming from < 20 ==>> switchOn
switch.switchOn()
elseif not temperatureInRange and not switchIsOff then -- > 40 or < 20 switchOff
switch.switchOff()
if temperature > higherTemperature then -- No longer coming from low
dz.data.lowTemperature = false
end
end
end
}
Re: Turning the relay on depends on the temperature
Posted: Thursday 03 January 2019 21:49
by Skydesign
waaren wrote: ↑Thursday 03 January 2019 21:12
Hope I understood you correctly this time.
Thank you very much, it works great.