Statistics-graph for template sensor value does not work

I have set up a template sensor to convert station level air pressure to sea level like this:

template:
  - sensor:
    - name: "Pressure sea level"
      unique_id: "pressure_red"
      state: |-
        {%- set h = 123.0 %}
        {%- set p = states('sensor.outdoor_pressure') | float %}
        {%- set phi = 0.01 * (states('sensor.outdoor_humidity') | float) %}
        {%- set t = (states('sensor.outdoor_temperature') | float) %}
        {%- set T = 273.15 + t %}
        {%- set E = phi * 6.112 * e**((17.62 * t) / (243.12 + t)) %}
        {%- set x = (9.80665 / (287.05* (T + 0.12 * E + 0.0065 * (h / 2)))) * h %}
        {{ (p * e**x) | round(2) }}
      unit_of_measurement: 'hPa'
      device_class: "pressure"
      state_class: "measurement"
      icon: "mdi:gauge"

Then I would like to add a new statistics-graph to plot the two:

chart_type: line
period: hour
days_to_show: 2
type: statistics-graph
entities:
  - entity: sensor.outdoor_pressure
    name: statniv.
  - entity: sensor.pressure_sea_level
    name: reduz.
stat_types:
  - mean
  - min
  - max
title: Luftdruck

However, only the sensor.outdoor_pressure shows up, the sensor.pressure_sea_level not.

Using a history graph works perfectly:

type: history-graph
entities:
  - entity: sensor.pressure_sea_level
    name: reduz.
  - entity: sensor.outdoor_pressure
    name: statniv.

What might be the issue here? Is this also related to this bug: Expected data source not listed - Home Assistant
However, it turns up in the list when setting device_class and state_class.

Verify that your entity_id is correct, and if it is, wait until the database is filled up enough for the statistics to work.

ahhh :man_facepalming: Okay, now values are turning up! thanks!

I see what the problem was: if device_class and state_class are not set, you get the same “error” as if there is no data yet. That’s why I was confused. I forgot to set the classes before and was given the error, then I set it and had the same message…