Lovelace: Button card

you could at least take out the icon: ‘mdi:arrow-up’…

i did, doesn´t fix it.

I might :wink: not using decluttering-templates though, and trying to set it in the card config or template is uses for now.

maybe tell us what it does do?

isnt very meaningful yet

but I dont think you need the state:part for that, if you use the entity directly.
try to use the

    icon: >
      [[[
        if (entity.attributes.current_position == 100) return "mdi:arrow-left"; return "mdi:arrow-right";
      ]]]

in the toplevel section of the button?

Yes me too. I’ll watch your conversation…
And copy what you discover ;-):stuck_out_tongue_winking_eye:

ye sure, sorry!

so if i remove it and use this code it just shows a standart cover icon.

type: 'custom:button-card'
entity: cover.balkon
name: Oben
state:
  - operator: template
    icon: >
      [[[
        if (entity.attributes.current_position == 100) return "mdi:arrow-left"; return "mdi:arrow-right";
      ]]]
tap_action:
  action: call-service
  haptic: success
  service: cover.set_cover_position
  service_data:
    position: 100

updated my response above. It works…

that one worked. thanks alot!

This would be the way to keep a leading 0:

[[[
  var d = new Date(entity.last_changed);
  return `${("0" + d.getHours()).slice(-2)}:${("0" + d.getMinutes()).slice(-2)}`
]]]

Action field should support templates.

action: >
  [[[ if (['automation','light','switch'].includes(entity.entity_id.split('.')[0])) return 'call-service'; return 'more-info']]]

That’s the 3 templates I use to display the 3 buttons on top:
image

cover_up:
  template: cover_button
  icon: mdi:arrow-up-thick
  tap_action:
    action: call-service
    service: cover.open_cover
    service_data:
      entity_id: entity
  state:
    - operator: template
      value: >
        [[[ return entity.attributes.current_position == 100 ]]]
      styles:
        icon:
          - opacity: 0.3

cover_stop:
  template: cover_button
  icon: mdi:stop
  tap_action:
    action: call-service
    service: cover.stop_cover
    service_data:
      entity_id: entity

cover_down:
  template: cover_button
  icon: mdi:arrow-down-thick
  tap_action:
    action: call-service
    service: cover.close_cover
    service_data:
      entity_id: entity
  state:
    - operator: template
      value: >
        [[[ return entity.attributes.current_position == 0 ]]]
      styles:
        icon:
          - opacity: 0.3

This should give you some inspiration.

cool! thanks a bunch again!

Just to be sure, we can’t use the ‘domain’ in the JS templates, like we can in jinja? entity.domain

I checked and I can’t see the domain attribute in the object (not something I can change), so apparently not :slight_smile:

1 Like

and yes, this works:
13

now only need to show it was yesterday (or more) when time > current time… and then show ‘(number of day) days ago’

this is magic of another level :wink: can template quite a few template cards away now… :wink: so glad I asked

Hi, I asked in declutering template forum, but not answers there
im trying to migrate my cards from anchors and after a few changes,i have this problem with this one:


This my template:

  tracker:
    card:
      type: custom:button-card
      show_entity_picture: true
      entity: '[[entity]]'
      entity_picture: '[[entity-picture]]'
      label: > 
           {{ return states['[[entity_id]]'].attributes.battery + '% de bateria' }}    
      tap_action:
        action: more-info
      color: auto
      size: 100%
      show_state: true
      show_name: false
      show_label: true
      state:
        - value: "not_home"              
          styles:
            card:
              - border: 5px outset red
        - value: "home"             
          styles:
            card:
              - border: 5px outset green
      styles:
        name:
          - padding: 0px 10px
          - font-size: 13px
          - font-family: Helvetica 
          - justify-self: start
          - font-weight: bold
        label:
          - color: gray
          - font-size: 10px
          - font-family: Helvetica
          - padding: 0px 10px
          - justify-self: start
          - text-transform: capitalize
        state:
          - font-size: 11px
          - font-family: Helvetica
          - padding: 0px 10px
          - justify-self: start
          - text-transform: capitalize
          - font-weight: bold
        card:  
          - padding: 0px

I tried several options in label option but similar results
and the card:

          - type: custom:decluttering-card
            template: tracker                      
            variables:
              - entity: person.jorge
              - entity-picture: /local/jorge.png
              - label: >

Some help please and thanks

Templates are created with [[[ ]]] not with {{ }} in button-card:

  tracker:
    card:
      type: custom:button-card
      show_entity_picture: true
      entity: '[[entity]]'
      entity_picture: '[[entity-picture]]'
      label: > 
           [[[ return states['[[entity_id]]'].attributes.battery + '% de bateria' ]]]
      tap_action:
        action: more-info
      color: auto
      size: 100%
      show_state: true
      show_name: false
      show_label: true
      state:
        - value: "not_home"              
          styles:
            card:
              - border: 5px outset red
        - value: "home"             
          styles:
            card:
              - border: 5px outset green
      styles:
        name:
          - padding: 0px 10px
          - font-size: 13px
          - font-family: Helvetica 
          - justify-self: start
          - font-weight: bold
        label:
          - color: gray
          - font-size: 10px
          - font-family: Helvetica
          - padding: 0px 10px
          - justify-self: start
          - text-transform: capitalize
        state:
          - font-size: 11px
          - font-family: Helvetica
          - padding: 0px 10px
          - justify-self: start
          - text-transform: capitalize
          - font-weight: bold
        card:  
          - padding: 0px

I have two questions about this wonderfull card.

  1. Templates are saved in ui-lovelace.yaml beginning from position 0 or are indented beginning from position 3?
  2. Is there a way, using the tap_action, to call a specified card. I mean if i have a card using the mini-media-graph custom card, may i call that card when tapping over the button ?

Thanks.

thanks for answer,I had tried it that way too ,but when i do the card disappears
maybe is this not possible with decluttering templates?
regards and thaks again

Actually the error is that [[entity_id]] doesn’t exist. Replace that bit with [[entity]] since your variable is called entity :wink:

1 Like

thanks,you are my hero,but my problem now is that the entity i use is a person type(person.jorge) but the battery atribute is from another entity (device_tracker)

Just provide another variable (name it how you want) with the value being your device_tracker and replace entity in the label with the new variable name.