Managed counter history not supporting decimals

Moderator: leecollings

Post Reply
ragz
Posts: 10
Joined: Friday 10 January 2020 16:54
Target OS: -
Domoticz version:
Contact:

Managed counter history not supporting decimals

Post by ragz »

Hi,

I've been trying to update the history of a managed counter with limited success.
My main problem currently is that decimals does not seem to be supported. Anyone know of a solution or workaround for this?

So the managed counter it self can hold and display decimal values, and the history graph seems to have some support for viewing decimal values but it seems the database or the `updateHistory` dzVents function does not support decimal values.

Example:

Code: Select all

domoticz.devices(166).updateHistory(domoticz.time.rawDateTime, '0.678;0.11')
Output:

Code: Select all

sqlite> select * from meter where devicerowid =166;
166|0|0|2021-10-03 10:58:10
I have tried all the formating options I could think of for the decimal values, such as:
string format ('0.678')
number format (0.678)
sqlite float (0.678f & '0.678f' )
and even crazy desperate things such as 678 / 1000

But it always ends up as an integer in the database (in this case 0).
User avatar
waltervl
Posts: 5149
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Managed counter history not supporting decimals

Post by waltervl »

You have to enter the values in Watt and not in kW. Domoticz will do the calculation to kW(h) for you depending on the divider settings in Menu Setup Settings (default 1000) https://www.domoticz.com/wiki/Applicati ... ters_Setup
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
ragz
Posts: 10
Joined: Friday 10 January 2020 16:54
Target OS: -
Domoticz version:
Contact:

Re: Managed counter history not supporting decimals

Post by ragz »

waltervl wrote: Sunday 03 October 2021 12:23 You have to enter the values in Watt and not in kW. Domoticz will do the calculation to kW(h) for you depending on the divider settings in Menu Setup Settings (default 1000) https://www.domoticz.com/wiki/Applicati ... ters_Setup
Sorry, I'm not sure I fully understand. How would that have any effect on the value / type stored in the database? Shouldn't a managed counter be able to support *any* value?
Besides, neither watt nor kW makes sense for my use case as I'm storing price fluctuations, which can be positive or negative decimal values.
User avatar
waltervl
Posts: 5149
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Managed counter history not supporting decimals

Post by waltervl »

I understand. But I do not know why it is not working for you. You could try the Domoticz HTTP Api call:

Code: Select all

 /json.htm?type=command&param=udevice&idx=IDX&nvalue=0&svalue=COUNTER;USAGE;DATE
    IDX = id of your device (This number can be found in the devices tab in the column "IDX")
    COUNTER = counter
    USAGE = usage
    DATE = date with %Y-%m-%d format (for instance 2019-09-24) to put data in last week/month/year history log, or "%Y-%m-%d %H:%M:%S" format (for instance 2019-10-03 14:00:00) to put data in last days history log
But why a managed counter, as a normal counter will do the history update for you....
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
ragz
Posts: 10
Joined: Friday 10 January 2020 16:54
Target OS: -
Domoticz version:
Contact:

Re: Managed counter history not supporting decimals

Post by ragz »

Thanks for the suggestion but I've already attempted that as well with the same results. Integers work, decimal/point/float/double does not work for the meters-table in domoticz database.

Api call:

Code: Select all

curl "https://localhost:8080/json.htm?type=command&param=udevice&idx=166&nvalue=0.555&svalue=0.666;0.777;2021-10-03%2013:13:13" --insecure
Response:

Code: Select all

{
        "status" : "OK",
        "title" : "Update Device"
}
Result is the same in database (i.e only integer values):

Code: Select all

sqlite> select * from meter where devicerowid =166;
166|0|0|2021-10-03 13:13:13
ragz
Posts: 10
Joined: Friday 10 January 2020 16:54
Target OS: -
Domoticz version:
Contact:

Re: Managed counter history not supporting decimals

Post by ragz »

Also, using a normal counter does not work either. For once it has this unnecessary"Today"-value that I do not need/want (the "Today"-value also works very poorly when dealing with decimals and negative numbers).
But more importantly is that my original issue still persists, that the meter-table in the database only accept integers. So the issue with storing decimals is still there with a normal counter.
ragz
Posts: 10
Joined: Friday 10 January 2020 16:54
Target OS: -
Domoticz version:
Contact:

Re: Managed counter history not supporting decimals

Post by ragz »

I've created a issue on GitHub for this: https://github.com/domoticz/domoticz/issues/4955
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 0 guests