Contains() function with multiple values


The Expressioncontains()” looks for a string that contains X
The Expressionmatches()” looks for matches.

a b c
does not match
a or b

Edit: I wonder what your success would be using three letter words in your tests.


Hm. Nothing seems to work anymore. It works if I don’t use the OR pipe. Contains() and matches() both match single values, but only without the slashes and as soon as I add the OR it says false.

contains(texttomatch, 'two') is true.
contains(texttomatch, '/two/') is false.

I had a piston on Smarthings that matched weather conditions that worked fine for years and I noticed it doesn’t work anymore. I have moved to Hubitat, though, which is why I wondered where it’s evaluated.


I was thinking this too, but at the moment, I don’t have a Hubitat in the shop to test.


Try it in the “Evalutation Console”. All three of them were true for me.


Semantic error here, try using matches() instead of contains().


Like this?



Here’s an example:

[EDIT] I see now you are looking at multiple entries. I’ll play around with this…

[EDIT] Tried many different ways…can’t get multiple values to work. :frowning:


Strange. Worked for me:

EDIT: Tried on HE and it doesn’t work. Only works on ST for me.


I’ve recently moved over to Hubitat from SmartThings. matches() worked well in ST but does not work in Hubitat. Bummer, I had my sprinklers looking for keywords like ‘rain’ ‘sprink’ ‘driz’ in the forecast.

My workaround is to replace all instances of the the text to ‘’. Then compare it to the original string. In the second line I’m looking for “cloud” and it found it and so it was true. But the third line did not find any of the strings so it returned false.


Let’s tag @E_Sch, maybe he can check it out.


If you can give me a test piston that works on ST and fails on HE, that would be helpful for me to debug with…

Also be sure you are running latest he webcore

If using hpm to install do a repair on webcore in hpm


There are two example pistons posted above. Posts #20 (matches) and #22 (contains). It seems to be an issue with the way Hubitat evaluates the expressions. There have been a ton of firmware updates since, so I don’t know if it’s still an issue.


So contains is doing a simple string ‘contains’ groovy/java function

ie you cannot use a pattern.

If you want a pattern, you want to use matches()

I ran the test, and matches works fine for your pattern.

so contains does a string.contains, and matches does a pattern match.

In short, I don’t see a problem…

I’m running latest webcore on HE. I suggest you do an HPM repair on HE to ensure you have the latest webcore and retest…


Nothing changed for me. ¯\_(ツ)_/¯



Here is my test:



’ (single quote) versus " (double quote) ?


Got false result on mine, tried both single and double. My webcore installation on HE is not up to date though so not sure if that could have anything to do with it.


likely does have something to do with it…