Grouping attributes

I have a few aqara outlets, and a few breakers that provide a reading of power and energy.
The entity state is energy.
What’s the best way to get the total of all sensors combined?
Is there a way to get the total of the Power attribute?

Is the only way to do a template sensor and add them up? Or is there a better way out there before I go into this. I have a lot of these to do around the house to get the power at a moment in time, so trying to find the best approach before I go down the wrong path.
This is what my aqara looks like:

btw, still trying to figure out how to zero the energy reading.

I created the group already, and I get this:

I am interested in total energy and total power for a group of devices.

If you don’t want a template sensor adding them up, have a look at the PowerCalc HACS integration - it can do it for you.

Yes Powercalc can do exactly what you want @Haze.
See Groups — Powercalc documentation

@bramski, @michaelblight, thanks for the input. The groups with powercalc would be a solution for the energy entities I have.
I could not gather from reading through the docs if I can point to an attribute to create a group for power, not energy.
Or would I then create a new entity out of an existing entity’s attribute, and then use that new entity in a powercalc group given I want a group of power, not only energy so I can compare real-time usage.
I see the group does generate power and energy sensors, for entities we add, I was just not clear what it does if the entities already have one in their attribute, not the entity itself.

Either way, I will try it out now and see the output of powercalc and play with it.

Powercalc can create groups for both power and energy.

It’s a bit strange you have an entity where the power is in an attribute, and not a separate entity. Most (if not all) integrations provide this kind of information as an entity.
When you don’t have it in a seperate entity yet you can do so by making a virtual power sensor in powercalc and use a template to extract the value from the attribute.

Than you can add that new entity to the powercalc group.

Hope this helps.

yeah, that’s where I landed. I will have to create a virtual power sensor for each, then add that as a powercalc entity when I create the group. Playing with one area now, then will deploy to others. Have a ton of them… :confounded:
Ton or work, but I think cleanest we it will all be managed within powercalc then.

Yeah, the aqara and my breakers (different brand altogether) have the power as an attribute. I only have a few others where like you said, I get 2 separate entities for power and energy.

dont want to take away anything from the great Powercalc integration by Bram (heavy user here), but you can also create a helper entity to combine entity values and use Sum

not sure about those attributes though…

I think there is no escape of having to create entities out of attributes to get power up to an entity level…

well, you can probably easily create a single template: sensor entity that sums the attributes for you.

depending on you organization, you could have them all in a group, or named in a structured manner, and have the template loop over those

read about it and been reading up on templating. I have enough skills with jinja coding, need some more polishing for that one.

I did find some HACS that convert attributes to sensors, so I am looking into those. I will report back which one is the fastest for bulk.

I added the entities to my powercalc. At first look, it automatically made a power entity for the group, and correctly added the power attributes. Didn’t have to go and make a bunch of power entities.
So I think this is the best way forward for me.
And with the nested groups, I can make one for my house, and have sub-groups for each room to have them tracked. I will keep playing around with it to see if there is any case that won’t work out. I haven’t used powercalc before other than the auto created WLED one.

I did a quick example in the GUI and seems to work.
I prefer handling in YAML though. I deleted the integration I created and moved the same to YAML, but for some reason it is not picking it up. I restarted HA as well.

This is what I have:

powercalc: #!include_dir_merge_named ../entities/powercalc
  sensors:
    - create_group: Gallery Consumption
      entities:
        - energy_sensor_id: sensor.ufo_2_light_energy
        - energy_sensor_id: sensor.ufo_3_light_energy
        - energy_sensor_id: sensor.ufo_4_light_energy
        - energy_sensor_id: sensor.ufo_5_light_energy
        - energy_sensor_id: sensor.ufo_6_light_energy
        - energy_sensor_id: sensor.ufo_7_light_energy
        - create_group: AV Room
          entities:
            - energy_sensor_id: sensor.server_1_outlet_energy
            - energy_sensor_id: sensor.server_2_outlet_energy

I have the !include commented, but that will be my next step, to have a file for each of the locations. So you can ignore for now.

I am not seeing the gallery_consumption in my entities after restart. Configuration does not flag any errors. Am I missing something?