Due to a massive waterleak in our stables I'm trying to figure out a proper way to avoid this in the future.
I just installed 'Watermeter Gateway' : a wifi device which 'sticks' on the watermeter and counts the pulses.
After some fiddling I got this working
I would like to get a notification( Pushover and email) when the water usage is above , say 8 liters/minute.
There is a virtual sensor in Domoticz which shows liters/min. Thats nice, so this virtual sensor could send a notification.
I tried this in blockly as I am a total noob in programming. Blockly is lacking some essential 'blocks' imo. I couldnt find a way to
get in working.
Oh well, ChatGPT to the resque : I asked to write a script which shows waterusage in l/min with Virtual sensor "waterverbruik"
(I created this sensor) with data from "Watermeter Value". This sensor gets data every 10 seconds and starts counting at 0:00 each day and resets after 24h.
However this didnt work either, the log shows an error in line 2 :
2024-12-21 14:15:00.771 Error: EventSystem: in lua-testwater: [string "-- Verkrijg de huidige waarde van de watermet..."]:2: attempt to index a nil value (global 'domoticz')
And tips/advice how to get this done? I'm clueless how to get this working
Code: Select all
-- Verkrijg de huidige waarde van de watermeter sensor
local watermeter = tonumber(domoticz.devices['Watermeter Value'].state)
-- Verkrijg de tijd van de vorige meting (bijvoorbeeld in een bestand of variabele)
local previous_time = tonumber(domoticz.variables['previous_time'].value) -- of een andere methode om de tijd bij te houden
local previous_value = tonumber(domoticz.variables['previous_value'].value)
-- Bereken het verschil in tijd (bijvoorbeeld in minuten)
local current_time = os.time()
local elapsed_time = (current_time - previous_time) / 60 -- tijd in minuten
-- Bereken het verschil in waarde van de watermeter
local delta_value = watermeter - previous_value
-- Bereken het waterverbruik per minuut
local consumption_per_minute = delta_value / elapsed_time
-- Update de virtuele sensor voor liters per minuut
domoticz.devices['Watermeter per Minute'].updateConsumption(consumption_per_minute)
-- Sla de huidige waarde en tijd op voor de volgende meting
domoticz.variables['previous_time'].set(current_time)
domoticz.variables['previous_value'].set(watermeter)