Page 1 of 1

Question on the WIki: AddDBLogEntry / historic data addition

Posted: Friday 10 March 2023 17:06
by JustDude
Hi,

I wanted to add historic data to my P1 (gas and Electra) via the following instruction on the Wiki (nice documentation by the way):
Note on counters
Usually, counters are updated daily to feed week/month/year history log views. Starting version 4.11774, if you want to disable that behavior to control everything from an external script or a plugin (already the case for managed counter), you can set the "DisableLogAutoUpdate" device option to "true", for instance in a Python plugin:
Domoticz.Device(Name="MyCounter", Unit=1, Type=0xfa, Subtype=0x01, Options={"DisableLogAutoUpdate" : "true").Create()
Starting version 4.11774, you can too directly insert data in in history log. Set the "AddDBLogEntry" device option to "true", for instance in a Python plugin:
Domoticz.Device(Name="MyCounter", Unit=1, Type=0xfa, Subtype=0x01, Options={"AddDBLogEntry" : "true").Create()

and:
Then, depending on counters, you can insert values in history log. For most counters:
/json.htm?type=command&param=udevice&idx=IDX&nvalue=0&svalue=COUNTER;USAGE;DATE
Now I looked at the Domoticz code and the AddDBLogEntry parameter is only used for Managed counters, nowhere else.
Before I do a try out on a copy of my DB, I want to make sure if it is possible to add historical data like this for current and daily usage.
Or is it limited to managed counters as the code suggests

Re: Question on the WIki: AddDBLogEntry / historic data addition

Posted: Friday 10 March 2023 18:06
by willemd
the if condition in the code is

Code: Select all

if ((devType == pTypeGeneral && subType == sTypeManagedCounter) || (options["AddDBLogEntry"] == "true"))
so this states you can do the inserts if it is a managed counter (even without setting AddDBLogEntry)
but you can also do the inserts on other counters if you set the AddDBLogEntry option.

I did some testing a few months ago and as result the documentation was adapted. If I remember well it indeed also worked for other counters.
It is easy to test, just update the options field in devicestatus (for example with sqlite3. Make a backup beforehand !!) to the string indicated and run the json statement.

see also
https://github.com/domoticz/domoticz/issues/5447
https://github.com/domoticz/domoticz/issues/5479

Re: Question on the WIki: AddDBLogEntry / historic data addition

Posted: Friday 10 March 2023 19:05
by JustDude
Thanks tons! That was indeed my mistake, I misread the statement.
I want to try it out on a test install indeed before live.