Page 1 of 1

DzVents Script reports sometimes a wrong value

Posted: Sunday 26 January 2025 8:08
by mgerhard74
Hello,
I have a problem with a dzVents script.
Version: 2024.7 Build 16355
Platform: Raspi 3B, Raspbian 11 (bullseye) run on a SSD
In about 3% of all script runs, wrong values will sent to my Ulanzi TC001 pixel display. Other values (temperatures, PV power, grid power,...) are correct, only the battery SOC makes a problem:
My PV batterie reports every 5 minutes the SOC to a domoticz sensor:

Code: Select all

url = 'http://10.0.0.142:8080/json.htm?type=command&param=udevice&idx=35&nvalue=0&svalue={:d}'.format(SOC_result)
This work 100% correct.

This dzVents script gives in about 3% of all runs a incorrect value:

Code: Select all

return {
    on = { 
        devices = {'Batterie_SOC'}, 
        timer = { 'every 1 minutes' } 
        },
    execute = function(domoticz, device)
    BAT = domoticz.devices('Batterie_SOC').percentage;
    print ("Batt SOC " .. BAT .. '%')
    domoticz.openURL({
        url = 'http://10.0.0.157/api/custom?name=SOC',
        method = 'POST',
        callback = 'SOC',
        postData = {
            text = BAT .. '%',
            color = '#EBEAFF',
            icon = 6354,
            lifetime = 300
        }
    })
    end
}
For example:
Domoticz sensor "Batterie_SOC" is now 12%
But it reports 16%:
2025-01-26 07:46:06.297 dzVents: ------ Start internal script: AwtrixSOC:, trigger: "every 1 minutes"
2025-01-26 07:46:06.298 dzVents: Batt SOC 16%
the next run is correct:
2025-01-26 07:48:30.810 dzVents: ------ Start internal script: AwtrixSOC:, trigger: "every 1 minutes"
2025-01-26 07:48:30.811 dzVents: Batt SOC 12%

Maybe you have a idea to this issue?

Re: DzVents Script reports sometimes a wrong value

Posted: Sunday 26 January 2025 10:31
by waltervl
Perhaps use
local BAT =
This to be sure it does not get mixed up with another BAT value.

And you update every 5 minutes from the batterie but sends it to display every minutes.
It could be it is a timing issue as the updates from batterie is just milliseconds after the sending to display.

Re: DzVents Script reports sometimes a wrong value

Posted: Sunday 26 January 2025 10:43
by mgerhard74
Thank you, will try "local BAT=..."
This is definitly no timing issue: Batterie_SOC is 10% for hours, because this is the end-SOC of discharging. The script sends almost every time 10% to the pixel display, and then once for example 62%.

Re: DzVents Script reports sometimes a wrong value

Posted: Sunday 26 January 2025 11:53
by habahabahaba
viewtopic.php?p=322121#p322121

Post data have to be all string format

Re: DzVents Script reports sometimes a wrong value

