How to calculate year usage

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.

Moderators: leecollings, remb0

Post Reply
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: How to calculate year usage

Post by waaren »

LenaLoyd wrote: Tuesday 30 June 2020 8:21 is it possible to calculate the year usage for electricity, gas,... based on a day to day calculation?
Yes that's possible using this API call.

Code: Select all

http://<domoticz ip:domoticz port>/json.htm?type=graph&sensor=counter&idx=<P1 energy id>&range=year
will give you the required data in a format like
Spoiler: show

Code: Select all

{
"ValueQuantity": "",
"ValueUnits": "",
"delivered": true,
"result": [
{
"c1": "7728.920",
"c2": "3442.223",
"c3": "5543.880",
"c4": "7789.626",
"d": "2019-06-30",
"r1": "19.460",
"r2": "0.000",
"v": "6.635",
"v2": "0.000"
},
{
"c1": "7735.604",
"c2": "3461.683",
"c3": "5543.880",
"c4": "7789.626",
"d": "2019-07-01",
"r1": "0.000",
"r2": "21.117",
"v": "3.741",
"v2": "3.093"
},
..........
{
"c1": "9849.203",
"c2": "4294.328",
"c3": "7038.254",
"c4": "9823.464",
"d": "2020-06-27",
"r1": "10.855",
"r2": "0.000",
"v": "6.081",
"v2": "0.000"
},
{
"c1": "9855.323",
"c2": "4305.183",
"c3": "7038.254",
"c4": "9823.464",
"d": "2020-06-28",
"r1": "18.142",
"r2": "0.000",
"v": "7.028",
"v2": "0.000"
},
{
"c1": "9862.351",
"c2": "4323.325",
"c3": "7038.254",
"c4": "9823.464",
"d": "2020-06-29",
"r1": "0.000",
"r2": "9.190",
"v": "3.179",
"v2": "2.434"
},
{
"c1": "9865.530",
"c2": "4323.325",
"c3": "7040.688",
"c4": "9832.654",
"d": "2020-06-30",
"r1": "0.000",
"r2": "0.250",
"v": "2.707",
"v2": "0.273"
}
],
"resultprev": [
{
"d": "2018-06-30",
"r1": "22.800",
"r2": "0.000",
"v": "4.831",
"v2": "0.000"
},
{
"d": "2018-07-01",
"r1": "26.374",
"r2": "0.000",
"v": "6.117",
"v2": "0.000"
},
.......
{
"d": "2019-06-28",
"r1": "0.000",
"r2": "21.360",
"v": "3.945",
"v2": "2.133"
},
{
"d": "2019-06-29",
"r1": "23.213",
"r2": "0.000",
"v": "5.381",
"v2": "0.000"
},
{
"d": "2019-06-30",
"r1": "19.460",
"r2": "0.000",
"v": "6.635",
"v2": "0.000"
}
],
"status": "OK",
"title": "Graph counter year"
}
You can process this with dzVents or any other script language.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
jvdz
Posts: 2445
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: How to calculate year usage

Post by jvdz »

That will give you the last year and previous year data as of today. Previous year data doesn't contain the counter values so you can't use the 2 dates counter values and simply subtract. So when you need the years data for a date in the past you probably need to make this API call for the 2 different years and get the counters data for the start and end dates.

Jos
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: How to calculate year usage

Post by waaren »

jvdz wrote: Tuesday 30 June 2020 10:20 That will give you the last year and previous year data as of today. Previous year data doesn't contain the counter values so you can't use the 2 dates counter values and simply subtract. So when you need the years data for a date in the past you probably need to make this API call for the 2 different years and get the counters data for the start and end dates.
On my system this call gives me the last 365 days with counter(s) and volumes in result and day minus 730-365 with volumes in resultprev.
So by looping over the volumes you will get what you look for using one call.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
jvdz
Posts: 2445
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: How to calculate year usage

Post by jvdz »

So that means we are in agreement... the previous years doesn't have the counter values, so you need to add all individual day values together to get to the total in stead of taking the start and end counter value aand subtract them. ;)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest