How can I add 'total_increasing' to my template sensor

I have several template sensor created to work with the energy dashboard, work without problems and looks like it still works. But on the energy configuration page I get this info

How do I need to update my template so this message disappears, or can I ignore it? I would prefer not to have any warnings or errors showing up :slight_smile:

Here is the code I have atm for my template sensor

template:
  - trigger:
      - platform: time_pattern
        hours: 0
        minutes: 0
    sensor:
      - name: "Laptop"
        unique_id: "laptop_daily_energy"
        unit_of_measurement: "kWh"
        state_class: measurement
        device_class: energy
        state: '{{ states("sensor.laptop_total_daily_energy") | float }}'
        attributes:
          last_reset: '{{ now().year }}-{{ now().month }}-{{ now().day }}T00:00:00+00:00'

  - sensor:
      - name: "Laptop"
        unique_id: "laptop_daily_energy"
        unit_of_measurement: "kWh"
        state_class: measurement
        device_class: energy
        state: '{{ states("sensor.laptop_total_daily_energy") | float }}'
        attributes:
          last_reset: '{{ now().year }}-{{ now().month }}-{{ now().day }}T00:00:00+00:00'

Can anybody help here?

What version of home assistant are you running?

The new 2021.9.0

last_reset: is no longer a valid attribute. Delete it.

For the state_class:

State classes#

There are 2 defined state classes:

  • measurement, the state represents a measurement in present time, for example a temperature, electric power, the value of a stock portfolio, etc. For supported sensors, statistics of hourly min, max and average sensor readings or of the accumulated growth or decline of the sensor’s value since it was first added is updated hourly.
  • total_increasing, a monotonically increasing total, e.g. an amount of consumed gas, water or energy. When supported, the accumulated growth of the sensor’s value since it was first added is updated hourly.

STATE_CLASS_TOTAL_INCREASING #

For sensors with state_class STATE_CLASS_TOTAL_INCREASING, a decreasing value is interpreted as the start of a new meter cycle or the replacement of the meter. It is important that the integration ensures that the value cannot erroneously decrease in the case of calculating a value from a sensor with measurement noise present. This state class is useful for gas meters, electricity meters, water meters etc.

The sensor’s state when it’s first added to Home Assistant is used as an initial zero-point. When a new meter cycle is detected the zero-point will be set to 0. Please refer to the tables below for how this affects the statistics.

https://developers.home-assistant.io/blog/2021/08/16/state_class_total/

As you have an energy sensor, use state_class: total_increasing

1 Like

so “last_reset” is deprecated again? OK missed that, will remove id. And will change the state class.

Thx

Is not available. Measurement is. Any idea on how I can change the state class?

What version are you on?

total_increasing was introduced in 2021.9

Hi Tom,

I’m on 2021.9. Got 7 PWM sensors that all throw errors regarding the total_increasing state class.

:man_shrugging: You could ask in the release notes topic.

@Abeltje I am also on 2021.9.0 an could change from Measurement without problems to total_increasing. So be sure you are really using latest version.

Your issue is solved then?

If so, please mark the post that helped as the solution.

What I see for now, yes. Will need to check the next days if the sensors still work correct.

Weird. I’m am indeed on the latest version! I managed to get it right from within the customize.yaml :+1:t2:

To eliminate the warning message " Unsupported status class. The following objects do not have the expected 'total_increasing’state class: "
image
You need to specify total_increasing instead of measurement. This is done via customize. We specify the sensor we need for which we received a warning and specify state_class: total_increasing

This is how it should look in customize

sensor.koridor_rele_shkaf_kupe_energy:
  state_class: total_increasing

Restart the Home Assistant. After that, this warning will disappear
image

Текст на русском (Text in Russian)

Чтобы устранить предупреждающее сообщение “Неподдерживаемый класс состояния
Следующие объекты не имеют ожидаемого класса состояния ‘total_increasing’:
image
Нужно вместо measurement указать total_increasing. Делается это через customize. Указываем нужный нам сенсор для которого мы получили предупреждение и указываем state_class: total_increasing

Вот так должно выглядеть в customize

sensor.koridor_rele_shkaf_kupe_energy:
  state_class: total_increasing

Перезапустите Home Assistant. После чего данное предупреждение исчезнет
image

4 Likes

For core integrations, other than template sensors, you should open an issue on github to get this corrected for the integration rather than using customize.

2 Likes

Hello,
it is persistent after reboot? I did it, then after few days (and reboots) I got the same issue and lost the modify done via customize. Thanks

Hi,

Same for me. When I set the state_class for a template sensor value, in my case a sum o several sensor values, the state_class just disappears after I set it. Am I doing something wrong?

How do you create sensor like this without need to reload whole configuration?