thank you verry much! this works like a charm!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 }
Rain counter
Moderator: leecollings
-
- Posts: 241
- Joined: Tuesday 16 May 2017 13:05
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2020.2
- Location: The Neterlands
- Contact:
Re: Rain counter
raspberry pi | xiaomi vacuum | yeelight | philips hue | zwave | ubiquiti unifi | harmony | sonoff | zigbee2mqtt | https://www.youtube.com/channel/UC2Zidl ... m1OLuNldfQ
-
- Posts: 2
- Joined: Tuesday 18 May 2021 14:44
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Rain counter
Great work on this script but I've got strange behaviour;waaren wrote: ↑Monday 31 August 2020 22:35I 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 todaysnellejellep 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
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 }
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
}
-
- Posts: 2
- Joined: Tuesday 18 May 2021 14:44
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Rain counter
And today it's even stranger
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)

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
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)
-
- Posts: 24
- Joined: Sunday 31 July 2022 13:27
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Rain counter
Hi,
so i used above shown script:
Regen test is virtual sensors name
so letting this skript run it says:
so what am i missing??
so i used above shown script:
Regen1 is my hardware name (Dummy)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
}
Regen test is virtual sensors name
so letting this skript run it says:
"11" is the number of counts made by the swith today2022-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)
so what am i missing??
- waltervl
- Posts: 5846
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2024.7
- Location: NL
- Contact:
Re: Rain counter
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.
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.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
-
- Posts: 24
- Joined: Sunday 31 July 2022 13:27
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Rain counter
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:
wich log do you ask for?
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:
or put something in here?dz.log("One bucket full ==>> updating raindevice. rainrate: " .. rainAmountHour .. " mm/hr, " .. rainTotal .." mm in total today ", dz.LOG_DEBUG )
wich log do you ask for?
-
- Posts: 24
- Joined: Sunday 31 July 2022 13:27
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Rain counter
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..
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..
- Attachments
-
- Unbenannt.png (6.24 KiB) Viewed 1294 times
- waltervl
- Posts: 5846
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2024.7
- Location: NL
- Contact:
Re: Rain counter
I only was triggered on your error:
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
To
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?
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)
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 )
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)
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?
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
-
- Posts: 24
- Joined: Sunday 31 July 2022 13:27
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Rain counter
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"?
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"?
- waltervl
- Posts: 5846
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2024.7
- Location: NL
- Contact:
Re: Rain counter
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.
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.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
-
- Posts: 24
- Joined: Sunday 31 July 2022 13:27
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Rain counter
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..
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..
- waltervl
- Posts: 5846
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2024.7
- Location: NL
- Contact:
Re: Rain counter
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.
Edit: So you have to send 0.45*100 = 45 when you want to send .45 mm/hr
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]
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
-
- Posts: 24
- Joined: Sunday 31 July 2022 13:27
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Rain counter
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??
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
}
- waltervl
- Posts: 5846
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2024.7
- Location: NL
- Contact:
Re: Rain counter
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.

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.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
-
- Posts: 24
- Joined: Sunday 31 July 2022 13:27
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Rain counter
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:
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):
i need one more digit but apparently domoticz is rounding to one digit after ./,

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)
(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)
- waltervl
- Posts: 5846
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2024.7
- Location: NL
- Contact:
Re: Rain counter
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.
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.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
-
- Posts: 24
- Joined: Sunday 31 July 2022 13:27
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Rain counter
ok nice you can change it.
so i understand the script ans dzVents more an more now.
so code should change this way:
to
right?
But its still adding 0.5 instead of adding 0.45
can i put something in like:
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)
Code: Select all
rainTotal = dz.utils.round((rainmm + rainDevice.rain),2)
But its still adding 0.5 instead of adding 0.45
can i put something in like:
Code: Select all
local decimals =2
- waltervl
- Posts: 5846
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2024.7
- Location: NL
- Contact:
Re: Rain counter
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
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 )
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
-
- Posts: 24
- Joined: Sunday 31 July 2022 13:27
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Rain counter
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:
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.
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
}
Devicelist says 0.45 vor total rein
wheather says -0,0 for total rain.
now just rainrate is changing, when switching.
-
- Posts: 24
- Joined: Sunday 31 July 2022 13:27
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Rain counter
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
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
- Attachments
-
- Unbenannt.png (98.28 KiB) Viewed 1190 times
Who is online
Users browsing this forum: No registered users and 1 guest