openHAB2 and Raspberry Pi GPIO / Sensors

Hello,

Started using openHAB 2-beta3 and it is amazing how well it worked, I have it installed on a Raspberry Pi 3 and it hooked into my existing Philips Hue bridge + lights without a hitch. It also picked up my WeMo wall plug with just a few clicks. This just works :slight_smile:

Having trouble finding information/guidance on how I could access GPIO pins on my Raspberry Pi? Is this possible? I saw instructions that this is possible with 1.x version using openhab-addon-binding-gpio package; has anyone got this working using the 2.x release?

I am looking to read some sensors (motion, temperature, lux, humidity and noise level for starters) and use buttons in rules that are plugged into the GPIO.

Some of the guides indicate I need to install org.openhab.io.gpio and org.openhab.binding.gpio but I cannot see those on the Paper interface, so I assume these are 1.x legacy addons. I can’t seem to find the .jar file that I can place into my /usr/share/openhab2/addons to load them. :frowning:

They are legacy 1.x bindings. You can find them at http://www.openhab.org/getting-started/downloads.html

Search this forum for GPIO as several people have reported some issues with the GPIO behavior. If I remember correctly it has to do with the startup of OH behavior and restoreOnStartup or something like that.

Personally I use a Python Script I wrote to interact with the GPIO pins, though that has as much to do with the fact that my Pis are not running OH and are instead reporting to/receiving commands from OH.

Thanks Rich,

I managed to get GPIO bindings to show up, now I gotta do my part and read up more on this.

Thanks for the link to the python script, will look into that as well.

For me the gpio binding didn’t work on the first try with OH2. There might be some changes needed to make it compatible

Others have reported the binding to work with OH 2. What specifically didn’t work?

Just found out that my problems weren’t related to OH2, seems i had hit this problem:

Any documentation on how to install gpio binding in openhab2?

You should be able to activate the gpio binding via Paper Ui or add the binding to the bindings section in services/addons.cfg

Item Syntax is the same as oh 1

Hello,
I can now use GPIO as Input on OpenHAB 2 using Snapshot 2.1.0 Build #887
For GPIO Bindig i am using GPIO Binding Snapshot 1.10.0.201704230111

  1. The first you need install libjna 3.2.7 on your raspberry:
sudo apt-get autoremove libjna-java
sudo wget http://ftp.debian.org/debian/pool/main/libj/libjna-java/libjna-java_3.2.7-4_armhf.deb
sudo dpkg -i libjna-java_3.2.7-d_armhf.deb

2 . You need take a new file gpio.cfg into the folder: /etc/openhab2/services with this code:

sysfs=/sys
debounce=10

3 . add gpio to openhab group:

sudo adduser openhab gpio

4 . Example for items file:

Contact	ws_hall 		{gpio="pin:17 debounce:10 activelow:yes"}

5 . Example for rules file:

rule "hall light"
when
	Item ws_hall received update CLOSED
then
	if (hall_light.state==OFF) {
		hall_light.sendCommand(ON)
	} else {
		hall_light.sendCommand(OFF)
	}
	
end

i hope this info can help someone :slight_smile:

1 Like

Hey rich,
I also use python script on PI and run OH on the same machine with Http binding, but when I pressed the button for Lights, it dosen’t change the state of my GPIO pin, I used the post method of http binding but it is not happening. Do I need to run OH on a different machine?
Kindly note that the python script’s server run on port 6060 and OH run on port 8080

This sounds like a problem between OH and the python script you are using. We won’t be able to help with that as we have no information about how this python script works or what it expects.

But you are not required to run the python script on a separate machine from OH so long as they are all using different ports.

If you are talking about MY sensorReporter script, then you must use MQTT to send commands to sensorReporter from openHAB. It does not support HTTP for receiving commands, only for sending messages to openHAB.

Rich,
Thank you for your reply, I will update you on this,
The other thing I would like to know is, How am I suppose to install My open hab binding in openhab2,
I checked the documentation for it, but I did not find UUID and Secret files in the location suggested by them,
Kindly note that I installed the OH2 using the apt-get method.

You must install the binding first through PaperUI (or Habmin, or the Karaf Console). Then the binding will create those files. They do not exist before installing the binding.

But I do not get this binding in the paper UI, can you suggest the path?
or how to install it?

PaperUI > Add-Ons > MISC tab > openHAB Cloud Connector

Got it, Thanks Rich!!

Rich,
I did not installed the HTTP binding first, but now I have installed it, But it is still not working, any IDEA?
Do I need to restart openhab service?

What is not working? myopenhab or your Python script?

Did you read my previous reply? If the Python script is sensorReporter then HTTP will not work. You must use MQTT.

If it is some other Python script, we can’t help because we know nothing of this script or how to use it.

Rich,
When I use the following link in a web browser it turns my gpio pin ON.My script is not sensor Reporter script it just a web server.

http://192.168.0.108:5000/23/on
this turns the gpio on, but it is not working with http binding.
{http="[ON:POST:http://192.168.0.108:5000/23/on]"}