Use Text Helper as Name in a Button

This is what I want to achieve, but it doesn’t work:

- type: button
    tap_action:
      action: toggle
    icon_height: 42px
    name: '{{ states(''input_text.ac_preset_3_name'') }}'
    hold_action:
      action: toggle
    show_name: true
    show_icon: true
    entity: input_boolean.ac_timer_toggle_preset_3
    icon: mdi:clock-fast

All I see is the template text {{ states(’‘input_text.ac_preset_3_name’’) }} showing as the button name, not the variable itself.

Intent is that the Name of the button is user-customisable as an editable Helper, and then the button to activate the relevant automation shows that name.

Can this be done?

Lovelace dose not accept templates without a custom card. Try this one (it’s JavaScript, not jinja):

1 Like

Thanks, will check that out. :+1:

I cannot get that to retrieve a text helper’s state.

Using this code, keeping it simple for now:

type: custom:config-template-card
entities:
  - input_boolean.ac_timer_toggle_preset_3
card:
  type: entities
  entities:
    - entity: input_boolean.ac_timer_toggle_preset_3
      name: ${states["input_text.ac_preset_3_name"]}

The entity has a name of “object Object”

Experimenting in the Developer Tools template:
(note normal bracket / square bracket)

value: "{{ states('input_text.ac_preset_3_name') }}"
value: "{{ states['input_text.ac_preset_3_name'] }}"

…returning:

value: "P3"
value: "<template TemplateState(<state input_text.ac_preset_3_name=P3; editable=True, min=0, max=100, pattern=None, mode=text, friendly_name=A/C Preset 3 Name @ 2021-08-29T16:52:57.065726+10:00>)>"

I cannot see a way to get the text helper’s value into the config-template-card.

This gets the text helper’s attributes:

    - entity: input_boolean.ac_timer_toggle_preset_3
      name: ${states['input_text.ac_preset_3_name'].attributes.mode}

So I see “text” as the name…

But I cannot get the text helper’s actual value.

OK, sorted. Final config that worked for a button inside config-template-card is:

type: custom:config-template-card
entities:
  - input_boolean.ac_timer_toggle_preset_4
card:
  type: button
  tap_action:
    action: toggle
  entity: input_boolean.ac_timer_toggle_preset_4
  name: ${states['input_text.ac_preset_4_name'].state}
  show_state: false
  icon_height: 42px
  hold_action:
    action: none
  icon: mdi:clock-fast

Trying to do something similar, but with a browser mod pop-up. The image name is stored in an input_text. Anybody that has a solution for this?

            - type: 'custom:button-card'
              template: chip_icon_label
              icon: mdi:motion-sensor
              tap_action:
                action: fire-dom-event
                browser_mod:
                  command: popup
                  deviceID: this
                  title: Laatste voordeur detectie
                  card:
                    type: picture
                    image: >-
                      {{ 'https://XXX/local/snapshots/' + states.input_text.cam_snap_timestamp.state + '_gang.jpg' }}

Thanks!