Page 3 of 3

Re: Rain counter

Posted: Friday 19 August 2022 13:47
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

Re: Rain counter

Posted: Friday 19 August 2022 23:09
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.

Re: Rain counter

Posted: Saturday 20 August 2022 9:24
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?

Re: Rain counter

Posted: Monday 22 August 2022 8:52
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
}

Re: Rain counter

Posted: Monday 22 August 2022 9:38
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.

Re: Rain counter

Posted: Monday 22 August 2022 18:17
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:/

Re: Rain counter

Posted: Saturday 25 February 2023 8:49
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
}

Re: Rain counter

Posted: Tuesday 26 September 2023 21:14
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

Re: Rain counter

Posted: Tuesday 26 September 2023 23:12
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

Re: Rain counter

Posted: Wednesday 27 September 2023 17:30
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')

Re: Rain counter

Posted: Wednesday 27 September 2023 18:34
by waltervl
What happens if you uncomment the log statements (remove the -- before domoticz.log )?
Do you have the security settings right?

Re: Rain counter

Posted: Wednesday 27 September 2023 20:24
by ssk17051980
so, i made another sensor, like in the foto.
i have data now, but they are not to good.

Re: Rain counter

Posted: Sunday 01 October 2023 18:27
by ssk17051980
and a second problem. i receive "time out" from the rain sensor.