Creating lists in vars


#1

I’m trying to create a list of strings and then use that list in a condition.

What’s interesting is that if I provide the strings a value in the condition the logic works, but I can’t figure out how to create my list as a variable to be interpolated in the condition.

What I’m getting at is this works:

But this doesn’t:

In the first example the variable weatherState is still defined but unused. I’ve tried setting it to typ String, or Dynamic. In both cases I get:

An error has occurred while subscribing: groovy.lang.MissingMethodException: No signature of method: java.util.ArrayList.startsWith() is applicable for argument types: (java.lang.String) values: [@]

The workaround in this case isn’t that difficult, but is there a way to create list or array variables that I’m missing?


#2

nvm… I see it now, “Advanced Lists…”

I’m blind.


#3

Advanced lists can’t be pre-populated like variables can though. Instead of using a canned condition, try this:

But substitute my sensors for [YourTemperatureSensor : weather]


#4

One drawback to be aware of though, is this will report true for partial matches too. You can see I deleted “Sunny” from the variable, but kept “Mostly Sunny, Partly Sunny”. Because the latter is still there, a check for “Sunny” will return true:

If this presents a problem for things you’re filtering out, there are other ways this can be done.