Contacts Not Changing state

I’m have some trouble working the Contacts of open hab.
My set-up is as follows: Raspberry pi 2 model B. (Jessie)
Openhab 1.8.3 Installed via apt-get.
I have the gpio binding installed and working. I can turn on and off a led.
I have been trying to get a simple ON/OFF or OPEN/CLOSED to work.
i have tried making my own items, site maps. or adding in the bindings to the demo items and site map.
both of which i can operate the led but the status of the door or window that i put the contact binding on never changes sate when i physically move the wire to ether the 3.3v source or to ground.

I am by no means a programmer. I can recognise enough to be able to make small modifications or copy past to fit my needs.

I have tried going thrue the manual to no avail.

Thanks for any and all help.


There is a whole range of things that could be causing your problem. A big one is that you need to make sure you set your pull-up/pull-down correctly.

Personally, I have never tried to do GPIO from OH. My server is too far from my devices wired to my Raspberry Pis so I wrote my own Python script to read and report the state of door sensors to OH over MQTT.

You can look at it and see if it gives you some hints. I can confirm that it works.

Thanks for the reply.
Ya I am using a pull up resistor set-up. I don’t think the issue is in the physical set-up.

Here is some of the code that i’m using.

Contact Window_Kitchen_Door “Kitchen Door [MAP(]” (Inside_Kitchen) {gpio=“pin:27”}

Now for the most part I understand what is going on here. the first word is telling openhab what the item is. (Contact) Then the next peace of info is a describer your your own purposes. (Window_Kitchen_Door) The window is still in it because i have been modifying cutting and pasting from the demo. Then we have the mapping for the UI. (“Kitchen Door [MAP(]” For the life of me i can not figure out what is within the brackets. What it means and what it does. Then we have the grouping. (Inside,Kitchen) Now we have the actual device. ( {gpio=“pin:27”} )

Thanks for any explanation. This software looks really cool and for the most part fairly straight forward. But im shore im stumbling on syntax here. Not being a programmer my self. I have not that much clue of what im looking at.


Also can any one explain what this peace of code does?
Group:Contacts:OR(OPEN, CLOSED) Windows “Open windows [(%d)]”

Also I don’t know if this is normal. But when I change something in items I loose the contacts in the web app. I still have control of the switches but all the contacts go grey. I have done the init.d addition to unbind the gpio’s on a restart but that dose nothing. the only way to get them back it to reboot the pi.

Another thing that is weird some time I can add an item the exact say way as another item but it dosn’t show up.

It seams like there is a cap on the amount of items you can have. if I add a munch for different things things that i start with will start to disappear.


ok issue with the contacts has been fixed found this post. Raspian Jessie / GPIO input replaced my existing gpio binding and io.jar files with these did the trick.

But still having the weird issue of some of my items not showing up.

When you change something in the items file, it reloads the whole file and all the items within usually get set to an ‘uninitialized’ state. It’s left to your choice to accept or handle that. You might create rules to set items to some known start-up state, or use the persistence services to remember what they were last known to be.

That part is the label. On your sitemap it will read "Kitchen Door " on the left side. The stuff in the “[]” represents the state of the Item and the MAP( indicates that you want to print the state on your sitemap as a String (%s) and you want to map the state of the Item (i.e. OPEN or CLOSED). The MAP( part says that instead of printing the state as is, you want to instead use what is in file.

If you look at the demo, there is an file in the transformations folder. Open this file and you should see the following two lines (among others):


So putting it all together, when the Item is OPEN your sitemap will read:

Kitchen Door                               Open

and when closed it will read:

Kitchen Door                               Closed

In essence, in this case all the MAP does is let you have a nicely capitalized word on your sitemap instead the all caps version you would get by default.

NOTE: When you put an Item on your sitemap, particularly as a Text, if you do not include [%s], or one of the other % formats (there are special versions for date/times and numbers) you will not see the state of your Item on the sitemap.

NOTE 2: When you supply a label tag in your sitemap it will override what is defined in your Item file.

This is all documented in the label section of the Item wiki page.

This one is documented on the Item wiki page as well.

  • Group - define a new Group Item
  • Contacts - if you put this Item on your sitemap, or send it a command, treat it as a Contact Item, NOTE: all members of the Group much be able to receive Open/Closed commands
  • OR - when calculating the state of the Group Item, OR the stats of all the members of the Group
  • (OPEN, CLOSED) - If one or more of the members of the group are OPEN, set the state of the Group to OPEN, otherwise set it to CLOSED
  • Windows - the name of the Group
  • “Open windows [(%d)]” - the label for the Group when put on the sitemap, the (%d) part would print the state as a number and the label implies that it is supposed to be the number of total windows open but the Group definition is not correct to get that value so I don’t know what will happen here.
  • (All) - Windows is a member of the All group.

This is normal. When you change an Items file all of your Items get rest to Undefined until they receive some event to set them again. To avoid this you need to set up persistence with restoreOnStartup so your Items get initialized to whatever state they were before the Items were releoded.

The restart of the Pi probably works because when the GPIO binding starts it probably probes the pins for their current state. If that is the case, you shouldn’t need to restart the Pi. You could just touch the gpio binding jar file which will restart that binding.

Items defined in an .items file that don’t show up usually indicates a syntax error preventing the rest of the file from being loaded. I recommend using Designer and looking for errors in your log file.

People have setups with many hundreds of Items. There is no hard limit.

Thanks for all that info. Its has been a big help. I am learning more and more every day.

Thanks again. for all your help.