Sensor data not showing in Statistics Graph

Hello,
I’m very new to the world of home assistant, be gentle :slight_smile:
I’m trying to create a plot with data from my own temperature sensors and the publicly available bureau of meteorology.
In Developer Tools / States I can find those 4 entities:

- sensor.entrance_sensor_temperature
- sensor.living_room_sensor_temperature
- sensor.upstairs_office_temperature
- sensor.weather_temperature

They all show a sensible number under State and have the following Attributes

- unit_of_measurement: °C
- device_class: temperature
- friendly_name: <A friendly name>

The first 3 also have:
- state_class: measurement

sensor.weather_temperature is coming from my sensors.yaml, which I’ve included in my configuration.yaml via sensor: !include sensors.yaml. It looks like this:

- platform: template
  sensors:
    weather_temperature:
      friendly_name: "Weather Temperature"
      unit_of_measurement: "°C"
      device_class: "temperature"
      value_template: "{{ state_attr('weather.marmion', 'temperature') }}"

I have made a new view in my Dashboard of type “Panel”. It’s using card_mod and looks like this:

type: vertical-stack
cards:
  - type: statistics-graph
    chart_type: line
    title: Day
    period: 5minute
    days_to_show: 1
    entities:
      - entity: sensor.living_room_sensor_temperature
        name: Living Room
      - entity: sensor.entrance_sensor_temperature
        name: Entrance
      - entity: sensor.upstairs_office_sensor_temperature
        name: Upstairs
      - entity: sensor.weather_temperature
        name: Outside
    stat_types:
      - max
    card_mod:
      class: middle
  - type: statistics-graph
    chart_type: line
    title: Week
    period: hour
    days_to_show: 7
    entities:
      - entity: sensor.living_room_sensor_temperature
        name: Living Room
      - entity: sensor.entrance_sensor_temperature
        name: Entrance
      - entity: sensor.upstairs_office_sensor_temperature
        name: Upstairs
      - entity: sensor.weather_temperature
        name: Outside
    stat_types:
      - max
    card_mod:
      class: middle

Unfortunately, I can’t get the data from sensor.weather_temperature to show:

What am I missing?

1 Like

You’ll need to add its state_class as measurement in order for statistics to process it.

I tried that.
When I change my sensor config to this:

- platform: template
  sensors:
    weather_temperature:
      friendly_name: "Weather Temperature"
      unit_of_measurement: "°C"
      device_class: "temperature"
      state_class: "measurement"
      value_template: "{{ state_attr('weather.marmion', 'temperature') }}"

I’m getting the following error when I check my configuration:
Invalid config for [sensor.template]: [state_class] is an invalid option for [sensor.template]. Check: sensor.template->sensors->weather_temperature->state_class. (See ?, line ?).

You are using the old style template definition. Try using the new style.


# Example configuration.yaml entry with two sections
template:
  # Define state-based template entities
  - sensor:
      ...

Yep. This is why you don’t use the old style template sensors. Even though they still work they do not support new features, like in this case, long term statistics.

1 Like

Thanks for your input, @PeteRage and @tom_l
Using the new style fixed it. :+1:

1 Like