custom-cards / button-card

❇️ Lovelace button-card for home assistant
MIT License
1.83k stars 227 forks source link

last_triggered #821

Closed werbi64 closed 5 months ago

werbi64 commented 5 months ago

hello,

I want to display last_triggered as a label, Here's my code:

    - type: custom:button-card
      entity: automation.alarme_ext_matin
      name: désactivation alarme matin extérieure
      template:
        - base_bouton
        - liste
      state:
        - value: 'on'
          styles:
            icon:
              - color: white
            img_cell:
              - box-shadow: 1px 1px 12px 0px white
        - value: 'off'
          styles:
            icon:
              - color: rgba(51,153,255,0.3)
            img_cell:
              - box-shadow: 1px 1px 12px 0px black
      layout: icon_name_state2nd
      show_label: true
      label: >
        [[[return helpers.relativeTime(states['automation.alarme_ext_matin'].attributes.last_triggered)]]]
      tap_action:
        action: toggle

I'm getting an error message: Capture d’écran du 2024-01-16 22-23-30

Thank you for everything, your code is fantastic

Mariusthvdb commented 5 months ago

this works:

    - type: custom:button-card
      entity: automation.afval_morgen
      show_state: true
      show_name: false
      show_label: true
      state_display: |
        [[[ return helpers.formatDateTime(entity.attributes.last_triggered); ]]]
      label: |
        [[[ return helpers.relativeTime(entity.attributes.last_triggered); ]]]

can you confirm?

Scherm­afbeelding 2024-01-17 om 11 36 27
werbi64 commented 5 months ago

That's how it works : type: custom:button-card entity: automation.alarme_ext_matin name: Alarme Extérieure template:

But when I integrate it into the whole, I get the same error message :

type: custom:button-card show_label: true show_icon: false show_name: false show_state: false template:

What am I doing wrong ?

Mariusthvdb commented 5 months ago

sorry but I cant read that, please format your code (and take out everything that has nothing to do with those values, leave out all styling )

my guess is then issue is not caused by those helper functions at all (if you say the single card works fine) but caused by some other issue. thats why you need to minimize the code to a working example and build from there

werbi64 commented 5 months ago

It's better ?

type: custom:button-card entity: automation.alarme_ext_matin show_label: true show_icon: false show_name: false show_state: false tap_action: action: more-info styles: grid:

Mariusthvdb commented 5 months ago

no, you need to format your code using the <> in the toolbar, select all of the code and then press the button

Scherm­afbeelding 2024-01-17 om 12 53 59

and for starters, only test the button-card at the bottom to see if that is ok

werbi64 commented 5 months ago
type: custom:button-card
entity: automation.alarme_ext_matin
show_label: true
show_icon: false
show_name: false
show_state: false
tap_action:
  action: more-info
styles:
  grid:
    - grid-template-areas: '"bouton"'
    - grid-template-columns: auto
    - grid-template-rows: min-content
custom_fields:
  bouton:
    card:
      type: vertical-stack
      cards:
        - type: custom:button-card
          entity: automation.alarme_ext_matin
          name: Alarme Extérieure
          layout: icon_name_state2nd
          show_state: true
          show_name: true
          show_label: true
          state_display: |
            [[[ return helpers.formatDateTime(entity.attributes.last_triggered);
            ]]]
          label: >
            [[[ return helpers.relativeTime(entity.attributes.last_triggered);
            ]]]
Mariusthvdb commented 5 months ago

better ;-)

now only test the bottom button

(Why on earth are you nesting a button in a button with the same entity? and use a vertical stack for that....)

you seem to have a support question (which should go to the community) and not a bug/issue with the card itself.

werbi64 commented 5 months ago

Thank you for your peace of mind !