Battery Levels - Custom Button

Hi Team.

Hoping someone can help.

I have three Sensor Groups.

  1. All Batteries
  2. Downstairs Batteries
  3. Upstairs Batteries

The group options of All Batteries has the up and downstairs batteries as members and i have the type set to minimum.

Now when i look at all three they are reporting the minimum vales correctly.

I then have this button card on my dashboard. Now if all batteries were 100% it should be green , then less than 80% colour should be orange and less than 30% turn the colour red.

The issue is , if i reboot HA then the button colour is white. If i remove up or downstairs from the All Batteries group and add them back in again then it displays the correct colour.

Any suggestions

type: custom:button-card
entity: sensor.group_batteries_all
unit_of_measurement: '%'
device_class: battery
show_name: false
theme: synthwave
show_state: false
tap_action:
  action: navigate
  navigation_path: /dashboard/allbatteries
state:
  - value: 'off'
    icon: mdi:battery
    color: green
  - value: 'on'
    icon: mdi:battery-10
    color: red
styles:
  card:
    - width: 50px
    - height: 50px
    - border-color: |
        [[[ 
          if (entity.state < 30) return 'red' 
          if ((entity.state >= 30) && (entity.state < 80)) return 'orange' 
          else if (entity.state > 80) return 'lime' 
        ]]]
    - box-shadow: |
        [[[  
          if (entity.state < 30) return '0px 0px 10px 1px red ' 
          if ((entity.state >= 30) && (entity.state < 80)) return '0px 0px 10px 1px orange ' 
          else if (entity.state > 80) return '0px 0px 10px 1px lime ' 
        ]]]
      icon: null
    - color: |
        [[[
          if (entity.state < 30) return 'red'; 
          if ((entity.state >= 30) && (entity.state < 80)) return 'orange' 
          if (entity.state >= 80) ret

when the button color is white… what’s the value of the sensor? does it have a value? or is it something like “unknown” at that time?

what i’m thinking is that perhaps the issue isn’t in the code you have there…

Hi.

I have just rebooted my HA. Yes the state of the battery group is unknown. Issue is after 5 minutes or so the will start to report the correct values but the button never changes colour once they do report.