How to create a simple toggle switch for a input boolean

I’d like to create a simple toggle switch like this:

No name, no icon, just the sole switch as above.

The only way I could do it was using the entities card.
However, it won’t allow me to to style it correctly. Example:

type: entities
entities:
  - entity: input_boolean.my_input_boolean
    name: " "
    icon: None
grid_options:
  columns: 2

Will give me this:
image

It is close, but not there yet. An apparently it breaks the grid by rendering the switch outside its area.

I tried using other cards, like entity, but I can’t find make it use the toggle switch like above. Example:

type: entity
entity: input_boolean.my_input_boolean
name: " "
icon: None
grid_options:
  columns: 2

Gives me this:

Not even close.

Any suggestions?
Thanks a lot!

Adapt to your needs as you like:

type: entities
entities:
  - entity: xxx
    name: " "
    icon: mdi:blank
    card_mod:
      style:
        hui-generic-entity-row $: |
          state-badge, .info {
            display: none;
          }
        .: |
          hui-generic-entity-row {
            justify-content: center;
          }
card_mod:
  style: |
    #states {
      padding-left: 0;
      padding-right: 0;
    }
grid_options:
  columns: 2

3 Likes

Thanks a lot!
It works well.

The only unfortunate is card mod will not work if inside a horizontal stack or a grid layout. :confused:

What? Elaborate )

If you put the card with the Card Mod customisations in a sections layout, it will work. However, if you put it inside of a horizontal-stack, apparently card-mod won’t work.

Example - in a sections layout, I have this:

type: entities
show_header_toggle: false
state_color: false
grid_options:
  columns: 2
entities:
  - entity:  <input_boolean entity>
    name: ""
    icon: mdi:blank
    card_mod:
      style:
        hui-generic-entity-row $: |
          state-badge, .info {
            display: none;
          }
        .: |
          hui-generic-entity-row {
            justify-content: center;
          }
card_mod:
  style: |
    ha-card {
      height: 56px !important;
      justify-content: center !important;
      background: transparent !important;
      border: none
    }
    #states {
      padding-left: 0;
      padding-right: 0;
    }

It will render just fine like this:

image

(not including the code for the cards on the left here).

However, if I put these 2 cards on a horizontal-stack, like this:

type: custom:layout-card
layout_type: custom:grid-layout
layout:
  grid-template-columns: 10fr 2fr
  grid-template-rows: none
  grid-template-areas: |
    "left right" 
cards:
  - <first card here>
    view_layout:
      grid-area: left
  - type: entities
    view_layout:
      grid-area: right
    show_header_toggle: false
    state_color: false
    entities:
      - entity: <input_boolean entity>
        name: ""
        icon: mdi:blank
        card_mod:
          style:
            hui-generic-entity-row $: |
              state-badge, .info {
                display: none;
              }
            .: |
              hui-generic-entity-row {
                justify-content: center;
              }
    card_mod:
      style: |
        ha-card {
          height: 56px !important;
          justify-content: center !important;
          background: transparent !important;
          border: none
        }
        #states {
          padding-left: 0;
          padding-right: 0;
        }

I’ll get this:

image

Notice properties height, background, and border got ignored.
The inner most card_mod style works 100%.

Card-mod 3 docs says:

NOTE: card-mod only works on cards that contain a ha-card element. This includes almost every card which can be seen, but not e.g. conditional, entity_filter, vertical-stack, horizontal-stack, grid.

Note, though that those cards often include other cards, which card-mod can work on.
See the manual for each card to see how to specify parameters for the included card(s).

EDIT: I don’t think that’s the issue, though. Something changes when it is inside a layout-card. I couldn’t find what it is.

Maybe I’m doing something stupid, though.

Thanks again for helping. Highly appreciated.

This is correct. But not applied to this case. Entities card with card-mod (ANY card with ha-card) will be always properly styled - standalone, in grid or in section.
The note in Docs says “you cannot apply card-mod to the stack/grid ITSELF” (like “style a stack’s title”). For this mod-card is needed, not a big deal).

Better “grid-template-columns: 10fr auto”.

Your example with added Entity card:

I really don’t get why it doesn’t work for me.

