Rain counter

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

User avatar
JackD
Posts: 68
Joined: Monday 02 November 2020 20:53
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Rain counter

Post by JackD »

Just looking at your log, a quick remark.
rainrate 81000.0 mm/hr....? and 0.45mm/m2 total today?

should that not be the other way round.... rainrate 0.45mm/hr and total 81000.mm/m2 in total today
But a daycount of 81000 is impossible unless you put your rainmeter under a waterfall :-)

Good luck with your quest on solving this.

Regards,
Jack
Peter83
Posts: 24
Joined: Sunday 31 July 2022 13:27
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Rain counter

Post by Peter83 »

hey
no it should be right, as rainrate is not 81000mm/hr its 810mm/hr wich means, that i used the switch manualy every second second. Or its 1620mm/hr using switch every second.

But yes, it would also be nice to have something like a blockage for like 5 seconds. I know you can set it up in Tasmota but i do now want it to work too much since its ment to work on battery.
So if you have an advice to change skrit so its working at maximum every 5 seconds i would like to know it :)

im still clueless with rainTotal not growing.
Peter83
Posts: 24
Joined: Sunday 31 July 2022 13:27
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Rain counter

Post by Peter83 »

So i set up a Wemos d1 yesterday with Tasmota and used the same skript with new virtual devices.
It was working perfektly yesterday but today its adding randomly numbers again.
No its not random its 3,9mm witch was yesterdays rainTotal in the end.

so maybe i have to reset activly at 0:00 again or still unnecessary?
Peter83
Posts: 24
Joined: Sunday 31 July 2022 13:27
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Rain counter

Post by Peter83 »

so this is the same problem, 3 people mentionen before. But i cant find a proper solution.

Changed skript to below and resettet at 00:01. Now it added -129 first time and its staying a 0 from now on.

Is it, because trigger is reset at 00:01 and has to be at 0:00? Or is there another way working?

Code: Select all

return 
{
    on = 
    {
        timer = 
        {
            "at 00:01" 
        },
        devices = 
        {
            "WippeOhlau"
        },
    },   

    logging = 
    {
        level = domoticz.LOG_DEBUG,            -- INFO, ERROR or DEBUG
        marker = "ESP test",
    }, 

    execute = function(dz, item, trigger)
               
        local rainDevice = dz.devices("RegenOhlau")               -- Your (virtual) rain device
        local rainSwitch = dz.devices("WippeOhlau")        -- Your (triggered by bucket full) switch 
        local rainmm = 45                                          -- find out what 1 bucket full means in terms of mm 
        local rainTotal = 0
        local timeSlice = math.min( (rainDevice.lastUpdate.secondsAgo / 3600), 10) -- at least 1 bucket  in 10 hours   
        
        local rainAmountHour = dz.utils.round((rainmm / timeSlice),1)
        
        if
            trigger.isTimer then 
            rainDevice.updateRain(dz.utils.round(rainDevice.rainRate,0),0)                     -- reset rainTotal
            rainSwitch.switchOff().silent()
            dz.log("Reset raintotal to 0",dz.log_DEBUG)
            
        elseif item.active then
            rainTotal = dz.utils.round(((rainmm / 100) + rainDevice.rain),2) 
            rainDevice.updateRain(rainAmountHour, rainTotal)
            dz.log("One bucket full ==>> updating raindevice. rainrate: " .. rainAmountHour .. " mm/hr, " .. rainTotal .." mm in total today ", dz.LOG_DEBUG )
            dz.log("Old value raindevice.rain: " .. rainDevice.rain .." mm in total today ", dz.LOG_DEBUG )
            rainSwitch.switchOff().silent()
        end
    end
}
Attachments
Unbenannt.png
Unbenannt.png (54.96 KiB) Viewed 1562 times
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Rain counter

Post by waltervl »

I think you should not have to reset the rainTotal value at night as it should be a normal counter (like your electricity counter at home). So Domoticz should calculate the daily values for you.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Peter83
Posts: 24
Joined: Sunday 31 July 2022 13:27
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Rain counter

Post by Peter83 »

ok, but how can i work arround this than?:
waaren wrote: Monday 31 August 2020 18:44 The value shown on the title row of a rain device shows the latest send value minus the first value of today. So if you have send the same value it will show 0.
I wonder if one has solved this befor, since i wont find any answer to this:/
User avatar
gizmocuz
Posts: 2350
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

