[00:00] Hey guys Matt here from MKSmartHouse.com and in this video I am going to show you how to use the OpenHAB 2 GPIO Binding. The GPIO Binding allows us to interact with the onboard gpio pins of the raspberry pi. [00:20] When I say interact I mean be able to turn the GPIO pins on and off as well as read the First up let's go over the parts I am going to use to demonstrate the GPIO binding. [00:33] I am going to use a white LED, 5 volt 4 Channel relay board, Momentary button and a door sensor. For tools we are just going to need female dupont jumper cables. The links to all the materials, tools and parts are over on my website, the link is [00:48] To make this guide easier I am going to be using my testing raspberry pi running a fresh I have a complete guide on my channel showing how to install and setup openhabian. [01:02] The raspberry pi is sitting in a clear plastic enclosure with a built in fan which is cooling I have a kit for the raspberry pi on my shop over at mksmarthouse.com/shop. [01:15] Now take the components and connect them to the raspberry pi using the female dupont jumper If you have any questions on the wiring ask it down in the comments below and I will try Here is a clip of my wiring. [01:33] I will not be doing two separate videos for mac and PC because the only difference is the software used to SSH, on mac you use terminal and on windows you use PUTTY. [01:45] To install the binding go to your openhab web user interface and click on paper ui. After that click on bindings and in the search type in GPIO and install the one that says [01:58] If you want to configure some other settings for the GPIO binding you can go to the configuration tab and then the bindings sub tab. After that you can click the configure button in the GPIO binding. [02:12] The binding is installed, now let’s use it. SSH into the raspberry pi using the program based on your operating system.I recomend having my website open so you can just copy and paste commands. [02:26] For this guide I am going to assume that you have an item's file,and a sitemap file. If you do not then check out my video where I cover the configuration files. Anyway the first thing we are going to do is create the items in the items file. [02:40] Type in sudo nano /etc/openhab2/items/home.items and press enter. Now type in: activelow:yes initialValue:low" } Switch channel3 "Channel 3" { gpio="pin:13 [02:55] Contact Button "Button [%s]" { gpio="pin:24 activelow:yes" } Let me explain what each item does and what each part means. The first part is the item type and since this will turn the LED ON and OFF we will [03:12] The next part is the item name and I just called it LED. After that is the label text and this is what shows up in the user interface, again I just The next part after that is the binding config. [03:28] I assigned this item to GPIO 21 because that is where I plugged in on the raspberry pi. The next set of items are for the relay board and since it is a 4 channel board I created [03:41] Each item is almost the same except for the binding config. I am going to show you a couple different ways you can configure this binding, but for this relay board the item config you should be using for every channel is the one on channel [03:54] The first part of the binding config is the pin to connect to and for this one is pin 26, the next part is activelow which is set to yes. Active low means that when the switch is off there will be no voltage applied to the gpio [04:10] pin and when the switch is on there will be voltage applied. After that is initialValue and what this does is tell openhab what to set the initial value This one is set to high because I want the switch to be off during initialization. [04:27] The next item is channel 2 and for this one I set activelow to yes and initialValue to So, this one will be like channel 1 except during initialization the switch will be on The binding config for channel 3 and 4 are a littile bit different because they do not [04:42] have the initialValue so instead they will use the default value of high. You will be able to see how the different items work later when I show you a demo of Next up is the gpio pins that act as inputs. [04:58] First is the door sensor and since the door sensor has two states open and closed we will For the label text I just wrote Door Sensor and format of the input as %s. [05:13] In the binding config I mapped it to GPIO pin 16, and set debounce to 10. Debounce means the time it waits before reading the input on a pin in milliseconds. After that is again activelow and this is set to yes because the way the button works [05:27] is it applies voltage which trip the pin high. The button item is basically the same except it does not have a debounce parameter in the That is it for the items file, now press control x, then y and enter to save. [05:40] Now we are going to put the items into the sitemap file so type in sudo nano /etc/openhab2/sitemaps/home.sitemap Switch item=LED [05:53] And press enter. To save press control x then y and enter to save. Go to your web user interface and then basic ui, I am going to do it on a tablet. [06:10] Before we play with the buttons lets take a look at the status of everything, The led is of and so is its switch, channel 1 is off so is its switch, channel 2 is on and so is its switch, chanel 3 is on and so is its switch, channel 4 is on but its switch is not on. [06:28] Now lets look at the input devices, the button is not pressed and on the interface it says open, and the door sensor is closed and on the interface it is also closed. Alright now let’s play with everything, when I turn the LED switch on the LED turns [06:43] To determine whether a relay is On just look at the leds on the relay board. When I turn on channel 1 the channel 1 relay turns on, When I turn off the channel 2 switch the relay turns off, when I turn off channel 3 the relay turns off. [06:58] But when I turn on channel 4 the relay turns off. Now let’s test out the input devices, when I press the button it goes to the closed state and when I separate the door sensor contacts it goes to the open state. [07:12] If you need any of the parts shown in the video you can buy a kit, the PCB or 3D printed parts to make this device as well as other devices at the link in the video description. [07:24] section below or head over to mksmarthouse.com/forum. Good Bye!