Add template sensor created in configuration.yaml to history graph

Hi,

as a newbie I’m stuck using my template sensor that I added in configuration.yaml.
This sensor is not accessible creating a history graph.

The code I added to configuration.yaml:

# Sensor Temperatur Büro von Fritz!Dect 301
  - platform: template
    sensors:
     temperatur_buro_fritz_current:
       friendly_name: "Temperatur Büro"
       value_template: "{{ state_attr('climate.heizung_buro', 'current_temperature') }}"
       unit_of_measurement: "°C"
       device_class: temperature
       unique_id : temperatur_buro_fritz_dect_301

What additional lines do I have to add to make this sensor accessible and show the statistics in history graph?

Could someone please help me providing the full code for me to paste into configuration.yaml? Or do I have to add lines to another file in Home Assistant?

Thx for your patience!

You need to add a state_class

# Sensor Temperatur Büro von Fritz!Dect 301
  - platform: template
    sensors:
     temperatur_buro_fritz_current:
       friendly_name: "Temperatur Büro"
       value_template: "{{ state_attr('climate.heizung_buro', 'current_temperature') }}"
       unit_of_measurement: "°C"
       device_class: temperature
       state_class: measurement
       unique_id : temperatur_buro_fritz_dect_301

Thanks for helping :grinning:

When I add “state_class: measurement” as you suggested I get the following error:

Invalid config for [sensor.template]: [state_class] is an invalid option for [sensor.template]. Check: sensor.template->sensors->temperatur_buro_fritz_current->state_class. (See ?, line ?).

Anything else I can try?