Lovelace: Button card

I’ve stumped myself. I created two buttons which are for the mostpart identical, with the exception that one entity_id is a sensor and the other is a switch. (superficial things like name and icon are different)

The result is:

image

  • The ‘Door’ button (sensor) displays its icon correctly while the ‘LR Fan’ (switch) button does not.

  • If I change the entity_id for the 2nd button to another sensor (instead of a switch), everything works as it should. From what I can tell, the icon is blank simply because the entity is a switch.

  • I’ve also determined removing color_type brings the icon back, but it appears as a different color (including when using the default skin), so that solution doesn’t really work either. I prefer to keep color_type in there because this is a WIP that will be incorporated into a decluttering card – I need to keep the option available of making some of them blank-cards.

Any ideas? yaml below. Thanks!

type: horizontal-stack
cards:
  - type: 'custom:button-card'
    color_type: null
    entity: sensor.lr_status_door
    hold_action:
      action: more-info
    icon: 'mdi:door'
    name: Door
    show_last_changed: true
    show_state: false
    size: 30%
    styles:
      card:
        - height: 100px
      label:
        - font-size: 9px
        - color: '#7babf7'
    tap_action:
      action: more-info
  - type: 'custom:button-card'
    color_type: null
    entity: switch.dev_fan_lr
    hold_action:
      action: more-info
    icon: 'mdi:fan'
    name: LR Fan
    show_last_changed: true
    show_state: false
    size: 30%
    styles:
      card:
        - height: 100px
      label:
        - font-size: 9px
        - color: '#7babf7'
    tap_action:
      action: toggle

I’ve tried to fix it. Is it better now? Thanks for your help, it’s really appreciated!

Please(!) help me understant one simple thing,
I’m working with lovelace, trying to understand how to make a template button.

Do I write the !Include <template_file.yaml> in the configuration.yaml file?
How the <template_file.yaml> syntax looks like?

refresh my memory, which post are we talking about here?

This one : Lovelace: Button card

change icon field from

icon: 'mdi:battery-unknown'

to

icon: |
  [[[
    if (entity === undefined)
      return 'mdi:battery-unknown';

    var s = entity.state;
    s = parseInt(s);
    if (isNan(s))
      return 'mdi:battery-unknown';

    s = Math.floor(s/10) * 10;
    if (s === 0)
      return 'mdi:battery-10';
    return `mdi:battery-${s}`;
  ]]]

and for color use…

color: |
  [[[
    if (entity === undefined)
      return 'gray';

    var s = entity.state;
    s = parseInt(s);
    if (isNan(s))
      return 'gray';

    if (s <= 15)
      return 'red';
    else if (s <= 49)
      return 'yellow';
    return 'green';
  [[[
1 Like

Im trying to figure out how to change the icon of a button card with javascript but i suck at it.
What i want to do is, if anyone of sensor.lights_status, sensor.switches_status, sensor.sensors_status shows the state Problems I want fas:exclamation-triangle icon. If not i want the icon fas:home to be shown.
I dont even know where to start and havnt found any code i understand and might be able to rewrite. :frowning:

Help is much appreciated!

@r1kkie This might not be the best way, but my solution to your problem takes two steps and is probably simpler than you thought it might be.

  1. Create a sensor that tells you if any of the three sensors in question shows the state ‘Problems.’
sensor:
  - platform: template
    sensors:
      sensor_problems:
        entity_id:
          - sensor.lights_status
          - sensor.switches_status
          - sensor.sensors_status
        friendly_name: 'Device Problems'
        value_template: >-
            {%- if is_state("sensor.lights_status", "Problems") -%}
                Yes
            {%- elif is_state("sensor.switches_status", "Problems") -%}
                Yes
            {%- elif is_state("sensor.sensors_status", "Problems") -%}
                Yes
            {%- else -%}
                No
            {%- endif -%}
  1. Include something like the below in your button config. When the entity.state is ‘Yes’, the button icon will change for you (To show you what else you can do with it, I’ve also written it below so that the icon color will turn red to get your attention. You could remove this, or play around to make it even more eye-catching by changing the card background, make the icon blink, etc. All up to you!)
type: 'custom:button-card'
entity: sensor.sensor_problems
icon: 'fas:home'
name: Sensor Problems
state:
  - value: 'Yes'
    icon: 'fas:exclamation-triangle'
    styles:
      icon:
        - color: red

Thanks for the reply and that worked great, didnt think about making a template sensor and then use that sensor as entity.

Did anyone add a custom logo to their button cards? I have devices from different manufacturers. Whenever they go offline for some reason (mostly due to Wink hub), I have to find the name of it and figure out which manufacturer and open their respective app to find out the issue.

Ex: (instead of notification circle, I want to show that the manufacturer’s small logo)
61592656-8ab54f80-abd6-11e9-8f6d-12c0b434cadf

Yeah you would have to use templating. If you look at the author’s Hass example you can see that he just uses html to link the logos. I am using same method to set custom material design icons for weather under time display. Here is how it looks and the code:

image

cards:
    - entity: sensor.simple_time
      show_icon: false
      show_state: false
      show_name: true
      show_label: true
      name: |
        [[[
          return states['sensor.simple_time'].state;
        ]]]
      label: |
        [[[ return `<ha-icon
          icon="mdi:home-thermometer"
          style="width: 18px; height: 18px; color: #5f6c83; opacity: 0.6;">
          </ha-icon><span> ` + states['climate.living_room'].attributes.current_temperature +`°F</span>
          <ha-icon
          icon="mdi:weather-cloudy"
          style="padding-left: 3px; width: 18px; height: 18px; color: #5f6c83; opacity: 0.6;">
          </ha-icon><span> ` + states['sensor.dark_sky_temperature'].state +`°F</span>` 
        ]]]
      styles:
        card:
          - width: 140px
          - padding-top: 11%
        name:
          - font-size: 27px
          - padding-bottom: 5px
        label:
          - font-size: 15px
      type: 'custom:button-card'

While we are on the subject, does anyone know how to add the dynamic Dark Sky weather icon instead of my static cloud?

1 Like

Thank you, @skynet01 I don’t think there is a way to display custom icon/image inside the notification ellipsis. Only icons from Materialdesignicons allowed.

I went ahead with ‘entity_picture’ and got this result instead.

Screen Shot 2020-03-10 at 12.12.56 PM

Screen Shot 2020-03-10 at 12.13.10 PM

          - type: 'custom:button-card'
            template: switches_lights_square
            size: 70% # icon size
            name: Bedroom
            entity: switch.bedroom_light
            entity_picture: '/local/kasalogo.png'
            custom_fields:
              notification: >
                [[[ return `<ha-icon
                icon="mdi:bed-king-outline"
                style="width: 18px; height: 18px; color: #5f6c83; opacity: 0.6;">
                </ha-icon>` ]]]

Cleaned up grid little bit and arranged icons to this effect.

Screen Shot 2020-03-10 at 3.19.25 PM

1 Like

I’m wondering if anyone has any thoughts on my previous post? I’m still struggling with absent icons.

You can create any html object, including a non-home-assistant style icon. You just can’t use ha-icon.

change color type to icon. then change your color to the grey. You modifying color type to null is causing the problem because switches and lights get their color property from the on/off colors where sensor just pulls the default color.

1 Like

Trying to figure out the grid setup but cant quit get it.
My current grid code looks like this:

styles:
    grid:
      - grid-template-areas: '"i n s" "i n l"'
      - grid-template-columns: 20% 30% 1fr
      - grid-template-rows: min-content min-content min-content

That results whats shown to the left in the picture below. What i would like is whats shown to the right, the name and state are aligned horizontal and label under the state. Any suggestions?


The red lines are just to illustrate the offsets.

Hi all,
I can’t get the slider entity row nice in the button card
When i set full row to true, the slider knob is placed at the right side of the button and i can not operate it
I folowed the example, what am i doing wrong?
Kind regards

You only have two rows detailed in your grid-template-areas.

See what happens if you try

      - grid-template-areas: '"i n ." "i n s" "i n l"'

Thank you, much better. Tried a bunch of combinations but didnt get it right. What does the dot mean/do in the first row “i n .”?