Page 2 of 3
Re: Rain counter
Posted: Wednesday 02 September 2020 18:58
by snellejellep
waaren wrote: ↑Monday 31 August 2020 22:35
I tested with below script (the reset at 0:00 is not needed as domoticz does that anyway without a script) and the upper right corner does display the total rain in mm
for today
BUT: if the lowest value of today in database table RAIN is > 0, the calculation in the script fails because the value of rain is
current number - lowest number of today in database table RAIN for this device
Code: Select all
return
{
on =
{
devices =
{
"tippingbucketrain",
},
},
logging =
{
level = domoticz.LOG_DEBUG, -- INFO, ERROR or DEBUG
marker = "ESP test",
},
execute = function(dz, item)
local rainDevice = dz.devices("Regenmeter") -- Your (virtual) rain device
local rainSwitch = dz.devices("tippingbucketrain") -- Your (triggered by bucket full) switch
local rainmm = 2 -- 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 item.active then
rainTotal = dz.utils.round((rainmm + rainDevice.rain),1)
rainDevice.updateRain(rainAmountHour, rainTotal)
dz.log("One bucket full ==>> updating raindevice. rainrate: " .. rainAmountHour .. " mm/hr, " .. rainTotal .." mm in total today ", dz.LOG_DEBUG )
rainSwitch.switchOff().silent()
end
end
}
thank you verry much! this works like a charm!
Re: Rain counter
Posted: Sunday 23 May 2021 20:59
by user12938
waaren wrote: ↑Monday 31 August 2020 22:35
snellejellep wrote: ↑Monday 31 August 2020 18:58
correct me if i am wrong but i thought that it would update the total rain in mm in the upper right corner
I tested with below script (the reset at 0:00 is not needed as domoticz does that anyway without a script) and the upper right corner does display the total rain in mm
for today
BUT: if the lowest value of today in database table RAIN is > 0, the calculation in the script fails because the value of rain is
current number - lowest number of today in database table RAIN for this device
Code: Select all
return
{
on =
{
devices =
{
"tippingbucketrain",
},
},
logging =
{
level = domoticz.LOG_DEBUG, -- INFO, ERROR or DEBUG
marker = "ESP test",
},
execute = function(dz, item)
local rainDevice = dz.devices("Regenmeter") -- Your (virtual) rain device
local rainSwitch = dz.devices("tippingbucketrain") -- Your (triggered by bucket full) switch
local rainmm = 2 -- 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 item.active then
rainTotal = dz.utils.round((rainmm + rainDevice.rain),1)
rainDevice.updateRain(rainAmountHour, rainTotal)
dz.log("One bucket full ==>> updating raindevice. rainrate: " .. rainAmountHour .. " mm/hr, " .. rainTotal .." mm in total today ", dz.LOG_DEBUG )
rainSwitch.switchOff().silent()
end
end
}
Great work on this script but I've got strange behaviour;
Version: 2021.1
When I set a full bucket to be 10mm it's calculating it correctly and sending the value to the rain device correctly. The returned rain amount is only +5mm...
And two days ago it was +7mm (10-3mm) and some more days ago it was +8mm.. (10-2mm) (Same script)
Really strange behaviour, who can shed a light on this one?
Some simple logging:
2021-05-23 20:37:44.202 Status: dzVents: Debug: ESP test: rainmm: 10 rainDevice.rain: 11 rainTotal1: 21
2021-05-23 20:39:43.778 Status: dzVents: Debug: ESP test: rainmm: 10 rainDevice.rain: 16 rainTotal1: 26
2021-05-23 20:40:23.288 Status: dzVents: Debug: ESP test: rainmm: 10 rainDevice.rain: 21 rainTotal1: 31
2021-05-23 20:45:02.129 Status: dzVents: Debug: ESP test: rainmm: 10 rainDevice.rain: 26 rainTotal1: 36
2021-05-23 20:47:05.785 Status: dzVents: Debug: ESP test: rainmm: 10 rainDevice.rain: 31 rainTotal: 41.0
2021-05-23 20:47:18.615 Status: dzVents: Debug: ESP test: rainmm: 10 rainDevice.rain: 36 rainTotal: 46.0
2021-05-23 20:47:26.526 Status: dzVents: Debug: ESP test: rainmm: 10 rainDevice.rain: 41 rainTotal: 51.0
2021-05-23 20:52:53.710 Status: dzVents: Debug: ESP test: rainmm: 10 rainDevice.rain: 46 rainTotal: 56.0
2021-05-23 20:56:43.113 Status: dzVents: Debug: ESP test: rainmm: 10 rainDevice.rain: 51 rainTotal: 61.0
First line: 41mm is sent to the device, second line 36 is returned.
There 5 min interval value which is stored in the database is the second to last value, 56mm, but in the last line 51 is returned...
Complete script:
Code: Select all
return
{
on =
{
devices =
{
'Zigbee2MQTT - RainSwitch (contact)', 'tippingbucketrain'
},
},
logging =
{
level = domoticz.LOG_DEBUG, -- INFO, ERROR or DEBUG
marker = "ESP test",
},
execute = function(dz, item)
local rainDevice = dz.devices('Regenmeter') -- Your (virtual) rain device
local rainSwitch = dz.devices('Zigbee2MQTT - RainSwitch (contact)') -- Your (triggered by bucket full) switch
local rainmm = 10 -- 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 item.active then
rainTotal = dz.utils.round((rainmm + rainDevice.rain),1)
dz.log("Old rain: " .. rainDevice.rain, dz.LOG_DEBUG )
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("rainmm: " .. rainmm .. " rainDevice.rain: " .. rainDevice.rain .. " rainTotal: " ..rainTotal, dz.LOG_DEBUG )
rainSwitch.switchOff().silent()
end
end
}
Re: Rain counter
Posted: Monday 24 May 2021 10:53
by user12938
And today it's even stranger
Code: Select all
2021-05-24 10:49:46.026 Status: dzVents: Debug: ESP test: rainmm: 10 rainDevice.rain: 56 rainTotal: 66.0
2021-05-24 10:50:03.336 Status: dzVents: Debug: ESP test: rainmm: 10 rainDevice.rain: 0 rainTotal: 10.0
2021-05-24 10:50:28.392 Status: dzVents: Debug: ESP test: rainmm: 10 rainDevice.rain: -56 rainTotal: -46.0
2021-05-24 10:50:43.040 Status: dzVents: Debug: ESP test: rainmm: 10 rainDevice.rain: -112 rainTotal: -102.0
2021-05-24 10:51:31.833 Status: dzVents: Debug: ESP test: rainmm: 10 rainDevice.rain: -168 rainTotal: -158.0
Edit:
As stated before, it has something to do with the begin value of the rainmeter on that day. That explains the difference in 2, 3 or 5mm difference I think. What should happen in Domoticz? Is there a whitepaper or API description for it? It appears to me my rainmeter isn't resetting at midnight. According to the database it isn't. Local timezone on the RPI is setup correctly. (Europe/Amsterdam)
Re: Rain counter
Posted: Sunday 14 August 2022 10:43
by Peter83
Hi,
so i used above shown script:
return
{
on =
{
devices =
{
"Regen1",
},
},
logging =
{
level = domoticz.LOG_DEBUG, -- INFO, ERROR or DEBUG
marker = "ESP test",
},
execute = function(dz, item)
local rainDevice = dz.devices("Regen test") -- Your (virtual) rain device
local rainSwitch = dz.devices("Regen1") -- Your (triggered by bucket full) switch
local rainmm = 0.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 item.active then
rainTotal = dz.utils.round((rainmm + rainDevice.rain),1)
rainDevice.updateRain(rainAmountHour, rainTotal)
dz.log("One bucket full ==>> updating raindevice. rainrate: " .. rainAmountHour .. " mm/hr, " .. rainTotal .." mm in total today ", dz.LOG_DEBUG )
rainSwitch.switchOff().silent()
end
end
}
Regen1 is my hardware name (Dummy)
Regen test is virtual sensors name
so letting this skript run it says:
2022-08-14 10:37:12.810 Status: Warning: Expecting svalue with at least 2 elements separated by semicolon, 1 elements received ("11"), notification not sent (Hardware: 9 - Regen1, ID: 82018, Unit: 1, Type: 55 - Rain, SubType: 3 - TFA)
"11" is the number of counts made by the swith today
so what am i missing??
Re: Rain counter
Posted: Sunday 14 August 2022 12:21
by waltervl
The devicet needs 2 values, rainAmountHour and Raintotal. So it looks like you do not send Raintotal. What does the log entry say?
Perhaps move the log line just above the rain device.updaterain line so you first get the log and the the error due to incorrect update.
Re: Rain counter
Posted: Sunday 14 August 2022 14:49
by Peter83
changing did not help.
so i do just have one Counter (Tasmoata device) wich sends a simple number zu the virtual device. Counter sends 11 counts per example.
So the virtual device is chosen as Rain device.
i thought that the scrip calculates the two variable rainrate and amount/day.
Do i have to change anything in the line:
dz.log("One bucket full ==>> updating raindevice. rainrate: " .. rainAmountHour .. " mm/hr, " .. rainTotal .." mm in total today ", dz.LOG_DEBUG )
or put something in here?
wich log do you ask for?
Re: Rain counter
Posted: Sunday 14 August 2022 19:55
by Peter83
so heres a photo of the devices i have.
The counter device (-- Your (triggered by bucket full) switch) is having 0, 30 for values. 30 is the counter auf the Tasmota device
other raindevices have 0;0 though. ("regen3" is my "-- Your (virtual) rain device" now
Maybe its wrong choosing tasmota counter to virtual raindevice? But choosing virtual counter it doesnt work and chosing virtual switch its alway off..
Re: Rain counter
Posted: Monday 15 August 2022 9:32
by waltervl
I only was triggered on your error:
Code: Select all
Status: Warning: Expecting svalue with at least 2 elements separated by semicolon, 1 elements received ("11"), notification not sent (Hardware: 9 - Regen1, ID: 82018, Unit: 1, Type: 55 - Rain, SubType: 3 - TFA)
This means that Domoticz did not receive a proper update for the device and and Raintotal is empty.
So to debug change your current code
Code: Select all
rainDevice.updateRain(rainAmountHour, rainTotal)
dz.log("One bucket full ==>> updating raindevice. rainrate: " .. rainAmountHour .. " mm/hr, " .. rainTotal .." mm in total today ", dz.LOG_DEBUG )
To
Code: Select all
dz.log("One bucket full ==>> updating raindevice. rainrate: " .. rainAmountHour .. " mm/hr, " .. rainTotal .." mm in total today ", dz.LOG_DEBUG )
rainDevice.updateRain(rainAmountHour, rainTotal)
Now you would get first the log line in your domoticz log and then the error.
Expected log line (with other values of course):
"One bucket full ==>> updating raindevice. rainrate: 11 mm/hr, 10 mm in total today "
What dous it say in your case? Do you get bothe rainrate and raintotal?
Re: Rain counter
Posted: Monday 15 August 2022 12:21
by Peter83
thank you. ill check tonight.
so befor im trying - im really confused right now. What am i setting up for my raindevice an rainswitch?
two virtual raindevices, 1 counting, on showing actual rain and rainrate? or do i need a switch, going on an off as "rainswitch"?
Re: Rain counter
Posted: Monday 15 August 2022 13:10
by waltervl
Perhaps you better describe what you have for Tasmota hardware and how it is defined.
The script needs a (virtual) on/off switch that is triggered by the tasmota hardware as soon as the rainbucket is full and tipped over.
Then the script will fill the rainmeter sensor based on the volume/related mm of a full bucket and the delta time between each full bucket.
Re: Rain counter
Posted: Monday 15 August 2022 23:45
by Peter83
ok, so theres the problem
i do have a sonoff basic siwtch flashed with tasmota - chose a counter device to count than reed contact is working/bucket is tipping.
Changing it to a switch and setting up a virtual switch in domoticz the script works.
But one thing is not working (tried both ways with switched lines as well):
1bucket is 0,45mm. changing "2" to "0.45" its not adding 0,45, its adding -1,5..later adding 15 (switched lines -1,6) putting in 0,45 its adding -2.. or what ever ridiculous numbers..
Re: Rain counter
Posted: Tuesday 16 August 2022 8:52
by waltervl
That seems the same issue as somebody else already mentioned in this topic.....
According wiki it should be as below. DzVents is updating this accordingly.
Code: Select all
/json.htm?type=command¶m=udevice&idx=IDX&nvalue=0&svalue=RAINRATE;RAINCOUNTER
IDX = id of your device (This number can be found in the devices tab in the column "IDX")
RAINRATE = amount of rain in last hour in [mm x 100]
RAINCOUNTER = continues counter of fallen Rain in [mm]
Edit: So you have to send 0.45*100 = 45 when you want to send .45 mm/hr
Re: Rain counter
Posted: Tuesday 16 August 2022 21:20
by Peter83
sorry but where do i put this code?
i am really a beginner and this is more or less my first projekt after installing some temp sensors. so every step is kind of new to me.
just asking for beeing shure - is my skrip below complete or do i have to change some thins or lines or mm to xxxx??
Code: Select all
return
{
on =
{
devices =
{
"s1",
},
},
logging =
{
level = domoticz.LOG_DEBUG, -- INFO, ERROR or DEBUG
marker = "ESP test",
},
execute = function(dz, item)
local rainDevice = dz.devices("regen4") -- Your (virtual) rain device
local rainSwitch = dz.devices("s1") -- Your (triggered by bucket full) switch
local rainmm = 0.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 item.active then
rainTotal = dz.utils.round((rainmm + rainDevice.rain),1)
rainDevice.updateRain(rainAmountHour, rainTotal)
dz.log("One bucket full ==>> updating raindevice. rainrate: " .. rainAmountHour .. " mm/hr, " .. rainTotal .." mm in total today ", dz.LOG_DEBUG )
rainSwitch.switchOff().silent()
end
end
}
Re: Rain counter
Posted: Tuesday 16 August 2022 23:55
by waltervl
You should not put this code anywhere

It was a copy from the wiki documentation referring to what the values mean. And to help you understand what the script is doing.
I think you have to change line
local rainmm = 0.45
Into
local rainmm = 45
So that it values the mm*100 calculation. 45 means .45 mm per bucket.
Re: Rain counter
Posted: Wednesday 17 August 2022 0:31
by Peter83
ah ok, now i got it..
so typed in 45 and rainrate should be right now, since clicking every second, its showing 1620mm/hr
but then total rain was adding 45mm each time.
soo i changed this line deviding by 100:
Code: Select all
rainTotal = dz.utils.round((rainmm/100 + rainDevice.rain),1)
unfortunatly its rounding now adding 0.5 every time
(chaging script to this leads to the same result (rainrate is 1620 an rain total is addin .5 every time):
Code: Select all
local rainmm = 0.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*100 / timeSlice),1)
i need one more digit but apparently domoticz is rounding to one digit after ./,
Re: Rain counter
Posted: Wednesday 17 August 2022 7:48
by waltervl
If you look in the documentation
https://www.domoticz.com/wiki/DzVents:_ ... nd_methods
You see that the function round's second argument is the decimal place .round(number, [decimalPlaces])
So change 1 into 2 and you will be fine.
Re: Rain counter
Posted: Wednesday 17 August 2022 10:54
by Peter83
ok nice you can change it.
so i understand the script ans dzVents more an more now.
so code should change this way:
Code: Select all
rainTotal = dz.utils.round((rainmm + rainDevice.rain),1)
to
Code: Select all
rainTotal = dz.utils.round((rainmm + rainDevice.rain),2)
right?
But its still adding 0.5 instead of adding 0.45
can i put something in like:
Re: Rain counter
Posted: Wednesday 17 August 2022 11:21
by waltervl
No that has no use.
Do you see the 0.5 instead of .45 addition on the device itself or in the log?
Did you check the old value? You could add an extra log line just below "if item.active then" to see what is happening
Code: Select all
dz.log("Old value raindevice.rain: " .. rainDevice.rain .." mm in total today ", dz.LOG_DEBUG )
Re: Rain counter
Posted: Wednesday 17 August 2022 19:01
by Peter83
looking in the divice list, its shows 2 decimals. But adding 0.5 instead of 0,45 though.
Looking at wheater, the rain device just shows one decimal
lloking at Log it shows the same as in the device list.
adding your log line, nothing changes
code now is:
Code: Select all
return
{
on =
{
devices =
{
"s1",
},
},
logging =
{
level = domoticz.LOG_DEBUG, -- INFO, ERROR or DEBUG
marker = "ESP test",
},
execute = function(dz, item)
local rainDevice = dz.devices("regen6") -- Your (virtual) rain device
local rainSwitch = dz.devices("s1") -- 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 item.active then
rainTotal = dz.utils.round((rainmm/100 + rainDevice.rain),2)
rainDevice.updateRain(rainAmountHour, rainTotal)
dz.log("Old value raindevice.rain: " .. rainDevice.rain .." mm in total today ", dz.LOG_DEBUG )
dz.log("One bucket full ==>> updating raindevice. rainrate: " .. rainAmountHour .. " mm/hr, " .. rainTotal .." mm in total today ", dz.LOG_DEBUG )
rainSwitch.switchOff().silent()
end
end
}
so i changed ma raindevice to regen9 and now it added 0.45. But just one singel time.
Devicelist says 0.45 vor total rein
wheather says -0,0 for total rain.
now just rainrate is changing, when switching.
Re: Rain counter
Posted: Wednesday 17 August 2022 23:40
by Peter83
so theres a picture of my Log
seems like its counting right, now and showing right decimals.
But its startnig wit 0 again an d again. An weather device keeps saying 0 while device in devices list keeps saying 0.45 for total rain