Gets gas consumption from the electrical energy of the gas boiler
Posted: Saturday 21 February 2026 12:25
Hi,
Below I will explain how I managed to obtain an approximate daily gas consumption by transforming the electrical energy consumed by the gas boiler.
The boiler is monitored by a smart plug and I created a custom sensor in domoticz that records daily gas consumption.
To be able to obtain an approximate gas consumption, you must first monitor the consumption on the gas meter for a day. Similarly, you monitor the energy consumption in Kw for that day.
Daily Gas consumption = Daily energy consumption of the gas boiler (in Kilowatt) x Multiplier
Calculate daily consumption smart plug (counterToday in domoticz) x Multiplier, for example in my case the multiplier value is 21 to obtain the approximate gas consumption, but you can also test with other values until it gives the correct result.
Then create the following dzvents script:
I hope it helps you too.
Below I will explain how I managed to obtain an approximate daily gas consumption by transforming the electrical energy consumed by the gas boiler.
The boiler is monitored by a smart plug and I created a custom sensor in domoticz that records daily gas consumption.
To be able to obtain an approximate gas consumption, you must first monitor the consumption on the gas meter for a day. Similarly, you monitor the energy consumption in Kw for that day.
Daily Gas consumption = Daily energy consumption of the gas boiler (in Kilowatt) x Multiplier
Calculate daily consumption smart plug (counterToday in domoticz) x Multiplier, for example in my case the multiplier value is 21 to obtain the approximate gas consumption, but you can also test with other values until it gives the correct result.
Then create the following dzvents script:
Code: Select all
return {
active = true,
on = {
devices = { 139 } -- idx smart plug
},
execute = function(domoticz, device)
-----------------------------------------------------
-- CONFIGURATION
-----------------------------------------------------
local MULTIPLICATOR = 21 -- multiplier replace with your own value
local GAZ_IDX = 520 -- 🟢 replace with the idx of your sensor Custom Sensor "Estimated Gas Consumption"
--------------------------------------------------------------------
-- MAIN LOGIC
--------------------------------------------------------------------
local val = device.counterToday or 0
local consumKWh = 0
if type(val) == "string" then
consumKWh = tonumber(val:match("([%d%.]+)")) or 0
else
consumKWh = tonumber(val) or 0
end
local consumGaz = consumKWh * MULTIPLICATOR
local gazDevice = domoticz.devices(GAZ_IDX)
if gazDevice then
gazDevice.updateCustomSensor(consumGaz)
domoticz.log(string.format(
"idx[%d]: %.3f kWh → Gas estimated: %.3f m³ (x%.3f)",
device.id, consumKWh, consumGaz, MULTIPLICATOR
), domoticz.LOG_INFO)
else
domoticz.log(string.format("Error: we did not find the device with idx %d", GAZ_IDX), domoticz.LOG_ERROR)
end
end
}