How to set state_class to total_increasing of a Riemann sun sensor

Hello,
I created a sensor with platform integration to have an energy measure of my UPS consumption:

- sensor:
  - name: "UPS Load"
    state_class: measurement
    device_class: power  
    unit_of_measurement: "W"
    state: >
      {%- if is_state('sensor.zinto1000_status_data', 'OL') %}
        {% set efficiency = 0.97 %}
      {% elif is_state('sensor.zinto1000_status_data', 'OB') %}
        {% set efficiency = 0.91 %}
      {% endif -%}
      {{ (states('sensor.zinto1000_load') | float * 900 / 100 * efficiency)  | int(default=0) }}
- platform: integration
  name: "Consumo UPS"
  source: sensor.ups_load
  unit_prefix: k
  round: 2

Checking the energy dashboard I found that this sensor is not available there.
So I checked the entity and I found that state_class is total but If I’m not mistaken it should be total_increasing to be showed in the energy dashboard.

How can I change this value correctly?
If I try to change it in the developer tools after few second it turns back to total

Thanks

I thought to set the device class via customize:

sensor.consumo_ups:
  state_class: total_increasing

It looks that it works

but I cannot see the sensor available in the energy dashboard

It can take up to 2 hours for sensors to appear in the energy dashboard.

The main problem could be that “total_increasing” and “total” could behave differently:

total:
The state represents a total amount that can both increase and decrease, e.g. a net energy meter. Statistics of the accumulated growth or decline of the sensor’s value since it was first added is updated every 5 minutes. This state class should not be used for sensors where the absolute value is interesting instead of the accumulated growth or decline, for example remaining battery capacity or CPU load; in such cases state class measurement should be used instead.

total_increasing:
Similar to total, with the restriction that the state represents a monotonically increasing positive total which periodically restarts counting from 0, e.g. a daily amount of consumed gas, weekly water consumption or lifetime energy consumption. Statistics of the accumulated growth of the sensor’s value since it was first added is updated every 5 minutes. A decreasing value is interpreted as the start of a new meter cycle or the replacement of the meter.

So, it depends how the sensor / integration does behave - if the Sensor does increase - but can also decrease, the state_class “total” is the correct one.

so, do you want to include the UPS into the Energy Dashboard as Battery device?
If yes, it would probably require a “load” and “unload” sensor… this could maybe done with the "Battery Consumption integration available on HACS… ?

The sensor can only increase its value.
To start I wanted only get from the UPS load provided by NUT the consumption in W and them integrate this value to have something in Wh to be added in the energy dashboard as normal device that eats energy.
Now I will dig into the use of the battery device to better understand if I can do the same smarter.

hm… according to the development area, the customization did work.
The sensor has state_class: total_increasing, has the correct device_class and unit_of_measurement.

if it can only increase, then total_increasing should be valid… (it should probably be changed within the integration then) - and it should appear in the energy dashboar configuration.

does it appear in the selection itself?

If it will be listed there, it should appear in the energy dashboard itself - maybe, after one or two hours (when a new statistic will be calculated)…

I got in the logs:

2022-11-02 14:35:10.602 WARNING (Recorder) [homeassistant.components.sensor.recorder] The unit of sensor.consumo_ups (kWh) can not be converted to the unit of previously compiled statistics (kWmin). Generation of long term statistics will be suppressed unless the unit changes back to kWmin or a compatible unit. Go to https://my.home-assistant.io/redirect/developer_statistics to fix this

Fixed this I can see the entity in the energy dashboard

Hi there, I’m sorry to dig out this thread, but I have the same issue, how do you “customize” the integration sensor ?