Contains() function with multiple values


#13

Or to make just one word case sensitive:
matches(Body, '/cool|Cool|nice/')

(pipes in the middle, and slashes at the beginning & end)

Edit: It just dawned on me that when you said, “in case sensitive”, you meant “case insensitive”.


@guxdude, I believe matches() is not in the Wiki due to all the typical problems that go along with regex and newbies. Honestly, I hope I do not regret posting that info.

IE: I would not go inserting matches() all willy-nilly in your pistons.


#14

If I would have known it was your Birthday, I would have waited 24 hours before taking back the crown, LOL


#15

LOL. Thanks!


#16

Now I am racking my brain trying to think of a piston I can write to use this information!


#17

Like a kid with a new toy, LOL


#18

Ok, I’ve greatly simplified this example trying to figure out this exact example. I have this:

matches('a b c d', 'a') with no slashes evaluates TRUE, but…
matches('a b c d', '/a/') with slashes evaluates FALSE, and…
matches('a b c d', '/a|b/') evaluates FALSE.

Shouldn’t these last two also evaluate true?

I had a piston that matched weather conditions that was greatly simplified using this method, but it’s not working after moving to Hubitat. I can’t even get the expressions to evaluate correctly.

Any thoughts?


#19

I would try a modified version of what I posted above… Maybe something like:

matches(var, '/a/')
matches(var, '/a|b/')

(var = a string variable previously set)


#20

This is still evaluating false. Where is the evaluation actually computed? On the dashboard or on the hub?


#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.