Value of managed counter is visible in the devices tab, but not stored in the database

Please use template to report bugs and problems. Post here your questions when not sure where else to post
Only for bugs in the Domoticz application! other problems go in different subforums!

Moderators: leecollings, remb0

Forum rules
Before posting here, make sure you are on the latest Beta or Stable version.
If you have problems related to the web gui, clear your browser cache + appcache first.

Use the following template when posting here:

Version: xxxx
Platform: xxxx
Plugin/Hardware: xxxx
Description:
.....

If you are having problems with scripts/blockly, always post the script (in a spoiler or code tag) or screenshots of your blockly

If you are replying, please do not quote images/code from the first post

Please mark your topic as Solved when the problem is solved.
Post Reply
jvdk
Posts: 38
Joined: Sunday 11 August 2019 17:16
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Value of managed counter is visible in the devices tab, but not stored in the database

Post by jvdk »

I made a dzvents script to calculate the daily energy costs. I store these costs in dummy sensors. That works fine. I want to store these values in managed counters however. The advantage of managed counters is that you can have reports in the graphs view.
To test if this works I made an extra dummy managed counter.
Edit device.png
Edit device.png (24.76 KiB) Viewed 785 times
I write the cost to the sensor at 23:59 hours using the command:
domoticz.devices('Dynamische energiekosten 2').updateCounter(Kostentotaal)
That works fine. I see the following in the devices tab:
Devices tab.png
Devices tab.png (10.15 KiB) Viewed 785 times
The graph as well as the report remains empty:
Edit device.png
Edit device.png (24.76 KiB) Viewed 785 times
I made a backup of the database and opened it in an SQLite viewer. There are no values in the Meter or Meter_Calendar tables.
I searched the forum and the internet, but could not find what I am doing wrong. Who can help?
Attachments
Graph.png
Graph.png (53.07 KiB) Viewed 785 times
peterchef
Posts: 37
Joined: Sunday 03 January 2016 17:49
Target OS: Windows
Domoticz version: 2024.4
Location: France
Contact:

Re: Value of managed counter is visible in the devices tab, but not stored in the database

Post by peterchef »

Hi
I think you need to use .updateHistory to update the values

https://www.domoticz.com/wiki/DzVents:_ ... ncremental
jvdk
Posts: 38
Joined: Sunday 11 August 2019 17:16
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Value of managed counter is visible in the devices tab, but not stored in the database

Post by jvdk »

peterchef wrote: Sunday 18 August 2024 10:19 Hi
I think you need to use .updateHistory to update the values

https://www.domoticz.com/wiki/DzVents:_ ... ncremental
I already tried that. But the values were not saved in the csdb. Perhaps I should start again with a new managed counter and a simple script to store a fixed value and see what happens.
willemd
Posts: 631
Joined: Saturday 21 September 2019 17:55
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.1
Location: The Netherlands
Contact:

Re: Value of managed counter is visible in the devices tab, but not stored in the database

Post by willemd »

I do something similar all the time, the updateHistory works fine.

If you want to store a daily value in the meter_calendar table you need to use
domoticz.devices('Dynamische energiekosten 2').updateHistory(valueDate,valueString)
where valueDate is a date in format yyyy-mm-dd
and valueString is a string with 2 values separated by a semicolon.
The first value of valueString will be stored in the counter field (i.e. the cumulative value of all days).
The second value will be stored in the value field.
So you could start with
local valueString="0;"..Kostentotaal
and use that value in the updateHistory command.
jvdk
Posts: 38
Joined: Sunday 11 August 2019 17:16
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Value of managed counter is visible in the devices tab, but not stored in the database

Post by jvdk »

Thank you all. It works! I tried it before using the updateHistory command. I probably made a mistake.
I now am going to rewrite the script to write the gas costs, the electricity costs and the total cost to managed counters.

Thanks again!
User avatar
waltervl
Posts: 5777
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Value of managed counter is visible in the devices tab, but not stored in the database

Post by waltervl »

jvdk wrote: Monday 19 August 2024 20:07 Thank you all. It works! I tried it before using the updateHistory command. I probably made a mistake.
I now am going to rewrite the script to write the gas costs, the electricity costs and the total cost to managed counters.

