Fun with custom:button-card

Providing assistance is about back and forth to understand what you are trying to achieve. To suggest othewise is not understanding how assistance works.

Anyhow, perhaps what you are after is using a theme default like my-var-default: xxx and then using var(--my-var-default) when you want that default.

hardcoding default that comes from theme or card config is unnececery redundancy I would like to avoid. It includes usage of vars of course. And if you changing more values than color, it requires to do the same fo all styles being overriden by a card

Hi all
How can I get a human-friendly value from the value provided by the sensor of the duration device_class?

For example, 1.5 should be displayed as 01:30.

Is there any helper I missed? I'm aware about formatTime() and parseDuration() helpers but I don't think these are right ones. I did it regular JS-way. But I'm wondering if there is a built-in method.

thank you in advace

I'm trying to move as much as possible to the tile card, but it doesn't have all the necessary functions yet. Is anybody here that has a button card config that looks exactly the same as the tile card, so i can use both on the same page without having any visual differences?

My try:

Perfect, thanks !

Team,

Question: does visibility: work in button_card_templates?

I can't seem to get this to work - in a button card template:

TEMPLATE

  template_prox_start:
    variables:
      var_container: null
    visibility:
      - condition: and
        conditions:
          - condition: state
            entity: binary_sensor.node_newserver_status
            state: "on"
          - condition: state
            entity: '[[[ return `binary_sensor.${variables.var_container}_status`; ]]]'
            state: "off"

CARD

    - type: custom:button-card
      template: template_prox_start
      variables:
        var_container: ollama_142

The referred entity (binary_sensor.ollama_142_status) is "ON" but the button does not hide.

Maybe it should be configured slightly different?

Tnx!
DJ

I doubt it would work. Visibility is new(ish) and custom button card is old, and it's likely that it does not support JS templates.

It seems so. Visibility alone works, but not with templates. I think this card ignores unknown fields when rendering templates.

Has nothing to do with button-card which supports visibility no problem.

You can’t just add templates to the native ha visibility as you please, just because it is in button-card :slight_smile:

Because that is where your quest lies.

Btw button-card is fully up to date with latest ha so no issue there

I just came to a similar conclusion. I tried to force "computed" visibility into card's definition but still no dice. So must be read before the custom button can do anything with it :slight_smile:

type: custom:button-card
entity: light.dummy_light
variables:
  visibility:
    - condition: state
      entity: light.dummy_light
      state: "on"
  force_visibility:
    force_eval: true
    value: |
      [[[
        const cfg = this._config;
        cfg.visibility = variables.visibility;
      ]]]

Haha.. There's so many button-card things I would love to see in ALL cards.

If only all cards would have such fantastic, easy and efficient "style:" commands, we could stop fiddling around with CSS in card_mod (which I also think is great btw :slight_smile: )

Guess I was wishfull thinking.

Tnx!
DJ

1 Like

You might want to have a look at hidden . Isn’t that available on button-card?
I think it is and does the same albeit reversed

Yep it’s there and supports templates natively in button-card Main Options - custom:button-card documentation

1 Like

Yes, hidden was introduced just for this sort of application. It supports templates.

2 Likes

BINGO!

Here's (part of) the template

  template_prox_start:
    variables:
      var_container: null
      var_name: null
    tap_action:
      action: perform-action
      perform_action: button.press
      target:
        entity_id: "[[[ return `button.${variables.var_container}_start`; ]]]"
      confirmation:
        text: "[[[ return `Start ${variables.var_name}?`; ]]]"
    hidden: |
      [[[
        return states[`binary_sensor.${variables.var_container}_status`]?.state !== 'off';
      ]]]

This HIDES the button of the status of the variable is ON.
:clap:

2 Likes

yep, that's it
glad it works for you

My dashboard

2 Likes