[SOLVED] Global Cache/UDP Binding - Contact Closure

Hi all,

I’m not really a noob nor am I extremely verse with openhab. I have been able to use the global cache binding to talk to IR devices and it works great (with my Itach Flex).

The problem is I am trying to read the states of a contact closure without any success. I have noticed that the binding says that sensor in and sensor notify features are not currently supported but I was hoping to find a way around this. Here is what I’ve tried so far:

  1. Looking at the code which makes up the binding in hopes of being able to add the features. - I got lost in that java code, but that was fun, maybe a bit beyond where I am at the moment with openhab.
  2. Using a TCP/UDP binding. - The iHelp and iTest programs (I am on Windows 10) work perfectly to confirm that the Itach Flex is communicating over my network. If I could just work out how to ‘poll’ the contact closure I could use UDP to always know the status of it. I believe this is the best option along with a rule or two to decide what to do when the state changes.

Any suggestions on this matter would be greatly appreciated.

You could possibly use the iTach Flex HTTP API and the openHAB HTTP binding.

That would entail installing the http binding. See here.

Documentation for the Flex HTTP API can be found here.

1 Like

Thanks a lot for the response. I am currently looking into it. I thought I should be using the UDP binding but HTTP really does look promising. I will let you know when I get it to work.

So far I think I don’t know how to parse the response correctly (if I am actually getting a response). I will try a few more things so I can know the right questions to ask if I don’t figure it out.

Thanks again.

Ok so the Flex HTTP API was not as helpfull as I hoped but it did point me in the right direction. I found the Global Caché RESTful HTTP API which took me the rest of the way. I haven’t gotten polling to work yet but I am confident that I can get a working solution from here.

Thanks for the support.

I got it to work! Here is how:

In the conf/services/http.cfg file I created my http binding variable:

contactsensor.url= http://192.168.xxx.xxx/api/host/modules/1/sensors/ports/3
contactsensor.updateInterval= 1000

In an .items file I created a string variable to receive the status of the port

String portStatus { http="<[contactsensor:1000:JSONPATH($.state)]" }

and finally I created a rule that runs whenever the state changes so as to update my sitemap interface.

rule “Get Device state”
when
Item portStatus changed
then
logInfo(“checkState.rules”, "State: " + portStatus.state )
if (portStatus.state==“1”)
sendCommand(MyRelay3,“ON”)
else
sendCommand(MyRelay3,“OFF”)
end

Of course you would have to know what ports to check, I’m checking port 3 in the example above. This was set in the http definition of contactsensor.url.

Nice! Well done.