local BOILER_DEVICE = 'Grzanie' -- przekaznik wykonawczy local SETPOINT_DEVICE = 'Termostat' -- Zadana temp Termostatu local TEMPERATURE_SENSOR = 'Temp' -- nazwa czujnika temperatury local HYSTERESIS = 0.3 -- histereza local SMOOTH_FACTOR = 4 -- ilosc danych do sredniej local LOGGING = true -- logi on , przy false logi off local MODE = 'Tryb' -- selektor z trybami pracy return { on = { timer = { 'every minute' },-- skrypt sie wykonuje co minute device = { TEMPERATURE_SENSOR, SETPOINT_DEVICE } }, data = { temperatureReadings = { history = true, maxItems = SMOOTH_FACTOR } }, active = true, execute = function(domoticz, device, triggerInfo) local avgTemp local temperatureReadings = domoticz.data.temperatureReadings local boiler = domoticz.devices(BOILER_DEVICE) local setpoint = domoticz.devices(SETPOINT_DEVICE) local mode = domoticz.devices(MODE) local sensor = domoticz.devices(TEMPERATURE_SENSOR) local current = sensor.temperature if (triggerInfo.type == domoticz.EVENT_TYPE_DEVICE) then if (sensor.changed) then if (current ~= 0 and current ~= nil) then temperatureReadings.add(current) else domoticz.log('Dziwny odczyt czujnika ... skakanie', domoticz.LOG_ERROR) return end elseif (domoticz.devices(SETPOINT_DEVICE).changed) then if LOGGING then domoticz.log('Nowe ustawienie Termostatu ' .. device.state) end else return end end if (setpoint.state == nil or setpoint.state == 'Off') then boiler.switchOff() return end local setpointValue = tonumber(setpoint.state) local switchOnTemp = setpointValue - HYSTERESIS local avgTemp = temperatureReadings.avg(1, SMOOTH_FACTOR, current) if LOGGING then domoticz.log('Średnia wyliczona temperatura: ' .. avgTemp, domoticz.LOG_INFO) domoticz.log('Wartość zadana: ' .. setpointValue, domoticz.LOG_INFO) domoticz.log('Aktualny stan ogrzewania: ' .. boiler.state, domoticz.LOG_INFO) domoticz.log('Temperatura włączenia: ' .. switchOnTemp, domoticz.LOG_INFO) end if (avgTemp >= setpointValue and boiler.state == 'On' and mode.state == 'Auto') then if LOGGING then domoticz.log('Osiągnięta temperatura docelowa, ogrzewanie off') end boiler.switchOff() boiler.switchOff().afterMin(2) end if (avgTemp < setpointValue and boiler.state == 'Off' and mode.state =='Auto') then if (avgTemp < switchOnTemp) then if LOGGING then domoticz.log('Temperatura jest za niska ogrzewanie on') end boiler.switchOn() boiler.switchOn().afterMin(2) else if LOGGING then domoticz.log('Średnia temperatura poniżej zadanej, ale w zakresie histerezy, w oczekiwaniu na spadek temperatury do ' .. switchOnTemp) end end end if (boiler.state == 'Off' and mode.state == 'Force') then if LOGGING then domoticz.log('Konieczność ciągłego grzania') end boiler.switchOn() boiler.switchOn().afterMin(2) end if (boiler.state == 'On' and mode.state == 'Stop') then if LOGGING then domoticz.log('Wymuszony koniec grzania') end boiler.switchOff() boiler.switchOff().afterMin(2) end end }