Skip to content

Commit dec81bf

Browse files
committed
Measurements for month are now available by day
1 parent 7ee1241 commit dec81bf

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ This channel contains values polled from SENEC App-API.
306306

307307
### **WORK IN PROGRESS**
308308
- Measurements for today and yesterday are also available by the hour
309+
- Measurements for month and previous month are also available by day
309310
- Dependency update
310311

311312
### 2.2.2 (2026-02-06)

main.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,9 @@ class Senec extends utils.Adapter {
595595
await this.doMeasurementsDay(anlagenId, token, yesterday, "yesterday");
596596
await this.doMeasurementsDay(anlagenId, token, yesterday, "yesterday.hourly");
597597
await this.doMeasurementsMonth(anlagenId, token, currentMonth, "current_month");
598+
await this.doMeasurementsMonth(anlagenId, token, currentMonth, "current_month.daily");
598599
await this.doMeasurementsMonth(anlagenId, token, lastMonth, "previous_month");
600+
await this.doMeasurementsMonth(anlagenId, token, lastMonth, "previous_month.daily");
599601
await this.doMeasurementsYear(anlagenId, token, now.getUTCFullYear()); // Current year
600602
await this.doMeasurementsYear(anlagenId, token, now.getUTCFullYear() - 1); // check if we need last year too
601603
}
@@ -708,7 +710,7 @@ class Senec extends utils.Adapter {
708710
!isNaN(lastDate.getTime()) &&
709711
lastDate.getUTCFullYear() === new Date().getUTCFullYear()
710712
) {
711-
this.log.debug(`Measurements for year ${year} already updated this year. Skipping.`);
713+
this.log.debug(`Measurements for ${year} already updated this year. Skipping.`);
712714
return;
713715
}
714716
} else {
@@ -721,7 +723,7 @@ class Senec extends utils.Adapter {
721723
lastDate.getUTCMonth() === new Date().getUTCMonth() &&
722724
lastDate.getUTCDate() === new Date().getUTCDate()
723725
) {
724-
this.log.debug(`Measurements for current year already updated today. Skipping.`);
726+
this.log.debug(`Measurements for ${year} already updated today. Skipping.`);
725727
return;
726728
}
727729
}
@@ -751,9 +753,9 @@ class Senec extends utils.Adapter {
751753
* @param {string} period period to sum for
752754
*/
753755
async doMeasurementsMonth(anlagenId, token, date, period) {
754-
this.log.debug(`🔄 Reading measurements for month.`);
756+
this.log.debug(`🔄 Reading measurements for ${period}.`);
755757
const pfx = `${API_PFX}Anlagen.${anlagenId}.` + `Measurements.Monthly.`;
756-
if (period === "previous_month") {
758+
if (period === "previous_month" || period === "previous_month.daily") {
757759
// check if already updated this month
758760
const lastUpdate = await this.getStateAsync(`${pfx + period}.${LAST_UPDATED}`);
759761
if (lastUpdate && lastUpdate.val !== null && lastUpdate.val !== undefined) {
@@ -764,7 +766,7 @@ class Senec extends utils.Adapter {
764766
lastDate.getUTCFullYear() === new Date().getUTCFullYear() &&
765767
lastDate.getUTCMonth() === new Date().getUTCMonth()
766768
) {
767-
this.log.debug(`Measurements for previous month already updated this month. Skipping.`);
769+
this.log.debug(`Measurements for ${period} already updated this month. Skipping.`);
768770
return;
769771
}
770772
}
@@ -773,7 +775,11 @@ class Senec extends utils.Adapter {
773775
const endDate = new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth() + 1, 1) - 1);
774776
const start = encodeURIComponent(startDate.toISOString());
775777
const end = encodeURIComponent(endDate.toISOString());
776-
const url = `${HOST_MEASUREMENTS}/v1/systems/${anlagenId}/measurements?resolution=MONTH&from=${start}&to=${end}`;
778+
let resolution = "MONTH";
779+
if (period === "current_month.daily" || period === "previous_month.daily") {
780+
resolution = "DAY";
781+
}
782+
const url = `${HOST_MEASUREMENTS}/v1/systems/${anlagenId}/measurements?resolution=${resolution}&from=${start}&to=${end}`;
777783
this.log.debug(`🔄 Polling measurements for ${url}`);
778784
const measurements = await axiosApi.get(url, {
779785
headers: { Authorization: `Bearer ${token}` },
@@ -790,7 +796,7 @@ class Senec extends utils.Adapter {
790796
* @param {string} period period to sum for
791797
*/
792798
async doMeasurementsDay(anlagenId, token, date, period) {
793-
this.log.debug(`🔄 Reading measurements for ${period}.`);
799+
this.log.debug(`🔄 Reading measurements for ${period}`);
794800
const pfx = `${API_PFX}Anlagen.${anlagenId}.` + `Measurements.Daily.`;
795801
if (period === "yesterday" || period === "yesterday.hourly") {
796802
// check if already updated today
@@ -845,6 +851,11 @@ class Senec extends utils.Adapter {
845851
sums[key] = Array(24).fill(0);
846852
}
847853
sums[key][new Date(entry.date).getHours()] += value;
854+
} else if (period === "current_month.daily" || period === "previous_month.daily") {
855+
if (!sums[key]) {
856+
sums[key] = Array(32).fill(0);
857+
}
858+
sums[key][new Date(entry.date).getDate()] += value;
848859
} else {
849860
sums[key] += value;
850861
}

0 commit comments

Comments
 (0)