Hello,
I’m new to flux language and I’m having trouble making an energy meter.
At the moment, the currently measured power (kW) of all 3 phases is sent every 5 seconds with MQTT.
The tables look like this:
Date/Time P_L1_kW P_L2_kW P_L3_kW
actual actual actual
Power Power Power
L1 L2 L3
2023-01-17 11:33:30 14.0 kW 13.0 kW 16.4 kW
2023-01-17 11:33:35 14.4 kW 13.0 kW 12.4 kW
2023-01-17 11:33:40 16.4 kW 11.0 kW 13.4 kW
2023-01-17 11:33:45 16.7 kW 15.0 kW 15.4 kW
The query looks like this:
from(bucket: "POWER")
|> range(start: -7d)
|> filter(fn: (r) => r["_measurement"] == "mqtt_influx")
|> filter(fn: (r) => r["host"] == "srv-mon1")
|> filter(fn: (r) => r["topic"] == "AKT_P_L3_kW" or
r["topic"] == "AKT_P_L2_kW" or
r["topic"] == "AKT_P_L1_kW")
|> toFloat() // -- string to float EXTREMELY SLOW!!!!!!!!!!!!!!!
|> aggregateWindow(fn: mean, every: 1h, createEmpty: false) // -- calculate kWh = 1h mean
|> aggregateWindow(fn: sum, every: 1d, createEmpty: true) // -- calculate sum kWh per day
|> group(columns: ["_time"], mode:"by") // -- group the 3 datasets (L1-L3) to one
|> sum() // -- sum up all the data
|> group() // -- to ungroup your data provide a group without any columns
|> yield(name: "sum_kWh_a_day") // -- dataset is +1 day, because ?!
This is the Bar Chart:
My Questions:
- the transformation toFloat() is very slow, I don’t know how to fix this (in telegraph?)
- why are the days shifted by +1 and the time is 01:00 ?
.
Any help is welcome,
thank you in advance!
BG Armin