Showing a current value

  • What Grafana version and what operating system are you using?

Grafana 9.2.2 on Fedora 35

  • What are you trying to achieve?

In a graph I display the setting of a thermostat.

  • How are you trying to achieve it?

I use Graph types > Line interpolation > Step after.

  • What happened?

The thermostat setting is only displayed when the value changes. E.g. if the setting is 15 and goes to 20 at 08:00, the graph has a vertical line from 15 to 20 at 08:00.

  • What did you expect to happen?

What I would like to happen is a way to obtain a horizontal line at 20 from 08:00 to the current time. The actual setting at e.g. 10:00 is still 20 and will remain 20 until the next value change.

Is this possible?

What is your datasource and can you share the query you have written thus far?

Datasource is a PostgreSQL database.

The query I currently use is

SELECT
  $__time(last_updated),
  state ::decimal as "heating temp"
FROM states
WHERE
  $__timeFilter(last_updated)
  AND entity_id = 'number.boiler_heating_temperature'
  AND state ~ '^[-0-9.]+$'
ORDER BY 1

I know I can artificially add a final value, e.g.

SELECT
  $__time(last_updated),
  state ::decimal as "heating temp"
FROM states
WHERE
  $__timeFilter(last_updated)
  AND entity_id = 'number.boiler_heating_temperature'
  AND state ~ '^[-0-9.]+$'
UNION
(SELECT
   now(),
   state ::decimal as "heating temp"
 FROM states
 WHERE
   entity_id = 'number.boiler_heating_temperature'
   AND state ~ '^[-0-9.]+$'
 ORDER BY last_updated DESC LIMIT 1)
ORDER BY 1

but I hope there is an easier (nicer) way to handle this particular kind of graphs.

The question should be extended to ‘how to display values that fall outside of the selected region’.
For example, a particular setting changes to 40 on november 20 08:00 and to 50 on november 25 21:00. When a graph is displayed for the period november 22 0:00 - 24:00 nothing is displayed as there are no data points. The setting does have a value in this period, 40, and when using a line type graph it should be possible to show a horizontal line at 40 spanning the region.