Issue with gpio and openHAB2

First of all I’m new to openhab so please stay with me if I say something stupid.

My problem is controlling a relay by gpio on a raspberry pi 3.
The relay is connected on gpio 29. I can control the relay by using

gpio write 29 0
gpio write 29 1

Items file contains

Switch RaspiRelay{ gpio="pin:29" }

Sitemap file contains

    sitemap standard label="Home" { 
    Frame label="Rasperry Pi GPIO"  
    Switch item=RaspiRelay

Nothinh happens when I press the switch. I noticed that running gpio from the terminal as user openhab doesn’t work also.

su -c "gpio write 29 1" - openhab

So I added openhab user to gpio and root groups, but it still doesn’t work.
Also I added


in /etc/default/openhab2 and


in /usr/lib/systemd/system/openhab2.service, but it still doesn’t work.

Karaf log doesnt show any errors. When I press the switch it shows:

    22:52:11.872 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'RaspiRelay' received command OFF
    22:52:11.882 [INFO ] [marthome.event.ItemStateChangedEvent] - RaspiRelay changed from ON to OFF
    22:52:25.483 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'RaspiRelay' received command ON
    22:52:25.495 [INFO ] [marthome.event.ItemStateChangedEvent] - RaspiRelay changed from OFF to ON

I’m lost, I cant figure it out what I’m missing.

I also wasn’t able to get the gpio binding to work.
Just use the exec 1.x binding like i do.

Items (my example):

Switch Powersupply_Printer “Strom Drucker” { exec=“ON:gpio write 21 0,OFF:gpio write 21 1” }
Switch Powersupply_Subwoofer “Strom Subwoofer” { exec=“ON:gpio write 22 0,OFF:gpio write 22 1” }
Switch Powersupply_Ambilight “Ambilight” { exec=“ON:gpio write 23 0,OFF:gpio write 23 1” }

1 Like

Thx @quangtuyentran. I was able to control the gpio pin using OH2 with the above steps and some reading from
I had to reboot my RPi after these steps for this to take effect.

Thx again. I had been struggling with this for last couple of days… :sunny:

Hi Andi, you made my day! After several frustrating tests, complete reinstallations of OH2 I found your hint, to use the 1.x binding instead of the 2.1. Finally my GPIO`s are working! Thanks - Jesco