Action/template is working in develeoper tools but not in button

Hi,

this issue drives me grazy. The simplified code for the action I am looking at is

action: vacuum.send_command
target:
  entity_id: vacuum.roborock_s7_maxv
data:
  command: app_segment_clean
  params:
    - segments: >
           {%- set mapper = {'Room23' : '[23]'} -%} 
           {%- set roomnr = mapper['Room23'] -%}
           {{- roomnr -}}

and it works as expected in Developer Tools.

However, basically the same code does not trigger the action in the button below

show_name: true
show_icon: true
type: button
entity: vacuum.roborock_s7_maxv
tap_action:
  action: perform-action
  perform_action: vacuum.send_command
  target:
    entity_id: vacuum.roborock_s7_maxv
  data:
    command: app_segment_clean
    params:
      - segments: >
          {%- set mapper = {'Room23' : '[23]'} -%}  {%- set roomnr =
          mapper['Room23'] -%} {{- roomnr -}}

The odd line breaks in the template part at the end are generated on Save by Home Assistant…
Replacing the last part with hard coded value resolves the issue

    params:
      - segments: [23]

But I need to use the mapper for different rooms (as I am actually using a input_select). For me it looks like the multiline part of yaml is not working. However, it is more likely that I am doing something wrong.

Any hints?

what errors are in your logs? Segments expects a list or a string that looks like a list. It depends on a few things. I’ve helped people in the past with this and you typically need to template the entire params field.

You can’t use templates in the standard Button card.

Move the action to a script then configure the Button card’s tap_action to call the script.

Ah, good catch

I do not see anything related in the logs

Yes. Because of this the value template generates a list with one value. It works in developer tools and as hard coded value but not in the action of the button. I also tried to use a list with two values. Same result.

see what 123 wrote

This will explain it. I tried it also with custom:button-card. But this obviously require js.
Thanks

1 Like

With the exception of the Markdown card, none of Home Assistant’s cards support (Jinja2) templates.

Some custom cards support either Javascript or Jinja2 templates.