Make a perfectly round and plain button with Mushroom cards

Sometimes you just want something simple. Like a power button that looks nice, to toggle a device at home. You just want a plain round button. Suppose you have this:

image

And you want this:

image

It’s almost like a chips card, but being an entity card, it can toggle things and it will show the state with color. It’s also more ergonomic on a phone than a chips card. Awesome.

And, best of all, it’s fairly easy!

Here’s some sample code to generate this row:

card:
  type: grid
  square: false
  columns: 2
  cards:
    - type: custom:mod-card
      style:
        hui-grid-card$: |
          div#root {
            display: grid;
            grid-template-columns: min-content max-content;
          }
        hui-grid-card$ mushroom-entity-card$: |
          ha-card {
            border: unset;
            background: unset;
          }
      card:
        type: grid
        square: false
        columns: 2
        cards:
          - type: custom:mushroom-entity-card
            entity: switch.media_center
            primary_info: none
            secondary_info: none
            icon: mdi:power
            tap_action:
              action: toggle
    - type: grid
      square: false
      columns: 2
      cards:
        - type: custom:mushroom-entity-card
          entity: switch.marantz_av7702mkii_subwoofer_adjust
          name: Sub
          secondary_info: none
          tap_action: null
        - action: toggle
          type: custom:mushroom-entity-card
          entity: switch.marantz_av7702mkii_dialog_adjust
          name: Dialog
          secondary_info: none
          tap_action:
            action: toggle

It’s all explained in detail here:

Enjoy!

3 Likes

Hey, while trying your code, I found out that it didn’t account for padding when using a theme.
After addressing this, I made some more changes:

  • No need for a custom:mod-card and grid card, instead it is just applied as a style within the custom:mushroom-entity-card, custom:mushroom-light-card and other cards that use the mushroom-shape-icon element.
  • I also kept kept the mushroom card itself as a background behind the mushroom-shape-icon, as the mushroom-shape-icon is usually transparent resulting in the underlying background being visible through the shape-icon.
  • I added box-shadow functionality taking style variables from the theme.
  • I added a dynamic border style, using the state color, taking style variables from the theme.
  • I added a small margin at the bottom of each card, because I want to use them as side buttons.

In my example I have added 2 light groups in a vertical stack, to display the difference when using state color.

Default theme:
image

Custom theme with box shadow, without border and with a purple background:
image

type: vertical-stack
cards:
  - type: custom:mushroom-light-card
    entity: light.woonkamer
    primary_info: none
    secondary_info: none
    icon: mdi:sofa
    tap_action:
      action: none
    use_light_color: true
    card_mod:
      style:
        .: |
          ha-card {
            border: var(--icon-color);
            border-radius: var(--icon-border-radius);
            padding: 0px !important;
            width: var(--mush-icon-size, 42px)!important;
            height: var(--mush-icon-size, 42px) !important;
            margin-bottom: 10px;
          }
        mushroom-shape-icon:
          $: |
            .shape:not(.disabled) {
              border-width: var(--ha-card-border-width,1px);
              border-style: solid;
              border-color: rgba(var(--rgb-state-light), 0.3)
            }
            .shape.disabled {
              border-width: var(--ha-card-border-width,1px);
              border-style: solid;
              border-color: rgba(var(--rgb-disabled), 0.25)
            }
  - type: custom:mushroom-light-card
    entity: light.slaapkamer
    primary_info: none
    secondary_info: none
    icon: mdi:bed
    tap_action:
      action: none
    use_light_color: true
    card_mod:
      style:
        .: |
          ha-card {
            border: var(--icon-color);
            border-radius: var(--icon-border-radius);
            padding: 0px !important;
            width: var(--mush-icon-size, 42px)!important;
            height: var(--mush-icon-size, 42px) !important;
            margin-bottom: 10px;
          }
        mushroom-shape-icon:
          $: |
            .shape:not(.disabled) {
              border-width: var(--ha-card-border-width,1px);
              border-style: solid;
              border-color: rgba(var(--rgb-state-light), 0.3)
            }
            .shape.disabled {
              border-width: var(--ha-card-border-width,1px);
              border-style: solid;
              border-color: rgba(var(--rgb-disabled), 0.25)
            }

3 Likes

I’ll just add the simplest of configurations to remove everything around the button of a mushroom card here. Depending on your usecase, building this into a part of something bigger might be easier with this base-config.

The fill-container and layout tags make the button centered in whatever grid/stack/… you stick it:

type: custom:mushroom-light-card
    entity: light.your_lamp
    primary_info: none
    secondary_info: none
    fill_container: true
    layout: horizontal
    card_mod:
      style:
        .: |
          ha-card {
            border: unset;
            background: unset;
          }

Here’s another way to do it using the built in Tile card.

type: tile
entity: light.office
hide_state: true
name: ' '
icon: mdi:power
card_mod:
  style: |
    ha-card {
      border-width: 0px;
      background: none;
    }
1 Like

Sadly that doesn’t work correctly because the card info still shows up (with a label of " " as set in the name) which makes the “button” not square (more space to the right of the icon than to the left).

The following is necessary to make it work so the button is perfectly square:

....
  style: |
        ha-card {
          // clear out borders and backgrounds
          border: unset;
          background: unset;
        }
        ha-card ha-tile-info {
          // make info 0 px so it takes literally zero horizontal space
          width: 0px;
          // display: none makes the button shrink in height, no bueno
        }
        ha-card .info {
          // remove left padding from info
          padding-left: 0px;
        }
...
3 Likes

Ah… that makes sense. I wasn’t worred about it being perfectly square and was repositioning it anyway.
See the result for two button in the top right here.

It’s surprising that there isn’t a more efficient method to delete labels from HA cards. :face_with_diagonal_mouth:

1 Like

Yah. Empty label should result in the <div> that contains it simply not being added, IMO.