But, i keep getting this error no matter what i attempt to reference for the device value:
2026-08-16 18:14:00.473 Error: dzVents: An error occurred when calling event handler Water usage
2026-08-16 18:14:00.473 Error: dzVents: ...moticz/scripts/dzVents/generated_scripts/Water usage.lua:12: attempt to index a nil value (global 'device')
Here's the code i'm using:
Code: Select all
return {
on = {
timer = {
'every 1 minutes' -- This is your time trigger
},
devices = {
'Total water used' -- CHANGE THIS to your actual device name
}
},
execute = function(domoticz, timer)
-- 1. Get the current reading
local currentFlow = device.sensorValue -- Use .sensorValue, .flow, or .state depending on device type
-- 2. Retrieve the last saved reading
local lastFlow = domoticz.variables('LastValue').sensorValue
-- 3. Calculate the difference
local difference = currentFlow - lastFlow
-- 4. Log the results to the Domoticz log
domoticz.log('Current Flow: ' .. currentFlow .. ' L/m', domoticz.LOG_INFO)
domoticz.log('Previous Flow: ' .. lastFlow .. ' L/m', domoticz.LOG_INFO)
domoticz.log('Calculated Difference: ' .. difference .. ' L/m', domoticz.LOG_INFO)
-- 5. OPTIONAL: Update a dummy device with the difference
-- domoticz.devices('Flow Difference Device').updateCustomSensor(difference)
-- 6. Update the persistent variable for the next run
domoticz.variables('TotalValue').set = currentFlow
end
}223 MQTTmapper powerpi/SCMplus/71280747 1 Total water used General Custom Sensor 101119 Gal - - 2026-08-16 18:20:16
224 Virtual sensors 00082224 1 Water usage General Custom Sensor 0 Gal - - 2026-08-15 21:24:00
The actual water meter is being read via an usb SDR dongle on a RPI 3b running rtl_433 and using MQTT to pass the value to Domoticz thru the MQTTmapper.
Domoticz server:
OS: Raspberry PI OS Bookworm - fully updated
Domoticz : 2026.2
So, what am i doing incorrectly? I feel like i've tried every combination of value, curentvalue, counter, etc. and nothing seems to work.
Thanks,
Darryl