Page 1 of 1

Python Framework - Updating Battery and Level without touching sValue and nValue

Posted: Wednesday 11 August 2021 9:17
by pipiche
Within the Domoticz Python Plugin Framework everytime we call the Update method, it triggers the domoticz notification mechanism (dzEvents .... ), however sometimes, we just have to update some side informations like Signal or Battery level.

For instance if you take a Water Leak device, it is expected that we never get a state change (detection of water) during its all life, despite the fact that the battery will drain and get empty at a point of time.

As of now, in order to protect the Domoticz notification system, (and the device log) we do update only when sValue and nValue are changing.

Could we imagine a specific methods to update silently Battery, Levels ?

Re: Python Framework - Updating Battery and Level without touching sValue and nValue

Posted: Wednesday 11 August 2021 13:29
by waltervl
Use the SuppressTriggers ?:
Optional
Default: False Boolean flag that allows device attributes to be updated without notifications, scene or MQTT, event triggers. nValue and sValue are not written to the database and will be overwritten with current database values.
https://www.domoticz.com/wiki/Developin ... #Devices_2

Re: Python Framework - Updating Battery and Level without touching sValue and nValue

Posted: Wednesday 11 August 2021 13:58
by pipiche
@waltervl did you already use it ? because from my understanding this do not update anything at all !
It is only used for updating:
Used
Options
Color
CustomImage
SwitchType
SubType
Type
Description
Name

This by the way why there is also a dedicated method for updating the LastUpdate ( Touch() )

Re: Python Framework - Updating Battery and Level without touching sValue and nValue

Posted: Wednesday 11 August 2021 14:28
by waltervl
I did not try it.

Re: Python Framework - Updating Battery and Level without touching sValue and nValue

Posted: Wednesday 11 August 2021 18:06
by Thorgal789
Same for me, "SuppressTriggers" haven't worked on my side.
And I have same problem for switches, to don't trigger LUA event during a battery update. I m forced to ignore all event and only update battery during a button press to avoid that.

Re: Python Framework - Updating Battery and Level without touching sValue and nValue

Posted: Wednesday 11 August 2021 19:28
by pipiche
The way I see it is to either create an addition method UpdateBattery() which could be simpler, or the treat "Battery" as the "SuppressTriggers" eligible attribute

Re: Python Framework - Updating Battery and Level without touching sValue and nValue

Posted: Thursday 12 August 2021 2:10
by Dnpwwo
Hi,

I've had a look at the update function in the legacy plugin framework and it looks like the developer who added SupressTriggers made some interesting choices.

BatteryLevel will ONLY be updated if SuppressTriggers is false and even then only sometimes because the original code was changed to use an underlying internal Domoticz function to update values and that code has hundreds of lines of logic that makes it do different things for different device types.

Given this change was made quite some time ago I'm not sure the code can be reverted because a number of plugins will have been developed to work with it the way it is. Instead I've pushed a fix where the existing code remains but they are also updated (if changed) regardless of SuppressTriggers, this is aligned to how most non-value fields are treated. In some cases they will now be updated twice but that seems like a minor side effect.

Can you try it out?

Re: Python Framework - Updating Battery and Level without touching sValue and nValue

Posted: Thursday 12 August 2021 9:31
by pipiche
@Dnpwwo as usal, this is working well, thanks for the quick update.

the only sad thing, but I think we cannot really change is that nValue and sValue must be part of the parameters.

Well done ! It works with 2021.1 (Build 13374)