Issues with utility meter

Hello, I got below warning message:

  • Entity sensor.giorno_produzione_solare_immessa_in_casa (<class ‘homeassistant.components.utility_meter.sensor.UtilityMeterSensor’>) is using state class ‘total_increasing’ which is impossible considering device class (‘power’) it is using; expected None or one of ‘measurement’; Please update your configuration if your entity is manually configured, otherwise create a bug report at Issues · home-assistant/core · GitHub
  • Entity sensor.mese_produzione_solare_immessa_in_casa (<class ‘homeassistant.components.utility_meter.sensor.UtilityMeterSensor’>) is using state class ‘total_increasing’ which is impossible considering device class (‘power’) it is using; expected None or one of ‘measurement’; Please update your configuration if your entity is manually configured, otherwise create a bug report at Issues · home-assistant/core · GitHub
  • Entity sensor.anno_produzione_solare_immessa_in_casa (<class ‘homeassistant.components.utility_meter.sensor.UtilityMeterSensor’>) is using state class ‘total_increasing’ which is impossible considering device class (‘power’) it is using; expected None or one of ‘measurement’; Please update your configuration if your entity is manually configured, otherwise create a bug report at Issues · home-assistant/core · GitHub
    and this is the sensor i have on my package folder.
- platform: template
  scan_interval: 60
  sensors:
    tesla_card_produzione_solare_immessa_in_casa:
      friendly_name: "Energia prodotta consumata in casa"
      value_template: "{{ (states('sensor.giorno_produzione_fotovoltaico') | float(2) - states('sensor.giorno_immissione_in_rete') | float(2)) | round(2) }}"
      device_class: power
      unit_of_measurement: kW

what’s wrong?

Should be either this if it is an energy sensor:

      device_class: energy
      state_class: total # or total_increasing
      unit_of_measurement: kW

Or this if it is a power sensor:

      device_class: power
      state_class: measurement
      unit_of_measurement: W

Though I am assuming it is an energy sensor as you are trying to feed it to a utility meter.

You should also be using the new template sensor format so that you can give it a state_class. This will not work with the legacy template sensor format you are using.

thanks for reply, this is the background of the that code:

  giorno_produzione_fotovoltaico:
    source: sensor.monit_casa_e_fotovoltaico_channel_2_energy
    cycle: daily

which is handle by a Shally power meter automatically set by system:

So, base on you reply I assue this shoul be the right code:

- platform: template
  scan_interval: 60
  sensors:
    tesla_card_produzione_solare_immessa_in_casa:
      friendly_name: "Energia prodotta consumata in casa"
      value_template: "{{ (states('sensor.giorno_produzione_fotovoltaico') | float(2) - states('sensor.giorno_immissione_in_rete') | float(2)) | round(2) }}"
      device_class: energy
      state_class: total_increasing
      unit_of_measurement: kW

could be ?

No.

You can not add a state_class to a legacy format sensor. You need to use the new format as I said:

got it! then it should be like this:

template:
  - sensor:
      - name: "Energia prodotta consumata in casa"
        unique_id: tesla_card_produzione_solare_immessa_in_casa
        state: >-
          {{ (states('sensor.giorno_produzione_fotovoltaico') | float(2) - states('sensor.giorno_immissione_in_rete') | float(2)) | round(2) }}
        device_class: energy
        state_class: total_increasing
        unit_of_measurement: kW

is now correct?

However, what is not really clear to me is why i have the log for the sensor tesla_card_produzione_solare_immessa_in_casa and not for tesla_card_consumo_totale_casa…

- platform: template
  scan_interval: 60
  sensors:
    #
    tesla_card_consumo_totale_casa:
      friendly_name: "Consumo totale casa"
      value_template: "{{ (states('sensor.giorno_consumo_casa') | float(2) + states('sensor.tesla_card_produzione_solare_immessa_in_casa') | float(2)) | round(2) }}"
      device_class: power
      unit_of_measurement: kW

If it is an energy sensor, you need units of kWh

1 Like

Actually I missed this:

Energy is measured in kWh, not kW.

Edit: beaten to it by Rick.

I have fixed kWh instead with kW but I still have this message using “state_class: total_increasing” or “state_class: total”…

