dzvents Energy/Power sensor from ZWave updates - Wrong Energy Value unless triggered by Another Device

Moderator: leecollings

Post Reply
sidepipe
Posts: 29
Joined: Wednesday 18 February 2015 12:48
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

dzvents Energy/Power sensor from ZWave updates - Wrong Energy Value unless triggered by Another Device

Post by sidepipe »

I'm using a relatively recent version of Domoticz ( Compile Date: 2023-07-31 10:10:02, dzVents Version: 3.1.8 ) but this has been going on for some time ( not sure when it started or if it has always been the case. ) I also don't know if it's a problem with the core Domoticz code or dzvents itself ( i.e. whether other subsystems/scripts would see the same issue ) or even whether it's a misunderstanding on my part ( though it's still odd if so. )

I'm using ZWaveJS-MQTT to receive information from a Qubino smart meter, which was auto-discovered. In the Domoticz devices list, an example pair of devices is "Battery Energy In" which is a kWh sensor, and "Battery Power In" which is the related W sensor. In the GUI, these are correctly combined into a single sensor which shows both values ( i.e. the power is shown on the heading line and the kWh in the body ) and both of these values are always correct - i.e. when there's an MQTT update of the power, only the power changes, and when there's an MQTT update for the energy, only the energy "Today" changes... the sensor type is shown as kWh, General and the energy read is "From Device."

However, I have a dzvents script which is triggered by updates to this sensor, and it appears to be triggered often ( maybe by the power updates ), but the energy value is some seemingly random, but related, value ( i.e. it's some energy value, but not the current one. ) I can't really understand what the relationship is, but something odd is definitely happening. In addition, there are other values on the same physical device - the main one I use being "Battery Energy Out" ( as well as the power component. ) Interestingly, when the trigger to this same script is THAT device, the correct value for the "In" device seems to be read.

For example, this morning the energy value updated from 36.7 to 36.8 at 11:35:21, and to 36.9 at 11:45:07. I have logging in my script showing the trigger cause and the current Wh value, and there are no updates exactly relating to those times - maybe there's a delay but even then what's happening doesn't make sense.... the logging output was:

Code: Select all

... MQTT update to 36.8 happens at 11:35:21 ...
11:35:58.789  Status: dzVents: Info: Battery Cost: Read: Triggered by Battery Energy Out Wh today is 3800.0 and total is 31500.0
11:35:58.795  Status: dzVents: Info: Battery Cost: Read: 22905908.0 36800.0 31500.0
.... There are more as per the last two lines, then ...
11:36:02.534  Status: dzVents: Info: Battery Cost: Read: Triggered by Battery Energy In Wh today is 10800.0 and total is 36600.0
11:36:02.540  Status: dzVents: Info: Battery Cost: Read: 22905908.0 36600.0 31500.0
.... There are then more of those, then ...
11:36:38.818  Status: dzVents: Info: Battery Cost: Read: Triggered by Battery Energy Out Wh today is 3800.0 and total is 31500.0
11:36:38.826  Status: dzVents: Info: Battery Cost: Read: 22905908.0 36800.0 31500.0
... and so on.
So you can see that when the triigger is "Battery Energy Out," the correct WhTotal value is read for "Battery Energy In," but when it IS triggered by the "In" device, some previous value is returned.

The relevant parts of the script are:

Code: Select all

on = {
		devices = { 'Battery Energy In', 'Battery Energy Out' },
		variables = { 'MyOctopusElectricityppkWh' },
	},
	....
	execute = function(domoticz, item)
	    local Time = require("Time")
	    
	    if(item.isDevice) then
	        domoticz.log('Read: Triggered by ' .. item.name .. ' Wh today is ' .. item.WhToday .. ' and total is ' .. item.WhTotal, domoticz.LOG_INFO)
            end

.... Other irrelevant code that sets some history variables etc ...
	    
	    local grid = domoticz.devices('Electricity Meter').WhTotal
	    local batnow = domoticz.devices('Battery Energy In').WhTotal
	    local outnow = domoticz.devices('Battery Energy Out').WhTotal
	    
... More history variable stuff ...
        
            domoticz.log('Read: ' .. grid .. ' ' .. batnow .. ' ' .. outnow, domoticz.LOG_INFO)
        
.... Rest of script...
So, essentially the Triggered By log line prints the values read from the triggering device, whilst the "Read" line shows all of the devices I'm interested in. The example above shows the issue for the "Battery Energy In" device which is the middle value of the "Read:" line, and so as I say above you can see that the correct ( as shown in the GUI and looking at MQTT logs ) value is only read IF it's not actually the Battery Energy In device that's causing the script to run - otherwise, some value which is usually 100, 200 or 300 behind the current value is read. Note that the same issue exists for the "Out" device too - at least I see these previous values a lot of the time... not checked to make sure that it's the same problem ( i.e. it's incorrect when triggered by the out device itself ) but I would assume so.

The parts of the code I've omitted just store the historical values and check for this problem ( since I know that in reality the value shouldn't go backwards unless the counter completely resets. ) Hopefully someone familiar with the code can explain ( or ideally fix 8-) ) this.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests