Lovelace: Button card

ahhh perfect! Thank you

You rock dude!!! Iā€™ve managed to use your integration perfectly, along with using the Philips icon repository you created but Iā€™m struggling to have the ā€œphilips circleā€. Do you mind to share it?

Itā€™s not my integration :wink:

The code for my ā€œphilips circleā€ is in this post:

Thanks for answering so fast :+1:
I used that code :wink: But the code mentions custom:circle icon which is not on the code you shared nor the icon repository. Maybe is somewhere else?

Well spotted, my mistake. This is from my other icon pack:

It should then be referenced as kongo09:circle. I should update that sometimeā€¦

1 Like

in your card you should still add the custom_field it self. Right now, you only entered the styles for the custom_field.
see the last lines of Lovelace: Button card - #6239 by Mariusthvdb

there you point that field to your card entity, which is set to the timer you desire?

Ohā€¦ with entiy.state the label appears, wonderfulā€¦ Iā€™m beginning to understand

But if I insert timer.scaldabagno the terminal give me an error:

custom_fields:
  notification: >
    [[[ return timer.scaldabagno; ]]]

ButtonCardJSTemplateError: ReferenceError: Canā€™t find variable: timer in ā€˜return timer.scaldabagno ;ā€™

The entity is correct:

that is because for Java script (which is the language these templates are in) you are now returning a ā€˜variableā€™ timer. You want to return the entity.state directly.

And how i tell to HA that i want a duration of timer? (The countdown)
I try with template but does not work.

now why dont you try what I have been suggesting you now for 3 timesā€¦ and then show us the button result. entity.state should show as ā€˜idleā€™, like your screenshot shows. Or, ofcourse, when counting, it should show the remaining time.

This might require some extra work, because I am not sure if it update every second automaticallyā€¦ but thats the next step.

first do as I asked, and use entity state.

O, and if you read the documentation, (and my remarks above): button-card uses Javascript (JS) templates, and not Jinja templates, like core HA does.

Your template will not work, and if you want an attribute, youā€™d need something else. (I wont tell you now, because then you will still not enter that I asked you to :wink: )

(btw, these screenshots of the ui editor are not very useful. Better paste your correctly formatted yaml code, and a separate screenshot of the button.)

garagedoors

          styles:
            card:
              - height: 7em
              - border-top: 24px groove brown
              - border-right: 14px groove gray
              - border-left: 14px groove gray
              - background: >-
                  repeating-linear-gradient(0deg, black 10px, gray 10px, silver
                  24px)
              - background-blend-mode: darken
              - border-radius: 1em 1em 0em 0em
1 Like

Ok, here you are the screenshot and the code.
But, the entity.state return the state of input_boolean.scaldabagno_temporizzato, not the timer.scaldabagno status.

Schermata 2022-01-07 alle 23.50.04

type: custom:button-card
entity: input_boolean.scaldabagno_temporizzato
name: Scaldabagno Timer
icon: mdi:thermometer-plus
custom_fields:
  notification: |
    [[[ return entity.state ]]]
styles:
  img_cell:
    - justify-content: start
    - align-items: start
    - padding-left: 10px
    - padding-bottom: 10px
  custom_fields:
    notification:
      - border: 1px solid var(--text-color-on)
      - border-radius: 12px
      - font-size: 11px
      - font-weight: bold
      - height: 18px
      - line-height: 18px
      - min-width: 12px
      - padding: 0px 3px
      - position: absolute
      - right: 5%
      - top: 10%

Thank you for your patience

right, thats cool, and now I see you dont need the entity at allā€¦ sorry for that, I was distracted by the object_id.

now you need to call the state of timer.scaldabagno and do that in JS like states['timer.scaldabagno'].state.

in the template hooks:

[[[ return states['timer.scaldabagno'].state; ]]]

and since weā€™re in the learning mode, please forgive me to tell you to ā€˜delimitā€™ those JS lines with a semi-colon always, making sure it is the end of a line. just grow the habit.

Well well wellā€¦ Now I see ā€œIdleā€ when the button is OFF and ā€œactiveā€ when the button is ON
The countdown is not yet visible.
Here you are the code:

type: custom:button-card
entity: input_boolean.scaldabagno_temporizzato
name: Scaldabagno Timer
icon: mdi:thermometer-plus
custom_fields:
  notification: |
    [[[ return states['timer.scaldabagno'].state; ]]]
styles:
  img_cell:
    - justify-content: start
    - align-items: start
    - padding-left: 10px
    - padding-bottom: 10px
  custom_fields:
    notification:
      - border: 1px solid var(--text-color-on)
      - border-radius: 12px
      - font-size: 11px
      - font-weight: bold
      - height: 18px
      - line-height: 18px
      - min-width: 12px
      - padding: 0px 3px
      - position: absolute
      - right: 5%
      - top: 10%

Schermata 2022-01-08 alle 00.04.28

you might want to format you button a bit, or at least put in in a grid card with eg 4 column, so it gets resized. than you get a better feeling for the space you want it to use and the different relative proportions of the card sections. add 1/1 for square.

  - type: grid
    columns: 4
    cards:

      - type: custom:button-card
        aspect_ratio: 1/1
        triggers_update: timer.scaldabagno

what happens when the countdown is started, can you show that in the dev tools?

as said, it might need a ā€˜hackā€™ that is to tell HA to update an entity every second. but maybe not, first add the timer to the triggers_update: option like above

If that doesnt help, you can implement an automation, that you only fire under certain conditions:

automation:

  - alias: Second updater
    id: Second updater
    mode: restart
    trigger:
      platform: time_pattern
      seconds: '/1'
    condition:
      condition: state
      entity_id: input_boolean.second_updater
      state: 'on'
    action:
      service: homeassistant.update_entity
      entity_id:
        - sensor.second_updater
        - sensor.new_years_day_countdown
        - sensor.since_new_years_day_counting

Iā€™ve inserted your new lines of code.
The following screenshots show you the button and dev tools before I click on the button and after.
Iā€™ve added one more screenshot that show you the timer bar in another my experiment.
Seems that the timer was been updated every seconds.

Schermata 2022-01-08 alle 00.20.32

Thanks

1 Like

@Mariusthvdb maybeā€¦ you donā€™t have a timer to try to put it in a botton on you configuration?
To verify if you see ā€œIdleā€ / ā€œActiveā€ or if you see the minutes.
Maybe my config are wrongā€¦

no sorry, but I guess you want the ā€˜remainingā€™ attribute to be displayed?
you can eg make the color change on state (grey for idle, orange for active), so you can see that in the icon, and then have the attribute show the remaining time, (when active only)

[[[ states['timer.scaldabagno'].attributes.remaining; ]]]

and

styles:
  icon:
    - color: >
        [[[ return entity.state === 'active' ? 'orange' ; 'grey'; ]]]

Yes, I would like the remaining value, the countdown.
Iā€™ve inserted the ā€œattributes.remainingā€ code but that does not work.
I canā€™t see the digits of the timer remaining.
Why? :cry:


Iā€™ve try 2 solutions but they donā€™t work; here you are the 2 solutions tested:

[[[ states['timer.scaldabagno'].attributes.remaining; ]]]
[[[ return states['timer.scaldabagno'].attributes.remaining; ]]]

Actual code and below the screenshot of the result:

type: custom:button-card
aspect_ratio: 1/1
triggers_update: timer.scaldabagno
entity: input_boolean.scaldabagno_temporizzato
name: Scaldabagno Timer
icon: mdi:thermometer-plus
custom_fields:
  notification: >
    [[[ states['timer.scaldabagno'].attributes.remaining; ]]]
styles:
  img_cell:
    - justify-content: start
    - align-items: start
    - padding-left: 10px
    - padding-bottom: 10px
  custom_fields:
    notification:
      - border: 1px solid var(--text-color-on)
      - border-radius: 12px
      - font-size: 11px
      - font-weight: bold
      - height: 18px
      - line-height: 18px
      - min-width: 12px
      - padding: 0px 3px
      - position: absolute
      - right: 5%
      - top: 10%

Schermata 2022-01-08 alle 09.23.09

About the color icon, for now, itā€™s best if I focus on one piece of code at a time

Thx

You forgot/ need return

That is only available when active?