Adding (kWh) integration sensors to energy panel. Some work, some dont, Im stumped

Im trying to monitor all my power consumption, and was curious how much my (smart) lights contribute to my overall bill.

First I made a template sensor that tracks the light’s power consumption, for instance, for a 6W zigbee light in my study:

    - name: "light_buro_lamp_pc_power"      
      unit_of_measurement: W
      state: >
        {% if is_state('light.buro_lamp_pc', 'on') %}
            {% set brightness = states.light.buro_lamp_pc.attributes.brightness | int  %}
            {{ 6 * (brightness | float / 255) + 0.6 | round(2) }}
        {% else %}
            0.6
        {% endif %} 

I then combine lights in to room sensors like:

    - name: "room_light_buro_power"      
      unit_of_measurement: W
      state: >                   
             {{ 
             states('sensor.light_buro_spots_power') | float + 
             states('sensor.light_buro_lamp_pc_power') | float +
             states('sensor.light_rgb_strip_buro_power') | float 
             }} 

This works fine. I then create an integration sensor, like I have done for some smart plugs that provide W but not kWh:

    - platform: integration
      source: sensor.room_light_buro_power
      name: Buro licht kWh
      unit_prefix: k
      round: 3

This again seems to work fine, I get a sensor that tracks power consumption for all lights in the study, the unit is kWh:

image

However, I can not add this device (or any other of my room light power consumption sensors) to my energy panel. I created them 20+ hours ago, they still dont show up. I created some other integration sensors to track smart plugs, they look identical and they could be added just fine.

Help? Is there maybe a limit to how many devices I can add to the energy panel?

BTW, ideally all this would be done “automagically”, see my feature request here

For sensors to show up in the Energy Dashboard they should be measuring (k)Wh and (most often) have a state_class: total_increasing .

If the integration you are using does not support a state_class you can add it using customize. Though it is preferable to open an issue and get the integration amended.

But Im using the “integration” integration:

which clearly works for the energy dashboard, it even does for some of my other sensors. And my integration sensors do measure kWh.

Did you look at the attributes of your sensors?

Do they all have a state_class?

You should look on the HACS Integration : Power calculation.
It’s designed for, and work out of the box

Im confused now. I have power sensors (unit_of_measurement: W) that are template sensors that do not have any state_class (I think?) , but " total_increasing" sounds wrong for a sensor that goes up and down all the time, or am I misunderstanding this?

And I have the consumption sensor (kWh), using the “integration integration” (great name :slight_smile: ) which integrates the value of those power sensor, and which we know should work, so I assume they have the state_class?

Yep, thanks, someone else pointed me to that too. I will try it, but Id still like to get to the bottom of this.

Don’t assume. Check the attributes of these sensors that don’t show up in the energy dashboard.

It does not:

state_class: total
source: sensor.room_light_buro_power
unit_of_measurement: kWh
icon: mdi:chart-histogram
friendly_name: Buro licht kWh

That’s your problem then. And I also told you how to fix it:

Ill try that, but the integration Im using is the official “Riemann sum integral integration” which does support it for all my other sensors (and which is recommended to use to generate kWh sensors for devices/integrations that dont support it natively)

By “support” I mean the ability to add it as an option to the configuration. It does not have this option: https://www.home-assistant.io/integrations/integration/#configuration-variables

It probably inherits the attribute from your other sensors that work. Not really sure.

I was struggling with this too.
The power source is from a Sonoff POW R2 that is behind my washing machine with old tasmota firmware that I cannot login to anymore and do not want to spend too much time on. The sensor has the following attributes:

unit_of_measurement: W
friendly_name: Sonoff ENERGY Power

This is how I got it to work with the energy dashboard:
I added the Integration - Riemann sum integral through the add integration button.
The attributes of this Entity now looked like this:

state_class: total
source: sensor.sonoff_energy_power
unit_of_measurement: kWh
icon: mdi:washing-machine
friendly_name: Wasmachine verbruik kWh

I was not able to find a way through the interface to add customization so I added this to the configuration.yaml

homeassistant:
  customize:
    sensor.wasmachine_verbruik_kwh:
      device_class: energy

The attributes of the entity now look like this and I was able to add it to the energy dashboard.

state_class: total
source: sensor.sonoff_energy_power
unit_of_measurement: kWh
icon: mdi:washing-machine
friendly_name: Wasmachine verbruik kWh
device_class: energy

Hope this helps people.
Maybe I will replace the tasmota with ESPHome in the future and do this in the ESPhome yaml.

4 Likes

Excellent! Thank you. This solved a similar problem for me…

Steve.

1 Like

Thank you @bvansambeek.

In the end, the only thing I needed to change was to have the power sensor in kW for the integral to show up in the energy panel as total.

I added a Sengled Smart plug with energy tracker (E1C-NB7) and it doesn’t show up in Energy, but it does have the state class, kWh, exactly as below. Is there something else that it needs? I did notice that with some light switch that I have that is also has meter_type: 1 and meter_type_name: ELECTRIC. It does show up. Another smart plug has same info as below, been installed much longer, doesn’t show up either.

state_class: total_increasing
unit_of_measurement: kWh
device_class: energy
friendly_name: Smart Plug energy

When you say they don’t show up…

Do you mean on the energy dashboard?

Or the list to add them to the energy dashboard?

You need to add them manually to the dashboard

Settings > dashboards > energy

1 Like

Thanks. I forgot about having to add them, been so long since I added the last ones. :grinning_face_with_smiling_eyes:

1 Like