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.
Turning the relay on depends on the temperature
Moderator: leecollings
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Turning the relay on depends on the temperature
What are the relevant (temperature sensor and output switch) device names, types and subtypes as shown on the domoticz devices tab ?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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 7
- Joined: Monday 31 December 2018 7:39
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Turning the relay on depends on the temperature
Temperature sensor DS18B20 in Domoticz: name "T1", type "Temp" and subtypes "LaCrosse TX3"
For the relay: name "S1", type "Light / Switch" and subtypes "Switch"
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Turning the relay on depends on the temperature
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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 7
- Joined: Monday 31 December 2018 7:39
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Turning the relay on depends on the temperature
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?
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Turning the relay on depends on the temperature
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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Who is online
Users browsing this forum: No registered users and 1 guest