This is exactly what I have:

            type: vertical-stack
            cards:
              - type: custom:layout-card
                layout_type: custom:grid-layout
                layout:
                  grid-template-columns: 10fr auto
                  grid-template-rows: auto
                  grid-template-areas: |
                    "left right" 
                cards:
                  - type: custom:bubble-card
                    card_type: button
                    button_type: slider
                    name: Waking Up
                    entity: input_number.loft_bedroom_wake_up_before_alarm
                    card_layout: large-2-rows
                    show_state: true
                    scrolling_effect: false
                    show_attribute: false
                    view_layout:
                      grid-area: left
                    styles: |
                      .bubble-range-fill { 
                        background: ${hass.states['input_boolean.loft_bedroom_wake_up_before_alarm_enabled'].state == 'on' ? '#ff9800' : 'rgba(79, 69, 87, 1)'} !important;
                        opacity: 1 !important;
                      }
                    sub_button:
                      - entity: sensor.loft_bedroom_wake_up_time
                        show_attribute: true
                        attribute: person
                        show_name: false
                        show_state: false
                        show_icon: true
                        show_background: true
                        icon: mdi:account
                        show_last_changed: false
                      - entity: sensor.loft_bedroom_wake_up_time
                        show_attribute: true
                        attribute: alarm_ui_friendly
                        show_icon: true
                        icon: mdi:clock
                  - type: entities
                    show_header_toggle: false
                    state_color: false
                    entities:
                      - entity: input_boolean.loft_bedroom_wake_up_before_alarm_enabled
                        name: ' '
                        icon: mdi:blank
                        card_mod:
                          style:
                            hui-generic-entity-row $: |
                              state-badge, .info {
                                display: none;
                              }
                            .: |
                              hui-generic-entity-row {
                                justify-content: center;
                              }
                    card_mod:
                      style: |
                        ha-card {
                          height: 56px !important;
                          justify-content: center !important;
                          background: transparent !important;
                          border: none
                        }
                        #states {
                          padding-left: 0;
                          padding-right: 0;
                        }

image

I really don’t get it.

I got your example and tried now:

type: custom:layout-card
layout_type: custom:grid-layout
layout:
  grid-template-columns: 10fr auto
  grid-template-rows: none
  grid-template-areas: |
    "left right"
cards:
  - type: entity
    entity: sun.sun
    view_layout:
      grid-area: left
  - type: entities
    entities:
      - entity: input_boolean.loft_bedroom_wake_up_before_alarm_enabled
        view_layout:
          grid-area: right
        name: ' '
        icon: mdi:blank
        card_mod:
          style:
            hui-generic-entity-row $: |
              state-badge, .info {
                display: none;
              }
            .: |
              hui-generic-entity-row {
                justify-content: center;
              }
    card_mod:
      style: |
        ha-card {
          height: 56px !important;
          justify-content: center !important;
          background: transparent !important;
          border: none
        }
        #states {
          padding-left: 0;
          padding-right: 0;
        }

Not using bubble-card - may be it is not supposed to be used in horiz-stack.
See, when a card is placed in grid or horiz-stack - it is supposed to occupy a whole height. All stock cards have “height: 100%” (exception - stack-like cards, thus there are related issues in github).
Add a style to your bubble-card:

:host {height: 100%;}

May be for some sub-container elements it would be needed too. Experiment!

Got it.
But the toggle switch still renders without the customisations.
I’ll keep trying…

Why do you think so?
Take my example - it does (at least for MY original styles).
Not sure why you need these (as for background & border - it is clear):

I need those because the bubble-card (first card) has a different height. Then the toggle switch seems to be lower.
I alternatively vertically centered the bubble-card. I added this to its style:

:host {
  display: flex;
  flex-direction: column;
  justify-content: center !important;
}

However, I can’t get rid of the toggle switch border and background. For some reason it seems to be completely ignored.

I do not have background & border (this code):

I know. That’s why I don’t get it.
For the exact same code (literally just copied and pasted), I get this:

card-mod version 3.4.4?

Yes. Latest version (v3.4.4).
Everything up do date as well.

Make sure you are using 3.4.4.
Could be some cashing issue.
Tested in Win10+Chrome/FF, iOS Companion App (iOS 15.7.x).

I am using it.
I tried to clean the cache. No improvement. :frowning: