Power Meter / Energy per Day / Date Problem

I have the same meter and also using MBMD, so familiar issues :wink:

You have a couple of things going on:

First you can get the actual Kwh meter count from the SDM630 by using the “import” field. You can then use the difference between the registrations at the end of all days. That is more accurate then trying to integrate the instant Power over time.

Secondly, you have an issue with timezones. As you can see it now aggregates using 00:00 UTC while you seem to be at UTC+2.

Third, you query now uses a different time range, depending when you execute this, so beware to pick the good time range manually (which you can not do if you would execute this as a task).

I ran also into the timezone and range issues, especially trying to automate this using a Task, see also the discussion here

This is how I solved this in my task, that produces the usage and the end-meter value and runs every day:

import "timezone"
import "experimental"


option location = timezone.location(name: "Europe/Amsterdam")

startoffset = 2d
tzoffset = 0h
start = experimental.subDuration(d: startoffset, from: today())
stop = experimental.subDuration(d: tzoffset, from: today())

data =
    from(bucket: "telegraf")
        |> range(start: start, stop: stop)
        |> filter(fn: (r) => r["_measurement"] == "data")
        |> filter(fn: (r) => r["_field"] == "value")
        |> filter(fn: (r) => r["device"] == "SDM1.1")
        |> filter(fn: (r) => r["type"] == "Import")

data
    |> aggregateWindow(every: 1d, fn: last, createEmpty: false, location: timezone.location(name: "Europe/Amsterdam"))
    |> map(fn: (r) => ({r with _endvalue: r._value}))
    |> difference(nonNegative: true, columns: ["_value"], keepFirst: false)
    |> map(fn: (r) => ({usage: r._value, endvalue: r._endvalue, _time: r._time, _measurement: "solar_daily"}))
    |> timeShift(duration: -1d)

Hope this helps!

4 Likes