Integration - Riemann sum integral for solar panels showing 'Unexpected device class'

Hi! New to the forum and HA overall.

I want to show my solar panel production in the energy tab.

I created a new sensor with the Riemann sum integral GUI under Settings > Devices & services > Helper Tab > + Create Helper > Integration - Riemann sum integral sensor. I followed this guide.

Added the integration with these settings:

And I can view the kwH as I want to if I view the sensor directly as it shows the current kwH and a timeline.

but when I add it to the Energy Tab I get the following message:
'Unexpected Device Class
The following entities do not have the expected device class:

  • sensor.solcellor_nuvarande_produktion’

sensor.solceller_nuvarande_produktion is the name of my newly created helper.

Did I make a mistake somewhere or if there is another way of creating a device_class energy.

Sorry I couldn’t post more images since I’m a new user.

You also need to do the last part of the guide, under energy.

No they don’t. That is equivalent of what they have done in the UI.

@Qvint go to developer tools → states. Paste the attributes of both the source sensor and Rieman Sum sensor here.

Thank you for the response!

They are already included in the sensor list:

Are the not configured correctly?

It’s missing the device_class, did you restart home assistant after adding the sensor, try that first.

image

That worked, thank you!

@Qvint Sorry if this is a stupid question but where did you add the device class please? I have the same issue and can see it is missing but not were to add it. Thanks

Hi @pete101 I came here wondering the same - and read the last part of the linked Riemann integrataion under Energy: It will work if you add device_class: power to you power sensor which you use as input to the integration helper (Riemann sum). It will then automatically get energy as device class it seems.

For completeness, these are two of my power sensors I have made, which I use as input to the Riemann sum:

  - platform: template
    sensors:
      hottub_pump2_power_consumption:
        friendly_name: "Hottub pump 2 power consumption"
        device_class: power
        unit_of_measurement: "kW"
        value_template: >
          {% set kilowatts_when_on = 3.000 %}
          {{ is_state_attr('fan.hottub_pump_2', 'preset_mode', 'HI')  * kilowatts_when_on }}                                                                                                                                                
  - platform: template
    sensors:
      hottub_blower_power_consumption:
        friendly_name: "Hottub blower power consumption"
        device_class: power
        unit_of_measurement: "kW"
        value_template: >
          {% set kilowatts_when_on = 0.700 %}
          {{ is_state('switch.hottub_blower', 'on') * kilowatts_when_on }}                                                                                                                                                                  

Note that I needed to trigger a change of state before the unit came into play correctly. Naturally I also restarted HA after changing the yaml config.

@mgee Thanks for the info. I had tried a device class of energy but not power on the source sensor. However that also didn’t work as the sensor doesn’t seem to accept a device class at all. I am using a command line sensor rather than a template so that maybe my issue.

Config:

- sensor:
      command: 'curl -u "[email protected]:*********" -X POST -H "Content-Type: application/json" -d "{\"id\":xxxxx}" https://mihome4u.co.uk/api/v1/subdevices/show'
      name: House Monitor
      unique_id: house_monitor
      device_class: power
      unit_of_measurement: W 
      value_template: '{{ value_json.data.last_data_instant }}'

And this is all that shows in dev tools

unit_of_measurement: W
friendly_name: House Monitor

I think the problem you have might be unrelated to the initial post here - I think it could be the command_line platform that is the problem - it has recently changed in HA. This is how I use it in version 2023.7.1:

command_line:
  - sensor:
      name: RPi CPU Temp
      command: "cat /sys/class/thermal/thermal_zone0/temp"
      unit_of_measurement: "°C"
      value_template: '{{ value | multiply(0.001) | round(1) }}'

I have no device_class there, but I think it can be added. I think it is best to create a new post if this doesn’t work for you, feel free to @ mention me there and I will try to help out.

1 Like

Have the same issue and a reboot / restart does not correct this
The following entities do not have the expected device class:
image

image

so was able to add the “device_class: power” using customize section in config.yaml
image

However it still complains about it not having this setting
Even after a restart.

QUICK Update:
Got this corrected. I changed POWER to ENERGY and this seems to satisfy the error (no more error)
image
image

Hello dear HA enthusiasts,
Like you in this thread, I’m running into this
image

So, I followed the advice in this thread to go to
Developer tools → States
and then one by one add the device_class: energy for each one that is missing
image

So I add ad line 6 the device_class: energy line and click on SET STATE button
Then it seems ok.
Then when I restart HA, all is gone again and I can start doing it again.

What am I doing wrong?
Why is it nog keeping the the added line?

2 Likes

I am having this exact issue. It was working just fine for the last couple months until recently it wanted the device class for one sensor… now it wants it for all my sensors. It’s broken this whole “Energy Dashboard” feature for me completely.

Edit 1:
It will remember the time stamp for the last change. even move the line into the correct spot, but it is not persistent after a restart.

Edit 2:
I redid every entity I had “Integration - Riemann sum integral sensor” I had to calculate the expected kWh reading that “Energy Dashboard” was expecting, and it worked… until I restarted, and it broke everything and put it back the way it was… but then would correct itself after a couple minutes… seems to be working now for most of my outlets from one brand. the outlets from another brand seem to not work, even though they show in Watts, but the “Integration - Riemann sum integral sensor” is unable to convert them kWh, and just shows unknown, even though it is reading out Watts.