create a custom dummy sensor in my case "1452"
substitute with the correct sensor numbers.
Code: Select all
----------------
return {
on = {
devices = {
10, -- Gas Daily Counter
758, -- Outside Temp
122, -- Room Temp
577, -- room CV setpoint
123 -- CH Water feed temp
}
},
logging = {
level = domoticz.LOG_INFO,
marker = "HEATING_CORRELATION"
},
data = {
lastGasReading = { initial = 0 }
},
execute = function(dz, device)
-- Indices
local IDX_GAS = 10
local IDX_OUTSIDE = 758
local IDX_SETPOINT = 577
local IDX_WATER_SET = 123 -- Change to your CH Water Setpoint IDX
local IDX_VIRTUAL = 1452 -- Your Virtual Custom Sensor IDX
-- Fetch Devices
local gasDevice = dz.devices(IDX_GAS)
local outTemp = dz.devices(IDX_OUTSIDE).temperature
local roomSetpoint = dz.devices(IDX_SETPOINT).setPoint
local waterSet = dz.devices(IDX_WATER_SET).setPoint or dz.devices(IDX_WATER_SET).sValue
local effSensor = dz.devices(IDX_VIRTUAL)
-- 1. Handle Gas Usage (Daily Counter Reset Logic)
local currentReading = gasDevice.counter
local gasDelta = 0
if (dz.data.lastGasReading > 0) then
if (currentReading >= dz.data.lastGasReading) then
gasDelta = currentReading - dz.data.lastGasReading
else
gasDelta = currentReading -- Midnight reset
end
end
dz.data.lastGasReading = currentReading
-- 2. Calculate "Target Delta"
local targetDelta = roomSetpoint - outTemp
-- 3. Update if there is heating demand
if (targetDelta > 0) then
if (gasDelta > 0) then
-- Formula: Gas used / Temperature difference
local efficiencyIndex = dz.utils.round((gasDelta / targetDelta), 5)
effSensor.updateCustomSensor(efficiencyIndex)
-- Log the correlation including the Boiler Water Setpoint
dz.log('--- Heating Logic Triggered by: ' .. device.name .. ' ---', dz.LOG_INFO)
dz.log('CH Water Setpoint: ' .. waterSet .. '°C', dz.LOG_INFO)
dz.log('Gas Increment: ' .. gasDelta .. ' m3', dz.LOG_INFO)
dz.log('Thermal Load: ' .. efficiencyIndex, dz.LOG_INFO)
end
else
-- No demand (Outside is warmer than inside setpoint)
if (effSensor.sensorValue ~= "0") then
effSensor.updateCustomSensor(0)
end
end
end
}