Lovelace: Button card

Anyone had problem like me?

Thank you. Cool idea to grab the automation trigger timestamp :wink:
Both works
I donā€™t wanted to create a new sensor only for displaying that on one button

Yeah, it was the only possibility to show the correct state change of a binary sensor (and to avoid false positives due to resets).

I hope I meet the right person with my question ^^
my dashboard consists almost entirely of custom:button_card.
here I try to adapt almost everything exclusively to templates.

I also try to use variables (entity.entity_id.splitā€¦etc) as much as possibleā€¦

now it is the case that i would like to display the states of some sensors.
They are in custom_fields

header_temp_buero:

    custom_fields:
      temp:
        card:
          styles:
            card:
              - background-color: transparent
              - width: 50px
              - box-shadow: none
          layout: vertical
          name: '[[[ return ` ${states[''sensor.buero_temp''].state}Ā°` ]]]'
          type: custom:button-card

I have created a template for each sensor at the moment. and then tie them in separatelyā€¦ for bathrooms then as an example:

name: Bathroom
template:
  - header_temp_buero:
..........

Is there a way I can make this easier? or is that the best way?

Use variables in your custom fields, too (in combination with triggers_update):

# Testsensor: sensor.cpu
type: custom:button-card
triggers_update: all
variables:
  name: Temperatur BĆ¼ro
  temp: sensor.cpu
name: |
  [[[ return variables.name ]]]
styles:
  grid:
    - grid-template-areas: '"n" "temp"'
    - justify-items: center
custom_fields:
  temp:
    card:
      styles:
        card:
          - background-color: transparent
          - width: 50px
          - box-shadow: none
      layout: vertical
      name: |
        [[[ return states[variables.temp].state + 'Ā°' ]]]
      type: custom:button-card

1 Like

thanks for the food for thought!! That worked wonderfully!

button_card_templates:
  header_temp_var:
    styles:
      grid:
        - grid-template-areas: '"temp n door"'
        - grid-template-columns: max-content 1.5fr min-content
        - grid-template-rows: 1fr min-content min-content
    custom_fields:
      temp:
        card:
          styles:
            card:
              - background-color: transparent
              - width: 50px
              - box-shadow: none
          layout: vertical
          name: |
            [[[ return states[variables.temp].state + 'Ā°' ]]]
          type: custom:button-card
name: BĆ¼ro
template:
  - header
  - header_temp_var
  - header_door_var
type: custom:button-card
variables:
  temp: sensor.buero_temp
  door: binary_sensor.ty13600724840d8eae6714

I have now ā€œfirstā€ selected three templatesā€¦
header is normal, it is standardā€¦
and then one for temp and one for the door/window sensors.

Not every room has bothā€¦ maybe we can also work with ā€œif/elseā€ here, but I think the code is very short like this

Thank you!

Hi all, one question, is it possible in the button_card_templates.yaml file to link another file with
!Include my_file.yaml to split file?

button_card_templates.yaml

!include my_file.yaml

Thanks.

If you are using the header template in general, you can insert it in all your other ones, e.g.:


button_card_templates:
  header_temp_var:
    template: header
    styles:
      ā€¦
      ā€¦

did you try it?

Thatā€™s rightā€¦ I have that with other cards tooā€¦ then Iā€™ll save myself an entry =)

yes but it doesnā€™t work.

Why I canā€™t see picture from entity_picture template?

here is code:

                - type: custom:button-card
                  aspect_ratio: 2/3
                  size: 100%
                  show_entity_picture: true
                  entity_picture: >-
                    [[[ if (states['media_player.livingroom_mp'].state == 'paused' ||
                    states['media_player.livingroom_mp'].state == 'playing') return
                    `${states['sensor.livingroom_mp_media_cover'].state}`; if
                    (states['media_player.livingroom_mp'].state == 'idle') return
                    '/local/images/logos/kodi.png';
                    else return
                    '/local/images/logos/kodi_red.png';
                    ]]]

pic5

the it probably doest work :wink:

you can however use button_card_templates: !include_dir_merge_named ../button_card_templates

and have as many files there as you want.
Not the same, but it does help you to keep the template files clear and organized

adapt the path to your situation

1 Like

try:

                  entity_picture: >-
                    [[[ if (states['media_player.livingroom_mp'].state == 'paused' ||
                            states['media_player.livingroom_mp'].state == 'playing') return
                              states['sensor.livingroom_mp_media_cover'].state; 
                        if (states['media_player.livingroom_mp'].state == 'idle') return
                          '/local/images/logos/kodi.png';
                        return '/local/images/logos/kodi_red.png';
                    ]]]

assuming the sensor.livingroom_mp_media_cover is a picture

if that works, use:

entity_picture: >-
  [[[ var state = states['media_player.livingroom_mp'].state;
      if (state == 'paused' || state == 'playing') return
          states['sensor.livingroom_mp_media_cover'].state; 
      if (state == 'idle') return '/local/images/logos/kodi.png';
      return '/local/images/logos/kodi_red.png'; ]]]

btw, is this for a button with that entity media_player.livingroom_mp? if so, you can simply use entity.state

What is the output of this sensor? Try without it.

This sensor collect data from entity_picture when media_player.livingroom_mp plays video and put data to sensor sensor.livingroom_mp_media_cover so I can see cover on remote ha.Because that is not working on remote home assistant integration. This sensor is working correctly.

When playing stops I canā€™t see images taken from local ha /local/images/logos/kodi.png when idle and /local/images/logos/kodi_red.png when unavailable.

When playing I can see picture from sensor.livingroom_mp_media_cover:
pic6

I canā€™t use entity_picture from media_player.livingroom_mp because this is remote ha and not working trough remote home assistant integration.

I tryed like you say but not working.

                - type: custom:button-card
                  aspect_ratio: 2/3
                  size: 100%
                  show_entity_picture: true
                  entity_picture: >-
                    [[[ var state = states['media_player.livingroom_mp'].state;
                        if (state == 'paused' || state == 'playing') return
                            states['sensor.livingroom_mp_media_cover'].state; 
                        if (state == 'idle') return '/local/images/logos/kodi.png';
                        return '/local/images/logos/kodi_red.png'; ]]]

View playing or paused:
pic7

View idle and unavailable
pic5

Then either the state could be other than idle (maybe paused) or the path to the entity picture could be wrong. Have you checked that both in your images folder and in the config of your sensor?

Yes, and there should be an error in Inspector console about this.

What does the sensor return, could you post a screenshot of dev tools state for it?

when idle


pic9png

when playing


pic12

pictures location:
pic13