Page 2 of 2
Re: Script subtracting measurements from two water meters
Posted: Sunday 01 September 2024 21:47
by FlyingDomotic
Maciek90 wrote: ↑Sunday 01 September 2024 21:41
What do you mean specifically? What should I change in the script to implement your suggestion?
Create a water counter, name it "Test" and ceate a dzVents script containing:
Code: Select all
return {
on = {devices = {'Water', 'Garden'}},
execute = function(domoticz, device)
domoticz.Devices("Test").updateCounter(domoticz.Devices("Water").counter - domoticz.Devices("Garden").counter)
end
}
Re: Script subtracting measurements from two water meters
Posted: Monday 02 September 2024 9:34
by willemd
Maciek90 wrote: ↑Sunday 01 September 2024 21:41
Sorry, there is one left parenthesis too much. Please remove the "(" before the word resultCounter. Then it should work.
I did it and the logs showed something like this:
Code: Select all
2024-09-01 21:39:31.464 dzVents: Debug: Water Counter Script: Processing device-adapter for Water: Counter device adapter
2024-09-01 21:39:31.464 dzVents: Debug: Water Counter Script: Processing device-adapter for test: Counter device adapter
2024-09-01 21:39:31.464 dzVents: Debug: Water Counter Script: Water: 1497.183
2024-09-01 21:39:31.464 dzVents: Debug: Water Counter Script: Garden: 339.457
2024-09-01 21:39:31.464 dzVents: Debug: Water Counter Script: Daily Water: 0.518
2024-09-01 21:39:31.464 dzVents: Debug: Water Counter Script: Daily Garden: 0.069
2024-09-01 21:39:31.464 dzVents: Debug: Water Counter Script: Total difference: 1157.726
2024-09-01 21:39:31.464 dzVents: Debug: Water Counter Script: Daily difference: 0.449
2024-09-01 21:39:31.464 dzVents: Debug: Water Counter Script: resultCounterToday: 0
2024-09-01 21:39:31.464 dzVents: Debug: Water Counter Script: resultCounter : 1157.726
I assume you get the above output multiple times per day and each time the Total Difference is slightly higher, the resultCounter is slightly higher but resultCounterToday remains zero? (ref. my previous explanation that counterToday is not updated during the script but will be visible at the next run)
I have no idea why this does not work. The resultCounter is updated correctly and therefore Domoticz itself should calculate and show counterToday value correctly. I do this all the time in my installation.
The only strange thing I see in your first post is that the total value is shown in m3 while the daily total is show with unit Liter (even if it is 0).
I assume you are multiplying the value with the divider of the resultcounter during the update? It was mentioned before and otherwise the total also would not be correct.
Try making a second resultcounter and update that one in the same way. Maybe somehow something is wrong with the device.
Re: Script subtracting measurements from two water meters
Posted: Monday 02 September 2024 12:12
by Maciek90
Create a water counter, name it "Test" and ceate a dzVents script containing:
Just this script or should I add something else? I get these errors in the logs when I try to do this.
Code: Select all
2024-09-02 12:05:30.577 Error: dzVents: An error occurred when calling event handler Woda chtgpt licznik dzienny
2024-09-02 12:05:30.577 Error: dzVents: ...zVents/generated_scripts/Woda chtgpt licznik dzienny.lua:4: attempt to call a nil value (field 'Devices')
2024-09-02 12:05:30.674 Error: dzVents: An error occurred when calling event handler Woda chtgpt licznik dzienny
I assume you get the above output multiple times per day and each time the Total Difference is slightly higher, the resultCounter is slightly higher but resultCounterToday remains zero? (ref. my previous explanation that counterToday is not updated during the script but will be visible at the next run)
Yes.
Can you show me your script and the devices it supports? I'll compare and maybe I'll spot some error in my script.
Re: Script subtracting measurements from two water meters
Posted: Monday 02 September 2024 15:31
by FlyingDomotic
Sorry, I made a mistake written device with an uppercase.
Try to cut & paste:
Code: Select all
return {
on = {devices = {'Water', 'Garden'}},
execute = function(domoticz, device)
print("Water: "..tostring(domoticz.devices("Water").counter))
print("Garden: "..tostring(domoticz.devices("Garden").counter))
domoticz.devices("TestWater").updateCounter(domoticz.devices("Water").counter - domoticz.devices("Garden").counter)
end
}
Re: Script subtracting measurements from two water meters
Posted: Tuesday 03 September 2024 0:43
by Maciek90
I get logs like below and TestWater meter still shows daily usage of 0 liters. Maybe the problem is the type of meter I am using? I select from the list counter and then click edit and change the type to water
Code: Select all
2024-09-03 00:35:51.519 dzVents: Handling events for: "Garden", value: "18446744073709548527"
2024-09-03 00:35:51.520 dzVents: ------ Start internal script: Water: Device: "Garden (Wodomierz)", Index: 1146
2024-09-03 00:35:51.520 dzVents: Water: 1497.201
2024-09-03 00:35:51.520 dzVents: Garden: 339.507
2024-09-03 00:35:51.520 dzVents: ------ Finished Water
Re: Script subtracting measurements from two water meters
Posted: Tuesday 03 September 2024 2:44
by FlyingDomotic
Oups, I forgot an amazing thing with counters. Returned data is divided by divisor (for water, default is 100), but stored as is. It means that you must multiply data by divisor before sending it (as Domoticz will divide it by divisor).
If not using default value (100 for water), change 100 in the following script by right divisor
Code: Select all
return {
on = {devices = {'Water', 'Garden'}},
execute = function(domoticz, device)
domoticz.devices("TestWater").updateCounter((domoticz.devices("Water").counter - domoticz.devices("Garden").counter)*100)
end
}
Re: Script subtracting measurements from two water meters
Posted: Thursday 05 September 2024 2:36
by Maciek90
It seems to work (thank you very much FlyingDomotic). I have one more question. Why do I get the result in liters and not m3? Is there any way to change this?
Re: Script subtracting measurements from two water meters
Posted: Thursday 05 September 2024 10:47
by FlyingDomotic
Differences comes from different counter types: Water and Garden are "(incremental) counters" while Test3 is "RFXmeter counter". If you wish having the same format, changing Test3 to "Counter" (not incremental) may help (I didn't test it).
Re: Script subtracting measurements from two water meters
Posted: Saturday 07 September 2024 20:37
by Maciek90
This doesn't help, because the RFXmeter counter is a counter selected from a list. As in the screenshot below.
Re: Script subtracting measurements from two water meters
Posted: Saturday 07 September 2024 21:13
by FlyingDomotic
Maciek90 wrote: ↑Saturday 07 September 2024 20:37
This doesn't help, because the RFXmeter counter is a counter selected from a list. As in the screenshot below.
What's the issue? Just create d dummy device with "Counter type", select it in "Utility" tab, change change type to "water" and validate.
Re: Script subtracting measurements from two water meters
Posted: Sunday 08 September 2024 18:46
by Maciek90
I know that. I created my test3 counter exactly as you wrote, but it shows me liters, not m3. I asked if it is possible to somehow change liters to m3 so that in each counter I have m3
Re: Script subtracting measurements from two water meters
Posted: Sunday 08 September 2024 23:23
by waltervl
You can also use this counter and set it to custom and use m3 as value. A normal water counter will always show liter in daily use and m3 in totals
Re: Script subtracting measurements from two water meters
Posted: Thursday 19 September 2024 1:37
by Maciek90
Thank you very much for you help. It works!!!