Howto set selector switch by dzvents. [Solved]
Posted: Thursday 25 July 2019 13:38
It is about heating and cooling.
I have some scripts dealing with heating and cooling.
For each room exists a selector switch actually is set by time control. Times are set for heating only.
There is also a switch (WP) switching between heating, cooling and off.
I would like to have times set by script depending on state of WP, so two different sets for heating and cooling
Here is one of my sripts:
If somebody thinks this script could be more elegant, help is appreciated
I have some scripts dealing with heating and cooling.
For each room exists a selector switch actually is set by time control. Times are set for heating only.
There is also a switch (WP) switching between heating, cooling and off.
I would like to have times set by script depending on state of WP, so two different sets for heating and cooling
Here is one of my sripts:
Code: Select all
-- assumptions:
-- the setpoint is set by a selector dummy device where the values are numeric temperatures
-- but you can easily change it to a setpoint device
local BOILER_DEVICE = 'FB 21 Heizkreis Salon' -- switch device
local SETPOINT_DEVICE = 'Solltemperatur Salon' -- selector dummy device
local TEMPERATURE_SENSOR = 'Salon'
local CHANGE_DEVICE = 'Modus Waermepumpe' -- selector dummy device
local HEATPUMP_RETURN = 'WP Ruecklauf' -- controls dewpoint of walls
local SMOOTH_FACTOR = 3
local LOGGING = true
return {
on = {
timer = {
'every minute',
},
devices = {
TEMPERATURE_SENSOR,
SETPOINT_DEVICE,
CHANGE_DEVICE
}
},
data = {
temperatureReadings = { history = true, maxItems = SMOOTH_FACTOR }
},
--logging = {
--level = domoticz.LOG_DEBUG,
--marker = "Hey wz"
--},
active = true,
execute = function(domoticz, device, triggerInfo)
local avgTemp
local temperatureReadings = domoticz.data.temperatureReadings
local sensor = domoticz.devices(TEMPERATURE_SENSOR)
local current = sensor.temperature
local boiler = domoticz.devices(BOILER_DEVICE)
local setpoint = domoticz.devices(SETPOINT_DEVICE)
local change = domoticz.devices(CHANGE_DEVICE)
local sensor_HP = domoticz.devices(HEATPUMP_RETURN)
local returnT = sensor_HP.temperature
local dewpoint = sensor.dewPoint
-- first check if the sensor got a new reading or the setpoint was changed:
if (triggerInfo.type == domoticz.EVENT_TYPE_DEVICE) then
if (sensor.changed) then
-- sensor just reported a new reading
-- add it to the readings table
if (current ~= 0 and current ~= nil) then
temperatureReadings.add(current)
else
-- no need to be here, weird state detected
domoticz.log('Strange sensor reading.. skiping', domoticz.LOG_ERROR)
return
end
if (domoticz.devices(SETPOINT_DEVICE).changed) then
-- a new setpoint was set
if LOGGING then domoticz.log('Setpoint was set to ' .. setpoint.state, domoticz.LOG_DEBUG) end
end
if (domoticz.devices(CHANGE_DEVICE).changed) then
-- a new Modus was set
if LOGGING then domoticz.log('Modus was set to ' .. change.state, domoticz.LOG_DEBUG) end
end
-- now determine what to do
if (setpoint.state == nil) or (setpoint.state == 'Off') or (change.state == nil) or (change.state == 'Off') then
if LOGGING then domoticz.log('Modus or Setpoint was set off', domoticz.LOG_DEBUG) end
boiler.switchOff()
return -- we're done here
end
local setpointValue = tonumber(setpoint.state)
-- determine at which temperature the boiler should be
-- switched on
-- don't use the current reading but average it out over
-- the past <SMOOTH_FACTOR> readings (data smoothing) to get rid of noise, wrong readings etc
local avgTemp = temperatureReadings.avg(1, SMOOTH_FACTOR, current) -- fallback to current when history is empty
if LOGGING then
domoticz.log('Average: ' .. avgTemp, domoticz.LOG_DEBUG)
domoticz.log('Setpoint: ' .. setpointValue, domoticz.LOG_DEBUG)
domoticz.log('Current boiler state: ' .. boiler.state, domoticz.LOG_DEBUG)
end
if (change.state == 'Heizen') then
if (avgTemp >= setpointValue and boiler.state == 'On') then
if LOGGING then domoticz.log('Target temperature reached, boiler off', domoticz.LOG_DEBUG) end
boiler.switchOff()
elseif (avgTemp < setpointValue and boiler.state == 'Off') then
if LOGGING then domoticz.log('Temperature to low, boiler On', domoticz.LOG_DEBUG) end
boiler.switchOn()
end
elseif (change.state == 'Kuehlen') then
if ((avgTemp <= dewpoint or returnT < (dewpoint - 2)) and boiler.state == 'On') then
if LOGGING then domoticz.log('Target temperature reached, boiler off', domoticz.LOG_DEBUG) end
boiler.switchOff()
elseif (returnT > dewpoint and avgTemp > setpointValue and boiler.state == 'Off') then
if LOGGING then domoticz.log('Target temperature not yet reached, boiler on', domoticz.LOG_DEBUG) end
boiler.switchOn()
else
return
end
end
end
end
end
}