Page 1 of 1
Value of managed counter is visible in the devices tab, but not stored in the database
Posted: Saturday 17 August 2024 14:47
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 (24.76 KiB) Viewed 787 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 (10.15 KiB) Viewed 787 times
The graph as well as the report remains empty:

- Edit device.png (24.76 KiB) Viewed 787 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?
Re: Value of managed counter is visible in the devices tab, but not stored in the database
Posted: Sunday 18 August 2024 10:19
by peterchef
Hi
I think you need to use .updateHistory to update the values
https://www.domoticz.com/wiki/DzVents:_ ... ncremental
Re: Value of managed counter is visible in the devices tab, but not stored in the database
Posted: Sunday 18 August 2024 17:02
by jvdk
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.
Re: Value of managed counter is visible in the devices tab, but not stored in the database
Posted: Sunday 18 August 2024 17:55
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.
Re: Value of managed counter is visible in the devices tab, but not stored in the database
Posted: Monday 19 August 2024 20:07
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!
Re: Value of managed counter is visible in the devices tab, but not stored in the database
Posted: Tuesday 20 August 2024 10:58
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
Re: Value of managed counter is visible in the devices tab, but not stored in the database
Posted: Tuesday 20 August 2024 14:33
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).
Re: Value of managed counter is visible in the devices tab, but not stored in the database
Posted: Tuesday 20 August 2024 16:04
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.
Re: Value of managed counter is visible in the devices tab, but not stored in the database
Posted: Tuesday 20 August 2024 18:38
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.
Re: Value of managed counter is visible in the devices tab, but not stored in the database
Posted: Tuesday 20 August 2024 19:49
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.
Re: Value of managed counter is visible in the devices tab, but not stored in the database
Posted: Friday 23 August 2024 13:49
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