Control a water heater and ground source heat pump based on cheap hours of spot priced electricity

@timo12357 The typo is now fixed but it’s getting late so I didn’t have time for the UI write-up.

I checked my old notes and here are the tutorials / docs that you might find useful. openHabian OS would have Grafana pre-installed but I understood you are not using it.

Setting this up:

• Remember to set the Authorization header in Grafana data sourcen settings

When it comes to the actual graphs, here are a couple of queries that you might find useful:

Consumption vs. spot prices

I fetch the consumption data from Caruna with GitHub - kimmolinna/pycaruna: Caruna API for Python and store it InfluxDB as “caruna_consumption” measrument.

Queries in plain text:

from(bucket: "openhab")
  |> range(start: v.timeRangeStart, stop:v.timeRangeStop)
  |> filter(fn: (r) =>
      r._measurement == "caruna_consumption" and 
      r._field == "value"
      )
  |> map(fn: (r) => ({ _value:r._value, _time:r._time, _field:"Sähkön kulutus (kWh)" }))

And the second one:

from(bucket: "openhab")
  |> range(start: v.timeRangeStart, stop:v.timeRangeStop)
  |> filter(fn: (r) =>
      r._measurement == "spot_price" and
      r._field == "value"
      )
  |> map(fn: (r) => ({ _value:r._value, _time:r._time, _field:"Sähkön tuntihinta (c/kWh)" }))

Spot prices and the control values


The spot prices you already have above, it’s just visualized as a bar chart here but the query is the same

Control values that are rendered below:

from(bucket: "openhab")
  |> range(start: v.timeRangeStart, stop:v.timeRangeStop)
  |> filter(fn: (r) =>
      r._measurement == "nibe_control" and 
      r._field == "value"
      )
  |> map(fn: (r) => ({ _value:r._value, _time:r._time, _field:"Maalämpöpumpun kompressori" }))

Average price of the day:

You need to change the Grafana “visualization” as a “Stat”

from(bucket: "openhab")
  |> range(start: v.timeRangeStart, stop:v.timeRangeStop)
  |> filter(fn: (r) =>
      r._measurement == "spot_price" and 
      r._field == "value"
      )
  |>mean()

Table of spot prices:
Same query as for the line / bar chart, but change the “visualization” as “Table”

Embedding the graphs to OpenHab pages
See the link in the bottom of comment #13 on how to create pages in OpenHab and how to embedd the Grafana dashboards as an “Web Frame” (which means an iframe in practice, if you are familiar with iframes)