Code: Select all
local BOILER_DEVICE = 'FB 21 Heizkreis Salon' -- switch device
local TEMPERATURE_SENSOR = 'Salon'
local RUECKLAUF_SENSOR = 'WP Ruecklauf'
local SMOOTH_FACTOR = 3
local LOGGING = true
return {
on = {
devices = {
TEMPERATURE_SENSOR,
RUECKLAUF_SENSOR,
},
timer = {
'every minute',
}
},
data = {
temperatureReadings = { history = true, maxItems = SMOOTH_FACTOR }
},
active = true,
execute = function(domoticz, device, triggerInfo)
local avgTemp
local temperatureReadings = domoticz.data.temperatureReadings
-- first check if the sensor got a new reading or the setpoint was changed:
if (triggerInfo.type == domoticz.EVENT_TYPE_DEVICE) then
local sensor = domoticz.devices(TEMPERATURE_SENSOR)
local ruecklauf = domoticz.devices(RUECKLAUF_SENSOR)
if (ruecklauf.changed) then
local ruecklaufT = ruecklauf.temperature
if (sensor.changed ) then
-- sensor just reported a new reading
-- add it to the readings table
local current = sensor.temperature
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
end
-- now determine what to do
local boiler = domoticz.devices(BOILER_DEVICE)
local dewpoint = sensor.dewpoint
-- 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)
if LOGGING then
domoticz.log('Average: ' .. avgTemp, domoticz.LOG_INFO)
domoticz.log('Current boiler state: ' .. boiler.state, domoticz.LOG_INFO)
end
if ((avgTemp <= dewpoint or ruecklaufT <= dewpoint) and boiler.state == 'On') then
if LOGGING then domoticz.log('Target temperature reached, boiler off') end
boiler.switchOff()
end
if ((avgTemp > dewpoint or ruecklaufT > dewpoint) and boiler.state == 'Off') then
if LOGGING then domoticz.log('Heating is required, boiler switched on') end
boiler.switchOn()
end
end
end
end
} So help is very much appreciated.