"state" based on condition of ANY member of a group?

There are a few really good battery level cards out there etc and i use them. However for a wall display im trying to make nice, simple icons. In this instance i’d like a button card using a battery icon that will change to a low battery icon if ANY entity in my battery group drops below a certain value. Is that possible? The custom: button-card is ideal for the changing of icons, i use it elsewhere. But i’m unsure about changing it based on the “state” created above.

TLDR:
Got a group of entities relating to battery levels
Want an icon to change if ANY of the entities in that group drop below X value

I would create a template sensor with the following state:

template:
  - sensor:
      - name: "Marks battery levels"
        unit_of_measurement: "%"
        state: >
          {{ expand('group.marks_battery_levels')|map(attribute='state') | min | int }}

Then your card configuration could be:

- type: "custom:button-card"
  entity: sensor.marks_battery_levels
  show_state: true
  state:
    - value: 15
      operator: '<='
      color: red
      icon: mdi:battery
    - value: 25
      operator: '>='
      color: green
      icon: mdi:battery
    - operator: 'default'
      color: yellow
      icon: mdi: battery
      styles:
        card:
          - opacity: 0.5

thanks! where would i be placing this? in a custom button card or?

would this sit in my sensor.yaml file? As the format seems a little different otherwise. Others in there are

platform: template
sensors:
friendly_name

etc

What I posted is the modern format which is under the template: key not sensor:, if you are using the legacy format then you will need to modify it to match…

uh oh, didnt even know it had become legacy. You can tell i’m a n00b at this haha. Thank you for your help!

“TemplateError(‘ValueError: min() arg is an empty sequence’)” seems to be my stumbling block."

That error likely means that either your group isn’t composed of entities who’s states are numeric (but even that should return a value of 0) or… you didn’t change the group entity_id from the stand in I used to the actual entity_id of your group.

hanging my head in shame. I did have it right in the old template format. changed it to new one but copy and pasted the one with your stand in naming. Finally got it. Huge, thanks, really appreciate the help

1 Like

may have spoken too soon. once i added in a second entity to the group, it just shows the card as 100%. i can work from here though im sure.