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.
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...
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 ) this.