Entity sensor.giorno_produzione_solare_immessa_in_casa (<class ‘homeassistant.components.utility_meter.sensor.UtilityMeterSensor’>) is using state class ‘total_increasing’ which is impossible considering device class (‘power’) it is using; expected None or one of ‘measurement’; Please update your configuration if your entity is manually configured, otherwise create a bug report at Issues · home-assistant/core · GitHub
Entity sensor.mese_produzione_solare_immessa_in_casa (<class ‘homeassistant.components.utility_meter.sensor.UtilityMeterSensor’>) is using state class ‘total_increasing’ which is impossible considering device class (‘power’) it is using; expected None or one of ‘measurement’; Please update your configuration if your entity is manually configured, otherwise create a bug report at Issues · home-assistant/core · GitHub
Entity sensor.anno_produzione_solare_immessa_in_casa (<class ‘homeassistant.components.utility_meter.sensor.UtilityMeterSensor’>) is using state class ‘total_increasing’ which is impossible considering device class (‘power’) it is using; expected None or one of ‘measurement’; Please update your configuration if your entity is manually configured, otherwise create a bug report at Issues · home-assistant/core · GitHub

Go to Developer Tools → Statistics and fix all the issues listed there.

There is any issues here…

could be related only when I restart because the sensor is not yet ready and i can solve it with availability?

template:
  - sensor:
      - name: "Energia prodotta consumata in casa"
        unique_id: tesla_card_produzione_solare_immessa_in_casa
        state: >-
          {{ (states('sensor.giorno_produzione_fotovoltaico') | float(2) - states('sensor.giorno_immissione_in_rete') | float(2)) | round(2) }}
        availability: >
          {{ has_value('sensor.tesla_card_produzione_solare_immessa_in_casa')}}
          device_class: energy
        state_class: total
        unit_of_measurement: kWh

No that is not how you use the availability template. You need to list both the source sensors, like this:

        state: >-
          {{ (states('sensor.giorno_produzione_fotovoltaico') | float(2) - states('sensor.giorno_immissione_in_rete') | float(2)) | round(2) }}
        availability: >
          {{ has_value('sensor.giorno_produzione_fotovoltaico') and has_value('sensor.giorno_immissione_in_rete') }}

However hat is not your issue. The error shown above has nothing to do with this template sensor. Can you please show the configuration for this entity

sensor.giorno_produzione_solare_immessa_in_casa

here the code:

utility_meter:
  giorno_produzione_solare_immessa_in_casa:
    source: sensor.tesla_card_produzione_solare_immessa_in_casa
    cycle: daily
template:
  - sensor:
      - name: "Energia prodotta consumata in casa"
        unique_id: tesla_card_produzione_solare_immessa_in_casa
        state: >-
          {{ (states('sensor.giorno_produzione_fotovoltaico') | float(2) - states('sensor.giorno_immissione_in_rete') | float(2)) | round(2) }}
          device_class: energy
        state_class: total_increasing
        unit_of_measurement: kWh

And you are 100% sure there are no FIX ISSUE buttons for sensor.giorno_produzione_solare_immessa_in_casa in Developer Tools → Statistics now?

If so, try commenting out the utility meter:

utility_meter:
#  giorno_produzione_solare_immessa_in_casa:
#    source: sensor.tesla_card_produzione_solare_immessa_in_casa
#    cycle: daily

Restart Home assistant.

Then recreate the utility meter by deleting the comments

utility_meter:
  giorno_produzione_solare_immessa_in_casa:
    source: sensor.tesla_card_produzione_solare_immessa_in_casa
    cycle: daily

and restart again.

If that does not fix it try renaming the utility meter,

utility_meter:
  giorno_produzione_solare_immessa_in_casa_2:
    source: sensor.tesla_card_produzione_solare_immessa_in_casa
    cycle: daily

nothing happen… however i guess we have to do a step back because I just recognized that with the new format nothing working anymore :frowning:

status before:
below folder “custom_sensor” I used following code which was working

