Dzvents isn't storing value in virtual point

Please use template to report bugs and problems. Post here your questions when not sure where else to post
Only for bugs in the Domoticz application! other problems go in different subforums!

Moderators: leecollings, remb0

Forum rules
Before posting here, make sure you are on the latest Beta or Stable version.
If you have problems related to the web gui, clear your browser cache + appcache first.

Use the following template when posting here:

Version: xxxx
Platform: xxxx
Plugin/Hardware: xxxx
Description:
.....

If you are having problems with scripts/blockly, always post the script (in a spoiler or code tag) or screenshots of your blockly

If you are replying, please do not quote images/code from the first post

Please mark your topic as Solved when the problem is solved.
Post Reply
dthompson
Posts: 26
Joined: Tuesday 07 June 2016 21:47
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Dzvents isn't storing value in virtual point

Post by dthompson »

So, i'm not sure if this is a dzvents issue or an issue with the virtual device i created. Here's the issue i noticed today.

I have a dzvents program running every 5 minutes. It's been fine as far as i can tell for months now. It calculates the differential value from the main water meter to determine actual water consumed per period (5 minutes).

But, this morning at 6am i ran my irrigation system which consumes around 800 gallons over the course of an hour. In looking at the chart for the virtual point i don't see that spike. Here's what i can see in the main log file of Domoticz:

2026-09-05 07:15:01.018 Status: Set UserVariable LastValue = 101287
2026-09-05 07:20:00.393 Status: Set UserVariable LastValue = 101376
2026-09-05 07:20:01.388 Status: Schedule item started! Name: Sprinkler Zone 3, Type: On Time, DevID: 160, Time: 2026-09-05 07:20:01
2026-09-05 07:25:00.540 Status: Set UserVariable LastValue = 101376
2026-09-05 07:30:00.762 Status: EventSystem: Script event triggered: dzVents/Water usage
2026-09-05 07:30:00.788 Status: Set UserVariable LastValue = 101376
2026-09-05 07:35:01.029 Status: EventSystem: Script event triggered: dzVents/Water usage
2026-09-05 07:35:01.070 Status: Set UserVariable LastValue = 101376
2026-09-05 07:40:00.318 Status: Set UserVariable LastValue = 101376
2026-09-05 07:45:00.715 Status: Set UserVariable LastValue = 101376

I was barely able to catch this as the log file was filling up and dumping the old reports. But, you can see that the Dzvents program saw the difference in the main meter values and stored that delta in my user variable LastValue at 7:20 this morning. That's 890 gallons as the water meter only reports in 10 gallon increments.

In the history file of the virtual point didn't store the differential. Here's a snippet of that file:

2026-09-05 06:00:00 0
2026-09-05 06:05:00 10
2026-09-05 06:10:00 0
2026-09-05 06:15:00 0
2026-09-05 06:20:00 0
2026-09-05 06:25:00 0
2026-09-05 06:30:00 0
2026-09-05 06:35:00 0
2026-09-05 06:40:00 0
2026-09-05 06:45:00 0
2026-09-05 06:50:00 0
2026-09-05 06:55:00 0
2026-09-05 07:00:00 0
2026-09-05 07:05:00 0
2026-09-05 07:10:00 0
2026-09-05 07:15:00 0
2026-09-05 07:20:00 0
2026-09-05 07:25:00 0
2026-09-05 07:30:00 0
2026-09-05 07:35:00 0
2026-09-05 07:40:00 0

And, finally here's the dzvents code that's been working fine as far as i can tell for months.

Code: Select all

