Custom button card with two entities

I have the following custom card that displays a battery value and also toggles on/off a switch when pressed

- color: white
    color_type: card
    entity: sensor.amazon_fire_battery_sensor
    label: Tablet
    show_label: true
    show_name: false
    show_state: true
    tap_action:
      action: call-service
      service: switch.toggle
      service_data:
        entity_id: switch.meross_tablet
    styles:
      card:
        - width: 105px
        - height: 105px
    type: 'custom:button-card'

I would like to change the color of this card based on the on/off value of the switch.meross_tablet switch. Is that possible?
I know I can do something like:

state:
      - color: 'rgb(255, 0, 0)'
        label: Tablet On
        value: 'on'
      - color: 'rgb(255, 255, 255)'
        label: Tablet Off
        value: 'off'

But that is only for the main entity of the card it seems sensor.amazon_fire_battery_sensor
Any idea if that would work?

1 Like

You can template state style sections. That’d be the only way to handle it.

Yeah I was looking at that and can’t get my head around them but I did have some success with custom_field and adding the battery level to a switch card