- platform: template
  scan_interval: 60
  sensors:
    #
    tesla_card_consumo_totale_casa:
      friendly_name: "Consumo totale casa"
      value_template: "{{ (states('sensor.giorno_consumo_casa') | float(2) + states('sensor.tesla_card_produzione_solare_immessa_in_casa') | float(2)) | round(2) }}"
      device_class: power
      unit_of_measurement: kW
    tesla_card_produzione_solare_immessa_in_casa:
      friendly_name: "Energia prodotta consumata in casa"
      value_template: "{{ (states('sensor.giorno_produzione_fotovoltaico') | float(2) - states('sensor.giorno_immissione_in_rete') | float(2)) | round(2) }}"
      device_class: power
      unit_of_measurement: kW

then I replace it with the new format as below in the folder “custom_packages”

template:
  - sensor:
      - name: "Consumo totale casa"
        unique_id: tesla_card_consumo_totale_casa
        state: >-
          {{ (states('sensor.giorno_consumo_casa') | float(2) + states('sensor.tesla_card_produzione_solare_immessa_in_casa') | float(2)) | round(2) }}
        device_class: energy
        state_class: total_increasing
        unit_of_measurement: kWh

      - name: "Energia prodotta consumata in casa"
        unique_id: tesla_card_produzione_solare_immessa_in_casa
        state: >-
          {{ (states('sensor.giorno_produzione_fotovoltaico') | float(2) - states('sensor.giorno_immissione_in_rete') | float(2)) | round(2) }}
        device_class: energy
        state_class: total_increasing
        unit_of_measurement: kWh

and this is what I see in the console… something is not clear and I guess here we need to solve something…

Someone else will have to help you. I don’t use packages.

I tried to move the code from packages to configuration.yaml but same result :frowning:

Did you restart after moving it?

Errors in your logs?

yes I restart it!

warning:
Registratore: homeassistant.components.sensor
Fonte: components/sensor/init.py:575
Integrazione: Sensore (documentazione, problemi)
Prima occorrenza: 11:04:58 (3 occorrenze)
Ultima registrazione: 11:04:58

Entity sensor.giorno_produzione_solare_immessa_in_casa (<class ‘homeassistant.components.utility_meter.sensor.UtilityMeterSensor’>) is using state class ‘total_increasing’ which is impossible considering device class (‘power’) it is using; expected None or one of ‘measurement’; Please update your configuration if your entity is manually configured, otherwise create a bug report at Issues · home-assistant/core · GitHub
Entity sensor.mese_produzione_solare_immessa_in_casa (<class ‘homeassistant.components.utility_meter.sensor.UtilityMeterSensor’>) is using state class ‘total_increasing’ which is impossible considering device class (‘power’) it is using; expected None or one of ‘measurement’; Please update your configuration if your entity is manually configured, otherwise create a bug report at Issues · home-assistant/core · GitHub
Entity sensor.anno_produzione_solare_immessa_in_casa (<class ‘homeassistant.components.utility_meter.sensor.UtilityMeterSensor’>) is using state class ‘total_increasing’ which is impossible considering device class (‘power’) it is using; expected None or one of ‘measurement’; Please update your configuration if your entity is manually configured, otherwise create a bug report at Issues · home-assistant/core · GitHub

warning 2
Registratore: homeassistant.components.sensor.recorder
Fonte: components/sensor/recorder.py:325
Integrazione: Sensore (documentazione, problemi)
Prima occorrenza: 11:05:37 (1 occorrenze)
Ultima registrazione: 11:05:37

Entity sensor.consumo_altro from integration template has state class total_increasing, but its state is negative. Triggered by state -3.07 with last_updated set to 2024-04-09T08:59:59.999999+00:00. Please create a bug report at Issues · home-assistant/core · GitHub

There is something wrong with your template sensor. I suspect it is because you removed the availability template. When one or both of the sensors was unavailable (e.g. during a restart) it was substituted with the your default value of 2, where you used |float(2) this caused the value to go backwards.

i confirm that I wrote this and for mistake i restat the hassio.

can I solve it with following code?

      - name: "Energia prodotta consumata in casa"
        unique_id: tesla_card_produzione_solare_immessa_in_casa
        state: >-
          {{ (states('sensor.giorno_produzione_fotovoltaico') | float(2) - states('sensor.giorno_immissione_in_rete') | float(2)) | round(2) }}
        availability: >
          {{ has_value('sensor.giorno_produzione_fotovoltaico') and has_value('sensor.giorno_immissione_in_rete')}}
        device_class: energy
        state_class: total_increasing
        unit_of_measurement: kWh