Allow Groups to have non-binary states

Groups have been expanded to have a binary state depending on their members. However it would be really great to extend this to non-binary values. For example, a group of temperatures could take on the mean value or a group of power entities could take on the sum of the entities. Maybe the Min/Max extension could be leveraged.

What else would useful with groups?

If groups allowed for templated attributes, then I would think anything could be added. Like a group of lights and you count the number of lights that are on divided by the number of lights in the group would give you “percent on” … your examples would be just as easy. So maybe the real question/statement should be “Allow Groups to have templated attributes”

That would work as well.

What advantage does this have over a template sensor or use of the min-max integration?

One advantage is that it completes the “Group” enhancement. If I’m already building groups of motion sensors, etc then I might as well build groups of temperature sensors, etc, which currently all have the state of “unavailable”.

At the moment I use Min/Max sensors to create an average temperature for my kitchen, basement, house. Maybe I missed it but I can’t create a Min/Max sensor for motion. Templates work too but can be bulky with lots of repeated code.

Multiple ways of doing the same thing is fine - user/situation choice - but let’s be inclusive. Groups of similar things could have a real combined state. Likewise add a on/off/true/false function for Min/Max.

@tom_l … Can you create a template sensor that is a group? I would like to see example YAML for that.

I can create a template sensor based an area. You could do something similar for entities in a group.

- sensor:
    # Average temperature in an area
    - name: "Kitchen Average Temperature"
      unique_id: "kitchen_ave_temperature"
      state_class: "measurement"
      device_class: "temperature"
      unit_of_measurement: "\u00b0C"
      state: > 
        {#- Return variable average from all sensors in a particular area. -#}
        {#-  porch  : {{ area_average('temperature', 'porch') }} -#}
        {% macro area_average(variable, area) -%}
        {%-
        set values = expand(area_entities(area)) |
         selectattr("attributes.device_class", 'eq', variable) |
         selectattr("state", 'is_number') |
         map(attribute='state') |
         map("float") |
         list
        -%}
        {%- if values -%}
            {{- ((values | sum) / ( values | length )) | round(1) -}}
        {%- else -%}
        unavailable
        {%- endif -%}
        {% endmacro -%}
        {{ area_average('temperature', 'kitchen') }}