Method 1: Default Iotawatt, Seperate Database
IotaWatt data will be stored:
-
Measurement: Power,Lights,Aircon, , power2, etc
-
FieldName: "value", FieldKey: measured-value
Setup IotaWatt
Use defaults on IotaWatt
- Set a tag with device = "$device".
- Add a "Total" to be reported to InfluxDB
- Add "Export/Import" to be reported to InfluxDB
- Add "PowerTotal" or "AirconTotal" if you have multiple circuits of one type.
Use one database per IotaWatt:
create database iotawatt
use iotawatt
grant all to your-user
Setup continuous queries
For each of the Measurements, create a continuous query. Note the use of "fill(0)" to ensure integral functions work as expected later.
create continuous query LightskWhh on iotawatt begin SELECT integral("value",1000h) into LightskWhh FROM "Lights" GROUP BY time(1h) fill(0) tz('Australia/Brisbane') end
Grafana
Add helper variables:
- $timezone = tz('Australia/Brisbane'
Energy from power, totalling everything. Add "groupby time (1d)" for daily energy.
SELECT integral("value",1000h) FROM "Total" WHERE $timeFilter fill(0) $timezone
Get energy-per-day with the Continuous Query's "Powerkwhh" which has already done the integration.
SELECT sum("integral") FROM "PowerkWhh" WHERE $timeFilter GROUP BY time(1d) fill(0) $timezone
Get average energy-per-day with the Continuous Query's "Powerkwhh" which has already done the integration.
select mean(sum) from (SELECT sum("integral") FROM "PowerkWhh" WHERE $timeFilter GROUP BY time(1d)) group by time($graphinterval) fill(0) tz('Australia/Brisbane')
Method 1b: Default Iotawatt, Seperate Database : Variation with Retention Period
As for 1a, except to limit typing, we use retention policy (just for the grouping) and wildcards. This is good for sites with many measurements (>7).
create retention policy inf_kwhperhour on iotawyatt duration INF replication 1
> CREATE CONTINUOUS QUERY kwhperhour ON iotawyatt BEGIN SELECT integral(*, 1000h) INTO iotawyatt.inf_kwhperhour.:MEASUREMENT FROM iotawyatt.autogen./.*/ GROUP BY time(1h), * END