Add counter/sensor to Long-term Statistics

Hey,
Can anybody help me how to add my counters and my
energy_cost - sensors to the long term statistics?
Their unit_of_measurement would be ‘€’ and no measurement

Thanks

1 Like

To be included in LTS a sensor must have an appropriate state_class. It is not possible to include counters. Only sensors.

OK, so I have to create a sensor with the state_class measurement that saves my values.

No, you can add the attribute to your existing sensors either directly if they support it, or by using customize.

Sorry but I can’t get it.
That’s my configuration:

homeassistant:
  customize:
    counter.huhnereier_tag:
         state_class: measurement
    sensor.daily_energy_cost:
         state_class: measurement
         device_class: monetary

They’re both showed with these attributes, but won’t work with statistics.

Pretty sure the counter does not support a state_class. That’s only for sensors.

Your sensor should begin to accumulate LTS.

Finally solved it
with (configuration.yaml)

homeassistant:
  customize:
    sensor.eier_daily:
         state_class: measurement

and (sensor.yaml)

- platform: template
  sensors:
    eier_daily:
      friendly_name: Eier Tag
      value_template: "{{ states('counter.huhnereier_tag') }}"

Thank you :pray:

7 Likes

This helped me, thanks

Could you not have just added this under the sensor definition instead of adding a separate customize entry?

I’m also curious about that.