Change icon based on a separate entity

I have a DIY esp32 garage door opener and a separate door sensor. Im trying to make a button on my dashboard that controls the esp32 but im trying to get the icon of the button to change based on the value of the door sensor which would be a separate entity. been trying to look at custom-button and card-mod from HACS but my limited knowledge i cant seem to figure out how you would read info from a separate entity to effect the icon of the entity im making a button for.

is this possible?

Use a template cover. it will take care of the icons for you.

1 Like

I ended up figuring out a solution finally using HACS custom-button

code is

type: custom:button-card
tap_action:
  action: toggle
entity: switch.garage_door_button_button
icon: |
  [[[
      if ( states["number.garage_door_sensor_basic"].state == '255.0') return 'mdi:garage-open-variant';
      else return 'mdi:garage-variant';
  ]]]
styles:
  icon:
    - color: |
        [[[
         if ( states["number.garage_door_sensor_basic"].state == '255.0') return 'red';
          else return '#50719c';
         ]]]