String interpolation for sequence

Hi all!
I’m creating an automation for my 4-button scene switch, and I need some help :slight_smile:
Each button has 3 actions (single-, double- and long press), so as you can imagine the blueprint will get quite big.

I don’t want 12 conditions and think 4 is plenty, but for this I need string interpolation.
Right now, I have this for every action:

- conditions:
    - "{{ command == '1_single' }}"
  sequence: !input "button_one_short_press"

My goal is to this for the 4 types of presses:

- conditions:
    - "{{ command is match('.*_single') }}"
  sequence: !input "button_{{ button_number }}_short_press"

My variables look like this:

- variables:
    command: "{{ trigger.to_state.state }}"
    button_number: "{{ trigger.to_state.state | regex_replace('\\D', '') }}"

Sadly, this doesn’t work. The issue is the string interpolation for the input name in the sequence. Eventually I’ll probably just give the inputs the same names as the actions, but even interpolating the entire string does not work.
Is this not supported at all within Home Assistant, or can someone push me in the right direction? :smiley:

edit: not relevant for the question, but it’s for the Tuya Zigbee 4-button scene switch linked with Z2M. I’ll share the automation when I have this solved

There are numerous blueprints in the blueprint exchange for this most likely. Either use one of them or look at them to inspire your own take at it.

If you are creating an automation, they do not use !inputs.
If you are creating a blueprint, that’s not how !inputs work.

You SHOULD first write an automation that does exactly what you want to achieve then plug in the stuff to make it a blueprint. Getting the logic working is not always easy, and becomes obfuscated in all that variable substitution stuff, making everything frustrating.
Get what you want working, then make the blueprint out of that by adding the !inputs and variables and such.

Thanks for your reply!
There are multiple existing blueprints indeed, and it’s not too difficult to create one that is working.
My issue however is that I don’t want a huge decision tree with 12 conditions, and it looks way better if I optimize it a bit.

You’re telling me this is not how inputs work:

sequence: !input "button_{{ button_number }}_short_press"

I know they do work like this:

sequence: !input "button_3_short_press"

But is there any way of dynamically referencing the inputs that works?
It makes blueprints so much cleaner and improves readability, in my opinion.

I think I was having a bad day. That is how !inputs work. Sorry about that.
Or at least That looks like it could work, but I would have to play around with it.

At first I thought you were defining an !input that way, but clearly you are not.

Ah no worries!
What I found is that any way of dynamic referencing always seems to result in an error.
Maybe I’m doing something wrong, or maybe it’s just not supported.
Almost looks like I’d have to call a service with the variable input as data, but that only makes things more complicated which is the opposite of what I’m trying to do :joy: