Contains() function with multiple values


#21

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

IE:
a b c
does not match
a or b


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


#22

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.


#23

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


#24

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


#25

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


#26

Like this?

image


#27

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:


#28

Strange. Worked for me:

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


#29

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.


#30

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


#31

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


#32

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.


#33

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…


#34

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

image


#35

Here is my test:

36%20PM


#36

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


#37

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.


#38

likely does have something to do with it…


#39

Screenshot_2021-10-14%20webCoRE%20Dashboard
Screenshot_2021-10-14%20webCoRE%20Dashboard1
Screenshot_2021-10-14%20webCoRE%20Hubitat%20One2