Posted: Tuesday 28 January 2025 19:00
by mgerhard74
Thank you for your tips, but the problem still exists :-(
current script is:

Code: Select all

return {
    on = { 
        devices = {'Batterie_SOC'}, 
        timer = { 'every 1 minutes' } 
        },
    execute = function(domoticz, device)    
    local BAT = domoticz.devices('Batterie_SOC').percentage;    
    print ("Batt SOC " .. tostring(BAT) .. '%')
    domoticz.openURL({        
        url = 'http://10.0.0.157/api/custom?name=SOC',
        method = 'POST',
        callback = 'SOC',
        postData = {
            text = tostring(BAT) .. '%',
            color = '#EBEAFF',
            icon = '6354',
            lifetime = '300'
        }
    })    
    end
}

Re: DzVents Script reports sometimes a wrong value

Posted: Tuesday 28 January 2025 19:24
by waltervl
And there is only 1 device named Batterie_SOC?

Re: DzVents Script reports sometimes a wrong value

Posted: Tuesday 28 January 2025 19:32
by mgerhard74
Yes, only one

Re: DzVents Script reports sometimes a wrong value

Posted: Wednesday 29 January 2025 6:51
by habahabahaba
What is the type of device Batterie_SOC?

Re: DzVents Script reports sometimes a wrong value

Posted: Wednesday 29 January 2025 7:09
by mgerhard74
General/Percentage

Re: DzVents Script reports sometimes a wrong value

Posted: Wednesday 29 January 2025 7:50
by habahabahaba
mgerhard74 wrote: Wednesday 29 January 2025 7:09 General/Percentage
How and how often is it updated?

Re: DzVents Script reports sometimes a wrong value

Posted: Wednesday 29 January 2025 8:01
by mgerhard74
Every 5 minutes

Re: DzVents Script reports sometimes a wrong value

Posted: Wednesday 29 January 2025 9:00
by habahabahaba
No idea...

So if it is not timing issue and it is battery device... may be problem is in device? Or plugin (if it is zigbee device)?

Re: DzVents Script reports sometimes a wrong value

Posted: Wednesday 29 January 2025 9:17
by lost
mgerhard74 wrote: Sunday 26 January 2025 8:08 In about 3% of all script runs, wrong values
(...)
My PV batterie reports every 5 minutes the SOC to a domoticz sensor:

Code: Select all

return {
    on = { 
        devices = {'Batterie_SOC'}, 
        timer = { 'every 1 minutes' } 
        },
(...)
For example:
Domoticz sensor "Batterie_SOC" is now 12%
But it reports 16%:
2025-01-26 07:46:06.297 dzVents: ------ Start internal script: AwtrixSOC:, trigger: "every 1 minutes"
2025-01-26 07:46:06.298 dzVents: Batt SOC 16%
the next run is correct:
2025-01-26 07:48:30.810 dzVents: ------ Start internal script: AwtrixSOC:, trigger: "every 1 minutes"
2025-01-26 07:48:30.811 dzVents: Batt SOC 12%

Maybe you have a idea to this issue?
1st observation is when reading is correct, for a script supposed to trigger on 1 minute (almost exact) boundaries, request time looks to be 6s from your example time log... and 30s when result is incorrect? Not using dzVent but my Lua time scripts tiggers very shortly after HH:MM:00 and this already looks suspicious for me.

+ you read every minute for a data updated by your hardware every 5mn.

So, if valid update delay is correct, 6s for a correctly handled request on a 1 minute time slice for a data updated every 5mn gives a probability to have the request from Domoticz done during data update by HW of (6/60)*1/5, so roughly your 3% fails figure.

For hand done request that succeeds, do you observe such long response times?

Re: DzVents Script reports sometimes a wrong value

Posted: Wednesday 29 January 2025 9:57
by waltervl
You could try to leave out the 1 minute timer trigger.
Then when the Domoticz device 'Batterie_SOC' is updated (by another script or plugin), it will immediately be sent to the display. I see no need to send the data to the display every minute....

Re: DzVents Script reports sometimes a wrong value

Posted: Wednesday 29 January 2025 12:45
by habahabahaba
lost wrote: Wednesday 29 January 2025 9:17 Domoticz done during data update by HW of (6/60)*1/5, so roughly your 3% fails figure.
How did you count that?? :shock:

Batterie_SOC updates every 5 mn so it was updated at 07:45:00
AwtrixSOC runs every 1 mn so it started at 07:46:00 (07:46:06 from log) - after ONE minute when Batterie_SOC have to be in the right value.

But i agree that the script running delay is too big.

maybe the system is overloaded with something?
then it could cause time overlaps.

Re: DzVents Script reports sometimes a wrong value

Posted: Wednesday 29 January 2025 14:45
by lost
Did not saw any indication that updates were in sync exactly every 5mn. So I believed reads were asynchronous vs updates so that's just based on a sliding 1mn (60s) window that may fall on a 6s data read time over 5x1mn slices (HW update time).

My guess was reading exactly when, unfortunately, an update was done by HW may cause bad readings from Domoticz.

But I may be wrong, I don't own this hardware...

Re: DzVents Script reports sometimes a wrong value

Posted: Wednesday 29 January 2025 16:41
by mgerhard74
Thank you waltervl , i will try this:
waltervl wrote: Wednesday 29 January 2025 9:57 You could try to leave out the 1 minute timer trigger.
Then when the Domoticz device 'Batterie_SOC' is updated (by another script or plugin), it will immediately be sent to the display. I see no need to send the data to the display every minute....

Re: DzVents Script reports sometimes a wrong value

Posted: Saturday 01 February 2025 19:43
by mgerhard74
Can anyone tell me why a dzVents script does not run every minute (I can see it in the log) if this is entered in the script?

Code: Select all

timer = { 'every 1 minutes' }

Re: DzVents Script reports sometimes a wrong value

Posted: Saturday 01 February 2025 20:27
by habahabahaba
Full code and log?

Re: DzVents Script reports sometimes a wrong value

Posted: Saturday 01 February 2025 21:06
by waltervl
Try

Code: Select all

timer =  { 'every minute' }