Limych / ha-average

Average Sensor for Home Assistant

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AverageSensor is using state class 'measurement' which is impossible considering device class ('energy') it is using

parautenbach opened this issue · comments

Environment

  • Home Assistant Core release with the issue: 2023.5.4
  • This custom component release with the issue: v2.3.0
  • Last working this custom component release (if known): unknown
  • Operating environment (Home Assistant/Supervisor/Docker/venv): venv

Describe the bug

WARNING (MainThread) [homeassistant.components.sensor] Entity sensor.average_solar_energy_forecast_today (<class 'custom_components.average.sensor.AverageSensor'>) is using state class 'measurement' which is impossible considering device class ('energy') it is using; expected None or one of 'total_increasing', 'total'; Please update your configuration if your entity is manually configured, otherwise report it to the custom integration author.

Configuration.yaml

  - platform: average
    name: Average Solar Energy Forecast Today
    start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
    end: '{{ now() }}'
    entities:
      - sensor.energy_production_today

Steps to Reproduce
Restart HA.

Expected behavior
I don't think the integration must automatically set the device class and/or state class. Granted, my case might seem like an odd case, but since it's a forecasted value, it does seem like measurement is the correct state class, and it is an energy sensor. The issue is that HA doesn't like this combination. I suppose one could argue HA must accommodate this, but as per the log, I've logged this issue.

I tried to force it with just to see if I could get the error to go away:

sensor.average_solar_energy_forecast_today:
  state_class: total_increasing

Debug log

WARNING (MainThread) [homeassistant.components.sensor] Entity sensor.average_solar_energy_forecast_today (<class 'custom_components.average.sensor.AverageSensor'>) is using state class 'measurement' which is impossible considering device class ('energy') it is using; expected None or one of 'total_increasing', 'total'; Please update your configuration if your entity is manually configured, otherwise report it to the custom integration author.

Additional context