[SOLVED] REGEX not working for my after migration to openhab 2


(Kimberly Fischer) #1

after converting my openhab to version 2 (i am running 2.4 snapshot) on windows 10.

linkage8/linkage

the words “linkage” above are in <>

is part of my data that is returned in an item

Number nCheckCam1Alarm “Front Porch [MAP(onoffcam.map):%d]” { http="<[http://192.168.0.1:88/cgi-bin/CGIProxy.fcgi?cmd=getMotionDetectConfig&usr=xxxxx&pwd=xxxxxx:4000:REGEX(.?(.?).*)]" }

This used to make the item value 8 in openhab 1.x
In openhab 2 it never changes from its initital value of 0


(Vincent Regaud) #2

Can you post the whole data please?


(Kimberly Fischer) #3

how do i post my results in this text box without it losing my formating? its removing the tags

<CGI_Result>
0
1
8
2
3
10
1
0
281474976710655
281474976710655
281474976710655
281474976710655
281474976710655
281474976710655
281474976710655
255
255
255
255
255
255
255
255
255
255
</CGI_Result>


(Vincent Regaud) #4

See:


(Kimberly Fischer) #5

Thanks…

Here is the openhab item

Number nCam1Alarm	   "Motion Detected [(%d)]"     { http="<http://192.168.0.xxx:port/cgi-bin/CGIProxy.fcgi?cmd=getDevState&usr=xxxxxxx&pwd=xxxxxxxx:4000:REGEX(.*?<motionDetectAlarm>(.*?)</motionDetectAlarm>.*)]" }

This is the result from the call when the http command is executed from a web browser.

<CGI_Result>
    <result>0</result>
    <IOAlarm>0</IOAlarm>
    <motionDetectAlarm>1</motionDetectAlarm>
    <soundAlarm>1</soundAlarm>
    <record>0</record>
    <sdState>0</sdState>
    <sdFreeSpace>0k</sdFreeSpace>
    <sdTotalSpace>0k</sdTotalSpace>
    <ntpState>1</ntpState>
    <ddnsState>0</ddnsState>
    <url>http%3A%2F%2Fik5078.myfoscam.org%3A89</url>
    <upnpState>1</upnpState>
    <isWifiConnected>0</isWifiConnected>
    <wifiConnectedAP></wifiConnectedAP>
    <infraLedState>1</infraLedState>
</CGI_Result>

This worked in openhab 1.x…when motion was detected and the value changed to 2.

this rule never fires:

rule “cam 1 motion detect”
when
Item nCam1Alarm changed
then

Thanks in advance.

Kim


(David Graeff) #6

Regex is fine here, but rule and item file parsing is way more strict now in openHAB 2 then it was before. That means that any special character need to be escaped (colons for example). If you go to https://regex101.com/ and enter your regex, you will see a parser error for example.

Use the XPath transformation instead is my recommendation.


(Kimberly Fischer) #7

Thanks…by adding a \ to the regex in regex101.com … it seemed to work…but as soon as i add a backslash to my item file the whole item file has errors and it ignores my items completely.

so in my item i have

   /motionDetectAlarm
changing that to
   \/motionDetectAlarm

invalidates my entire item file.

kim


(David Graeff) #8

Yeah that is a longer story actually. You are using an openHAB 1 binding (http), so you must configure it in the item file. But the item file itself does not allow specific characters without escaping them (with a backslash).

So you basically need to double escape ("\\"). This problem will hopefully be gone with http2 in OH 2.5.


(Kimberly Fischer) #9

so i changed it to

<\\/motionDetectAlarm>

but now am back to square one as its not updating with value.

giving me a headache…gonna stop for a while and come back to it fresh later. thanks

Kim


(Kimberly Fischer) #10

Thanks again!! came back to it later (after a nap,lol). Uninstalled the http binding and reinstall it…working now with double backslash.
Thanks again

kim