Re: Rain counter

Post by gizmocuz »

For anyone finding this thread:

device.rain provides the actual rain of today (not the counter)

to get the counter, you have to retrieve this from the sValue of the device with

Code: Select all

    		local f_rainValTable = domoticz.utils.stringSplit(rain_sensor.sValue,';')
    		local actual_rain = f_rainValTable[2]
(First value is rain-rate, second value is the counter value)

A complete dzVents example which increments the counter via a door-sensor is provided below:

Code: Select all

return {
	on = {
		devices = {
			'RegenSensorSwitch'
		}
	},
	logging = {
		level = domoticz.LOG_INFO,
		marker = 'rain-zigbee',
	},
	execute = function(domoticz, device)
		--domoticz.log('Device ' .. device.name .. ' was changed: ' .. device.state, domoticz.LOG_INFO)
		if (device.state == 'Closed') then
    		local rain_sensor = domoticz.devices("RainZigbee")
    		
    		local f_rainValTable = domoticz.utils.stringSplit(rain_sensor.sValue,';')
    		local actual_rain = f_rainValTable[2]
    		--domoticz.log('total rain: ' .. actual_rain, domoticz.LOG_INFO)
    		
    		local rain2add = 0.30303
    		local new_rain = domoticz.utils.round((rain2add + actual_rain),2) 
    		--domoticz.log('new_rain: ' .. new_rain, domoticz.LOG_INFO)
            rain_sensor.updateRain(0, new_rain)
		end
	end
}
Quality outlives Quantity!
ssk17051980
Posts: 112
Joined: Thursday 08 December 2022 22:15
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: ROMANIA
Contact:

Re: Rain counter

Post by ssk17051980 »

hello,

need some help,


so I created an open/closed switch. he confirms to me that the sensor in the rain gauge works and changes its state. dummy name is "rain-zigbee"

i created a custom counter type sensor, called "RegenSensorSwitch" that expresses the quantity in liters/square meter

at the end in setup/events I created a new dzvents script and pasted the above script . however, in the log it appears that the script is being created, but then nothing about couter named RegenSensorSwitch

Version: 2023.2
Build Hash: 19efd039c
Compile Date: 2023-07-21 18:23:44
dzVents Version: 3.1.8
Python Version: 3.7.3 (default, Oct 31 2022, 14:04:00) [GCC 8.3.0]



any help ?
thx
Attachments
dz.vents.jpg
dz.vents.jpg (20.75 KiB) Viewed 1282 times
switch.rain.jpg
switch.rain.jpg (38.56 KiB) Viewed 1282 times
precipitatii.jpg
precipitatii.jpg (51.97 KiB) Viewed 1282 times
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Rain counter

Post by waltervl »

It is all in the details. For the script above the devices needed are:

Rain sensor name should be RainZigbee and not rain-zigbee
The dummy switch name should be RegenSensorSwitch
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
ssk17051980
Posts: 112
Joined: Thursday 08 December 2022 22:15
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: ROMANIA
Contact:

Re: Rain counter

Post by ssk17051980 »

now the problem is this :
2023-09-27 18:27:20.934 Error: dzVents: Error: (3.1.8) rain-zigbee: An error occurred when calling event handler Precipitatii
2023-09-27 18:27:20.934 Error: dzVents: Error: (3.1.8) rain-zigbee: ...oticz/scripts/dzVents/generated_scripts/Precipitatii.lua:21: attempt to perform arithmetic on a nil value (local 'actual_rain')
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Rain counter

Post by waltervl »

What happens if you uncomment the log statements (remove the -- before domoticz.log )?
Do you have the security settings right?
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
ssk17051980
Posts: 112
Joined: Thursday 08 December 2022 22:15
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: ROMANIA
Contact:

Re: Rain counter

Post by ssk17051980 »

so, i made another sensor, like in the foto.
i have data now, but they are not to good.
Attachments
works.jpg
works.jpg (35.75 KiB) Viewed 1244 times
ssk17051980
Posts: 112
Joined: Thursday 08 December 2022 22:15
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: ROMANIA
Contact:

Re: Rain counter

Post by ssk17051980 »

and a second problem. i receive "time out" from the rain sensor.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest