Temperature chart: showing HeatingState along with temperatures

A follow up on the graphs of the How to customize a Rule tutorial

I successfully set up Influxdb and Grafana in a separate OpenHab instance, and manage to generate @rlkoshak’s graphics with the temperatures. However, I cannot add the HeatingState status, which is ON/OFF in the database. Maybe I should Flux for the mapping? Or use a proxy number item before values are stored?

InfluxDB should store the on/off states as 1 and 0 respectively. So I add them to the chart with a second Y-axis in Grafana with a fixed range of 0 to 2 or 3.

I think this is not my case:

> SELECT value FROM HeatingState
name: HeatingState
time                value
----                -----
1609203600909000000 OFF
1609205662426000000 ON
1609206336431000000 OFF
1609207200911000000 OFF
1609209231059000000 ON
1609209935331000000 OFF

Maybe the How to integrate with another OH Instance needed some tweaks? :thinking:

Finally I went for the Flux option, because I considered it is Grafana’s responsibility to draw it right :slight_smile:

The code in Flux for transforming and drawing HeatingState

from(bucket: v.defaultBucket)
  |> range(start: v.timeRangeStart, stop:v.timeRangeStop)
  |> filter(fn: (r) =>
    r._measurement == "HeatingState" and
    r._field == "value"
  )
  |> map(fn: (r) => ({r with _value:if r._value == "ON" then 1 else 0 }))
  |> fill(column: "_value", usePrevious: true)
  |> set(key: "_field", value: "")
  |> set(key: "_measurement", value: "Calefacción")

I made a blog post on how to setup the graphics with Grafana, InfluxDB and Flux. I was just on time to catch the greatest snowstorm in Madrid in the last 60 years!

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.