Thanks again!
Just to be sure: if you have a device that has the current (dynamic) cost price of Electricity and Gas, Domoticz can calculate the total costs for you automatically now. No need to do fancy script things anymore with managed counters.
See wiki https://www.domoticz.com/wiki/Applicati ... alculation
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
willemd
Posts: 631
Joined: Saturday 21 September 2019 17:55
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.1
Location: The Netherlands
Contact:

Re: Value of managed counter is visible in the devices tab, but not stored in the database

Post by willemd »

waltervl wrote: Tuesday 20 August 2024 10:58
jvdk wrote: Monday 19 August 2024 20:07 Thank you all. It works! I tried it before using the updateHistory command. I probably made a mistake.
I now am going to rewrite the script to write the gas costs, the electricity costs and the total cost to managed counters.

Thanks again!
Just to be sure: if you have a device that has the current (dynamic) cost price of Electricity and Gas, Domoticz can calculate the total costs for you automatically now. No need to do fancy script things anymore with managed counters.
See wiki https://www.domoticz.com/wiki/Applicati ... alculation
But please note that due to issue #5437 the costs calculated by domoticz will not be 100% correct and therefore not match the calculations of your electricity provider.

I run an integrity-check script on a regular basis which checks wether the value field in the dbase matches the difference between two consecutive counter fields and very often it does not match because of 5 minute values missing as explained in issue 5437.

I see issue 5437 was closed and I don't know how to reopen it (other than creating a new one).
jvdk
Posts: 38
Joined: Sunday 11 August 2019 17:16
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Value of managed counter is visible in the devices tab, but not stored in the database

Post by jvdk »

Just to be sure: if you have a device that has the current (dynamic) cost price of Electricity and Gas, Domoticz can calculate the total costs for you automatically now. No need to do fancy script things anymore with managed counters.
See wiki https://www.domoticz.com/wiki/Applicati ... alculation
I know, but I want to take everything into account. Also the fixed costs. I want to compare my new dynamic contract with a year contract, where I also take into account the fine (terugleverkosten) I have to pay supplying energy back into the net when I would have chosen a year contract.
Fixed costs are not taken into account when using the built-in energy cost calculation of Domoticz.
User avatar
waltervl
Posts: 5777
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Value of managed counter is visible in the devices tab, but not stored in the database

Post by waltervl »

Perhaps you guys update Domoticz so it can handle all cost options?

@willemd, things have changed a lot since you have opened it 2 years ago. It was closed to no feedback. https://github.com/domoticz/domoticz/issues/5437

But if it it still an issue better create a new issue based on latest beta and give some examples so it can be reproduced.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
willemd
Posts: 631
Joined: Saturday 21 September 2019 17:55
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.1
Location: The Netherlands
Contact:

Re: Value of managed counter is visible in the devices tab, but not stored in the database

Post by willemd »

waltervl wrote: Tuesday 20 August 2024 18:38 Perhaps you guys update Domoticz so it can handle all cost options?

@willemd, things have changed a lot since you have opened it 2 years ago. It was closed to no feedback. https://github.com/domoticz/domoticz/issues/5437

But if it it still an issue better create a new issue based on latest beta and give some examples so it can be reproduced.
I am not running beta but 2024.7

Once I collect a few examples over the comming days I will share in a new opened issue on github and
I will also share a small python program that can check the database and will list the errors.
All one has to do is indicate the device idx of a P1 device or a kWh device.
willemd
Posts: 631
Joined: Saturday 21 September 2019 17:55
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.1
Location: The Netherlands
Contact:

Re: Value of managed counter is visible in the devices tab, but not stored in the database

Post by willemd »

waltervl wrote: Tuesday 20 August 2024 18:38 But if it it still an issue better create a new issue based on latest beta and give some examples so it can be reproduced.
Issue created included example dbase entries and python program to check for this issue.
https://github.com/domoticz/domoticz/issues/6143
Post Reply

Who is online

Users browsing this forum: Toulon7559 and 1 guest