{{ if... any of these input_selectors contains this string }}

Hello;

I am trying to set up an < if / else > template within a TTS automation message that searches for a specific string of text selected in any of three different input_selects. I would like to map the selectors to avoid multiple if statements, but my template doesn’t seem to work. I’ve been scouring the internet all day to try and find anything similar, but I can’t seem to find anything.

Here is the condition in question:

{{ if ['input_select.keg_1','input_select.keg_2','input_select.keg_3'] | map('states') == "Coming Soon" }}
Here's what's coming soon...
{{ else }}...

What you have posted doesn’t really “search” the list in any way. It is effectively asking “Is this list the same as a string”, so it will always be false. There are a few ways to search through the list of states. If the complete value of the state will be “Coming Soon”, then you can use the following:

{% if "Coming Soon" in ['input_select.keg_1','input_select.keg_2','input_select.keg_3'] | map('states') | list  %}
  Here's what's coming soon...
{% else %}
  ...
{% endif %}

But if “Coming Soon” is only part of the state value, you will need to use one of the regex-based functions:

{% if ['input_select.keg_1','input_select.keg_2','input_select.keg_3'] 
| map('states') | list is search("Coming Soon") %}

Don’t forget to replace the double braces with {% and %} because it’s an “if else endif”.

1 Like

Hello again Drew!

Yeah, it was only throwing “false” and nothing I tried would work.

The complete value of the state is indeed “Coming Soon”, so your first suggestion works like a charm, thanks for that! Ironically, I tried it the other way around, listing the inputs with “in”… but nothing worked there. So close and yet so far. The regex option will be noted as well, its a good thing to know and you all teach us novices so much.

@Taras: Good call, I should have mentioned I was pseudo-coding for the sake of brevity - but its good to mention here for anyone that might stumble upon this.

Thanks again guys!