return {
    on = {
        timer = {
            'every 5 minutes' -- This is your time trigger
        }
    },
    execute = function(domoticz, timer)
        -- 1. Get the current reading
        local currentFlow = domoticz.devices('Total water used').sensorValue
        
        -- 2. Retrieve the last saved reading
        local lastFlow = domoticz.variables('LastValue').value
        
        -- 3. Calculate the difference
        local difference = (currentFlow - lastFlow) * 10
        
        -- 4. Log the results to the Domoticz log
        domoticz.log('Current Flow: ' .. currentFlow .. ' Gal', domoticz.LOG_INFO)
        domoticz.log('Previous Flow: ' .. lastFlow .. ' Gal', domoticz.LOG_INFO)
        domoticz.log('Calculated Difference: ' .. difference .. ' Gal', domoticz.LOG_INFO)
        
        -- 5. OPTIONAL: Update a dummy device with the difference
        domoticz.devices('Water usage').updateCustomSensor(difference)
        
        -- 6. Update the persistent variable for the next run
        domoticz.variables('LastValue').set(currentFlow)
    end
}
I'm running on a Raspberry Pi 5 running Bookworm. Domoticz version 2026.2

No errors in the log file.


Any help on this would be greatly appreciated.

Thank you,
Darryl
Last edited by dthompson on Tuesday 15 September 2026 3:32, edited 1 time in total.
User avatar
waltervl
Posts: 7002
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2026.3
Location: NL
Contact:

Re: Dzvents didn't store value in history

Post by waltervl »

Looks OK for me.
Best to get another try to get the log on the moment you expect a water demand. Then you would see more logging pop up according your script when everything goes as expected. That logging could give some clues.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
dthompson
Posts: 26
Joined: Tuesday 07 June 2016 21:47
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Dzvents didn't store value in history

Post by dthompson »

So, here's what i saw this morning. I don't see anything that looks incorrect. The script appears to be calculating appropriately, yet the new value is NOT being stored.

Here's the log file for 7:05 this morning where it shows the script running and calculating the differential value:

2026-09-08 07:05:01.048 dzVents: ------ Start internal script: Water usage:, trigger: "every 5 minutes"
2026-09-08 07:05:01.058 dzVents: Current Flow: 101411 Gal
2026-09-08 07:05:01.058 dzVents: Previous Flow: 101410.0 Gal
2026-09-08 07:05:01.058 dzVents: Calculated Difference: 10.0 Gal
2026-09-08 07:05:01.059 dzVents: ------ Finished Water usage
2026-09-08 07:05:01.089 Status: Set UserVariable LastValue = 101411

And, here's a copy of the history for the Water usage device:

2026-09-08 06:30:00 0
2026-09-08 06:35:00 0
2026-09-08 06:40:00 0
2026-09-08 06:45:00 0
2026-09-08 06:50:00 0
2026-09-08 06:55:00 0
2026-09-08 07:00:00 0
2026-09-08 07:05:00 0
2026-09-08 07:10:00 0
2026-09-08 07:15:00 0
2026-09-08 07:20:00 0
2026-09-08 07:25:00 0

So, i'm at a loss here. I don't know why the value wasn't stored into my virtual device Water usage.

Thank you for your help !!!

Darryl
dthompson
Posts: 26
Joined: Tuesday 07 June 2016 21:47
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Dzvents didn't store value in history

Post by dthompson »

Ok, this time it stored the value. I've been watching it this morning as i'm running my sprinkler system. At 8:10 this morning my main water meter reported the total flow and the script calculated the difference as before, but this time the value was stored in the virtual sensor Water usage as expected.

I just don't understand why it works sometimes and doesn't other times. There's nothing i can see in the log file below to explain it.


2026-09-08 08:10:00.477 dzVents: ------ Start internal script: Water usage:, trigger: "every 5 minutes"
2026-09-08 08:10:00.491 dzVents: Current Flow: 101495 Gal
2026-09-08 08:10:00.491 dzVents: Previous Flow: 101411.0 Gal
2026-09-08 08:10:00.491 dzVents: Calculated Difference: 840.0 Gal
2026-09-08 08:10:00.492 dzVents: ------ Finished Water usage
2026-09-08 08:10:00.518 Status: Set UserVariable LastValue = 101495


History file:

2026-09-08 07:55:00 0
2026-09-08 08:00:00 0
2026-09-08 08:05:00 0
2026-09-08 08:10:00 840

