bramstroker / homeassistant-powercalc

Custom component to calculate estimated power consumption of lights and other appliances

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[FR] Make group sensors more group sensor compliant

erkr opened this issue · comments

commented

Checklist

  • I have filled out the template to the best of my ability.
  • This only contains 1 feature request (if you have multiple feature requests, open one feature request for each feature request).
  • This issue is not a duplicate feature request of previous feature requests.

Is your feature request related to a problem? Please describe.

The Powercalc group sensors currently list the embedded entities under the key entities in the attributes:

state_class: measurement
entities:
  - sensor.voordeur_power
  - sensor.tuinhuis_power
  - sensor.poort_power
  - sensor.overloop_power
is_group: true

Describe the solution you'd like

By changing that into entity_id, it will be recognised as a group sensor by e.g the auto entities card and expand() in templates:

state_class: measurement
entity_id:
  - sensor.voordeur_power
  - sensor.tuinhuis_power
  - sensor.poort_power
  - sensor.overloop_power
is_group: true

For i.e the auto entities card the whole group than can be simply added like this:

filter:
  include:
    - group: sensor.group_power

Describe alternatives you've considered

Enumerate entities list

Additional context

I guess this is a relative easy change, that makes usage in templates and cards more convenient.

@erkr Pretty sure I investigated this somewhere in the past. Could not find the issue/discussion again.
Anyways if I remember correctly there is another prerequisite in expand template function which I cannot comply (thought there is a check for platform group or something like that in code code).
Also for auto entities I have checked to support that.
I might revisit this though as I see why this can be very useful. Maybe there has been changes in HA where I can be able to get this working.

Also this would be a breaking change. People relying on entities in there template will need to adopt when I change this.

I did a quick test, but I cannot make this working for expand.

The culprit is here. Where HA checks specifically for group.* entities. Powercalc group sensors are part of sensor domain.
https://github.com/home-assistant/core/blob/dev/homeassistant/helpers/template.py#L1270

commented

Thanks for testing. Didn't know that expand() expects the group domain. Nice you recognise the added value for populating cards😊

Thanks for testing. Didn't know that expand() expects the group domain. Nice you recognise the added value for populating cards😊

It was on the back of my mind somewhere. It's a pity, but they won't add any specific code for powercalc in core. Also, there is no possibility for custom components to provide entities in the group domain, that's something only core code can do.
So there is no solution unfortunately yet for the expand

commented

Group support for cards would already be very nice. 😊 I realise it is actually breaking change.

commented

To be honest, this integration is so useful, it should be part of core 🤗

Closing as it's not something I can fix. Example how to use with auto entities is shared above.

commented

Yes that template works fine👌