Electricity consumption & cost per day, month and year  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

User avatar
McMelloW
Posts: 434
Joined: Monday 20 November 2017 17:01
Target OS: Raspberry Pi / ODroid
Domoticz version: V2024.1
Location: Harderwijk, NL
Contact:

Re: Electricity consumption & cost per day, month and year

Post by McMelloW »

mojso wrote: Friday 21 June 2024 13:17 I made a change in the script, in line 150, 158, 167
if you plan to update domoticz immediately, you can do it before or after,
I have last beta update of Domoticz
Thanks a lot It works OK now.
Greetings McMelloW
User avatar
McMelloW
Posts: 434
Joined: Monday 20 November 2017 17:01
Target OS: Raspberry Pi / ODroid
Domoticz version: V2024.1
Location: Harderwijk, NL
Contact:

Missing 5 days - Electricity consumption & cost per day, month and year

Post by McMelloW »

These 2 lines (179-180) in the source code

Code: Select all

            dz.log('daysCounterMonth: '  .. daysCounterMonth, dz.LOG_DEBUG)
            dz.log('daysCounterYear: '  .. daysCounterYear, dz.LOG_DEBUG)
Showing these results in the domoticz log

Code: Select all

2024-06-21 19:39:00.579  Status: dzVents: Debug: ElecConsCost: daysCounterMonth: 16
2024-06-21 19:39:00.579  Status: dzVents: Debug: ElecConsCost: daysCounterYear: 168
Today it is day 173 of 2024 and day 21 of June so I miss 5 days of the year and of the month. The date on my Raspberry Pi is the actual date & time. It is also synchronized with ntp

Does somebody has an explanation for this difference.
Greetings McMelloW
User avatar
waltervl
Posts: 6676
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2025.1
Location: NL
Contact:

Re: Electricity consumption & cost per day, month and year

Post by waltervl »

It seems to count the number of entries in the database. So probably Domoticz did not register your energy every day.
Do you see gaps in the graphs of your original energy devices?
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
McMelloW
Posts: 434
Joined: Monday 20 November 2017 17:01
Target OS: Raspberry Pi / ODroid
Domoticz version: V2024.1
Location: Harderwijk, NL
Contact:

Re: Electricity consumption & cost per day, month and year

Post by McMelloW »

waltervl wrote: Friday 21 June 2024 20:29 It seems to count the number of entries in the database. So probably Domoticz did not register your energy every day.
Do you see gaps in the graphs of your original energy devices?
Yes there are gaps in these devices. I had to go back 5 days after an updatebeta. This causes the gaps in the database.
The energy data consumed and delivered is registered by my energy provider as I can see.

I had the impression the days and month were just counted by de calendar. But it is not.
Greetings McMelloW
hyeronimo
Posts: 68
Joined: Saturday 11 March 2023 8:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Electricity consumption & cost per day, month and year

Post by hyeronimo »

Hi, I am using this script to display daily and cumulative electricty cost in my dashticz dashboard. Recently I have moved to latest beta and new hardware, and now the script is not working any more. I have changed v into v1, bit that does not seem to help.
The log error:

Code: Select all

2025-10-04 09:52:00.247 Error: Error opening url: http://127.0.0.1:8080/json.htm?type=graph&sensor=counter&range=year&idx=249
2025-10-04 09:52:00.319 Error: dzVents: ElectricityConsumptionAndCost: HTTP/1.1 response: 404 ==>> Not Found 
249 is the P1_DSMR.

Also I do not know how I can use the calculated cost from the energy dashboard. For the script I created several dummy devices for the output, so i can use the data where I want.
User avatar
waltervl
Posts: 6676
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2025.1
Location: NL
Contact:

Re: Electricity consumption & cost per day, month and year

Post by waltervl »

Your script makes use of a Domoticz API call and those have been changed. See this wiki page how to fix this https://wiki.domoticz.com/Domoticz_API/ ... and_newer)
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
hyeronimo
Posts: 68
Joined: Saturday 11 March 2023 8:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Electricity consumption & cost per day, month and year

Post by hyeronimo »

Thanks Walter, I will go from there!
hyeronimo
Posts: 68
Joined: Saturday 11 March 2023 8:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Electricity consumption & cost per day, month and year

Post by hyeronimo »

Working again! For those who want the updated script:
electricity_usage_cost_script.txt
(11.25 KiB) Downloaded 26 times
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest