Lovelace: Button card

Yep, tried either group entity in the single template and they both worked ok. I’m just baffled as to why it’s not working.

Just tried with individual entities in case groups was the problem, but still no luck.

            - box-shadow: |
                [[[
                  return ( states['light.study_desk_lamp'].state == 'off' ||
                           states['binary_sensor.window_study_main_contact'].state == 'off' )
                  ? '0px 0px 5px grey' : '0px 0px 5px red';
                ]]]

Hmm, even trying on another style doesn’t work either:

      - type: custom:button-card
        entity: binary_sensor.window_study_main_contact
        show_state: true
        show_icon: false
        name: Test
        styles:
          card:
            - border-radius: 15px
            - border: 'solid 1.5px rgb(0,0,0)'
            - font-size: 17px
            - width: 200px
            - padding: 4%
            - box-shadow: |
                [[[
                  return ( states['light.study_desk_lamp'].state == 'off' ||
                           states['binary_sensor.window_study_main_contact'].state == 'off' )
                  ? '0px 0px 5px grey' : '0px 0px 5px red';
                ]]]
          name:
            - color: |
                [[[
                  return ( states['light.study_desk_lamp'].state == 'off' ||
                           states['binary_sensor.window_study_main_contact'].state == 'off' )
                  ? 'grey' : 'red';
                ]]]

It just defaults to the first option (grey in the example above). If I swap grey and red text around, text becomes red:
image

oddly enough I found another template, (also working :wink: ) which has the closing ‘)’ completely at the end:

var phrase = (temp <= 6 || day == 'off' ? 'Vijverpompen mogen: ' : 'Vijverpompen moeten: ');

though this is a var declaration, you could try that… but it’s a guess, (because the template also works in the corrected version with the closing ‘)’ after ‘off’

var phrase = (temp <= 6 || day == 'off' )? 'Vijverpompen mogen: ' : 'Vijverpompen moeten: ';

and I don’t like that really… we should just understand why the above template doesnt work.

Thanks, I’ll try those out.

Just to double check the issue is with my config somewhere, would you mind trying my test button code above with two of your entities to see if it works please?

sure:

  - type: custom:button-card
    entity: light.couch_library
    show_state: true
    show_icon: false
    name: Test
    styles:
      card:
        - border-radius: 15px
        - border: 'solid 1.5px rgb(0,0,0)'
        - font-size: 17px
        - width: 200px
        - padding: 4%
        - box-shadow: |
            [[[
              return ( states['light.bureau_right'].state == 'off' ||
                       states['light.bureau_left'].state == 'off' )
              ? '0px 0px 5px grey' : '0px 0px 5px red';
            ]]]
      name:
        - color: |
            [[[
              return ( states['light.bureau_right'].state == 'off' ||
                       states['light.bureau_left'].state == 'off' )
              ? 'grey' : 'red';
            ]]]

working perfectly …

both lights on:

Schermafbeelding 2020-10-05 om 16.50.42

and either (or both) ‘off’

Schermafbeelding 2020-10-05 om 16.50.55

I really appreciate you testing that, thank you!!

I’m very puzzled now - time for more testing…

There’s nothing wrong with your code. Are you sure your groups have the appropriate state in the dev panel of HA?
Also sometimes a HA restart helps :wink:

Is there any way to wrap text? I want to keep the font size the same but when locked this card it too cramped for my liking.
image

Just use styles, style the name/label/state with a smaller width, and a bigger height. Don’t forget to change text wrap.

You can do:
name: Living<br/>Room

1 Like

This just changed it to Living Ro…

This worked

I have this lock code working as is, I want to add another state, “Watch Live TV”, to the template so the card locks with either. How would I do that?

        lock:
          enabled: >
            [[[ return states['sensor.harmony_activity_living_room'].state === 'Watch Fire TV' ]]]
          exemptions: []

Try

return states['sensor.harmony_activity_living_room'].state === 'Watch Fire TV' || states['sensor.harmony_activity_living_room'].state === 'Watch Live TV'

Worked perfectly, thanks!

I’m full of questions today. I have the below template and card entry. The button is not displaying the “primary color” when the binary sensor on. Functionality is ok. Is this a template issue or do I have something wrong?

button_card_templates:
  sonos_master:
    variables:
      var_entity:
      var_name:
      var:option:
    entity: '[[[ return variables.var_entity ]]]'
    name: '[[[ return variables.var_name ]]]'
    tap_action:
      action: call-service
      service: input_select.select_option
      service_data:
        entity_id: input_select.sonos_master
        option: '[[[ return variables.var_option ]]]'
    color: var(--paper-card-background-color)
    color_type: card
    show_icon: false
    show_name: true
    state:
      - color: var(--primary-color)
        value: 'on'
        styles:
          name:
            - color: var(--secondary-background-color)
    styles:
      card:
        - transform: scale(0.95)
        - background-size: 100% 100%
        - border-style: solid
        - border-width: 2px
        - border-color: var(--primary-color)
        - height: 60px
      name:
        - font-size: 20px
        - font-variant: small-caps

type: custom:button-card
template: sonos_master
variables:
  var_entity: binary_sensor.sonos_master_office
  var_option: media_player.sonos_office
  var_name: Office

Just a guess, try replacing state: 'on'. Also sometimes edit mode stops button-card from getting updates for me.

Replace what? Sorry, not following

value: on with state: on, actually that’s not real, sorry. I think you mean

styles:
  name:
    - color: var(--primary-color)

not background color.

Thats not it, I change the font color to a dark color when the button lights up

What if you put the state filter before the standard color?

You can’t use javascript templates for the entity field, that’s why it’s not working.