Any help is very much appreciated !!!

Darryl
dthompson
Posts: 26
Joined: Tuesday 07 June 2016 21:47
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Dzvents isn't storing value in virtual point

Post by dthompson »

It's still randomly not storing the calculated value in the virtual point. I don't see any errors or any reason for it to work sometimes and other times nothing.

I could really use some help on this issue.

Thanks,
Darryl
lost
Posts: 715
Joined: Thursday 10 November 2016 9:30
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Dzvents isn't storing value in virtual point

Post by lost »

Not sure this apply to variables, but take care that any sensor value is sampled every 5mn for DB storage. So for something differential that may be changed/zeroed in the next slice, updating at the exact sampling period may explain this sometimes don't work.

So computing your differences every 10mn (or even 6mn!) may IMO be worth a try: Over the sampling period => No more intermediate values missed?

For a different purpose, I have already being annoyed by this Domoticz behavior: That's not a problem for data that don't vary a lot in a 5mn period (like a temperature/humidity), but for anything that does vary a lot what's stored in DB mostly does not reflect real values for the period.

This was a problem for me with the (very) verbose data of the wattmeter that sends my whole home electric power usage (instant values, not counter, the latter would have been easier to handle) for every 1% variation. I had to write a script that calculates (device script doing a discrete integration, in fact, summing value * time since last_update of HW linked device, in the end divided by time since last virtual device update) mean power (as well as peak power, that I use to trigger some offloading to remain in my electricity provider limits) over ~10mn (that's time script, so may exceed a bit the limit but usually not much as device is verbose) time slices to have meaningfull power data stored in DB. This script feeds virtual devices (one for mean, another for peak) that gets the meaningfull data that devices directly feed by the hardware don't provide.
dthompson
Posts: 26
Joined: Tuesday 07 June 2016 21:47
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Dzvents isn't storing value in virtual point

Post by dthompson »

Lost, thanks for that possible solution. It seems to me though that if you set the calculation time to every 10 minutes, that it would still be hung up with the 5 minute db storage routine. And, the same would be true of 6 minute calcs, every 30 minutes it would coincide with the db storage routine. There must be a way to pause the dzvents update to the virtual point until it's done it's db storage.

I may try this just to see if it corrects the issue even somewhat.

Thanks again!
Darryl
lost
Posts: 715
Joined: Thursday 10 November 2016 9:30
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Dzvents isn't storing value in virtual point

Post by lost »

dthompson wrote: Tuesday 15 September 2026 17:05 It seems to me though that if you set the calculation time to every 10 minutes, that it would still be hung up with the 5 minute db storage routine. And, the same would be true of 6 minute calcs, every 30 minutes it would coincide with the db storage routine.
In my experience, this was not the case: Values updated every 10mn (in my case) and then stable for the same time (so over the 5mn sampling period for DB inclusion, even if you can see in live devices updates all values are shown, but will mostly not be stored to keep DB size reasonable) all goes to DB without any miss.

See this CSV data downloaded from my mean power usage of the day (I'm not at home, so that's pretty low wattage figures), that's quite clear: No miss, but as my update period is twice the Dz sampling, same value is in my case seen twice:

Code: Select all

"DateTime";"Utilisation"
"2026-09-15 15:15:00";219
"2026-09-15 15:20:00";219
"2026-09-15 15:25:00";217
"2026-09-15 15:30:00";217
"2026-09-15 15:35:00";234
"2026-09-15 15:40:00";234
"2026-09-15 15:45:00";255
"2026-09-15 15:50:00";255
"2026-09-15 15:55:00";217
"2026-09-15 16:00:00";217
"2026-09-15 16:05:00";169
"2026-09-15 16:10:00";169
To avoid such issues and resulting hacks, this would be nice to have a few compute switches in sensor widgets able to activate true max/min/mean computes on a sampling period (and ability to print them on a single graph).
Post Reply