[GPIO] New GPIO Binding for OH3

I thought the delay time was the debounce time. I have been increasing the delay time in an attempt to mitigate the false readings I have been getting. I can experiment more this weekend. The ability to change GPIO settings from within the binding as suggested by @gab75 would be greatly appreciated.

Hi . You need
Rule with command line script.

ssh to OpenHAB:

sudo nano /etc/openhab/scripts/set_Input.sh

Type:
pigs m 6 r

Ctrl x
Y (Save file)

sudo chmod 755 /etc/openhab/scripts/set_Input.sh

Main UI:
settings
Bindings
Add
Exec Binding
Install

Main UI
Rules
Add
Type name “XXX”
Add Trigger
System Event
choose 80 - Things initialized
done
Add Action
Run Script
Rule DSL

copy text:

executeCommandLine("/etc/openhab/scripts/set_Input.sh")
logInfo(“XXX.rules”, “Input set”)

Save
Back

When Run the script manualy
in openHAB Log Viewier (http://192.168.XX.XX:9001/) You can see:

Input set

After restart OpenHAB in openHAB Log Viewier You can see:
Input set

If you need set the GPIO to input Mode using “pigs” in Main UI, simple Run script manualy in Main UI…

GPIO Output Mode pull up/down:

http://abyz.me.uk/rpi/pigpio/pigs.html#PUD

In any case, if you connect the GPIO pin to the VCC (3.3V) without changing the Mode, then a current (35 mA) flows through the GPIO.
And that’s actually why Remote GPIO Input seems to show someone something even without changing the Mode.

1 Like

Thanks for your quick reply!
I tried your solution and it seems to work fine. The debounce time now also works correctly.
I hope that in the final version of GPIO Binding this procedure will be automatic within the I/O configuration.

Thank you for developing this binding. But i have one question: As far as i understand the code (i am no coding expert :slight_smile: ), actually there is only the possibility for “on / off” commands. What i am looking for is the possibility of sending PWM requests to pigpio. Is there an easy way to do this or is this feature planned?

1 Like

That works thank you. I had some trouble getting the EXEC command in the script to work. I just created EXEC thing in the GUI and added the command to that. Then make a Running item for that thing and send it an ON in the rule instead of executing a script.
Thanks again for the help.

@jojo100 you may want to have a look at the RaspberryPi PWM Binding I wrote some time ago. It supports hardware and software PWM.

Thank you for the hint at your PWM Binding. looks interesting for me, despite of the need for running openhab with root privileges. Maybe I’ll give the exec-binding a try.

Thank you very much for this great Add On.

I had also Problems with the Input Signals and that I could not set a pull up or down resistor.

Because of this I added a pull up or down option to the code. They I saw the Input and Output were switched configured into JPigpio. I also fixed this by using the Constants of JPigpio. I put the changed files here: https://wordpressvonmorgen.dd-dns.de/pigpio/

Hopefully you will take over this changes in the Add on.

Best regards from Germany,
Sjoerd Takken

Thanks @nbauer,

I have got this working today and its running normal on the new OH3. I wanted to ask you if you have found a solution to fix the bug when restarting the Raspberry Pi ? as it reboots it doesn’t reset the pins. Everything stays ON When rebooting my RPi unlike the old GPIO binding for previous versions of OH were it reset the pins after complete reboot.

If anyone solved this issue please share and post to help.

Thanks you all in advanced.

I’m so glad you’ve made this binding, thanks!

I had some trouble getting the binding to work after installing. Posting incase this is useful for anyone else with same problem.

I’m using OpenHabian on a RPI3B+ on build 3.1.0.M2.

I was receiving a communication error using PIGPIO on the local RPI. I tried using localhost, 127.0.0.1, the IP address of the RPI itself, but none worked. I noticed that PIGPIO was only listening on IPv6 ::1. I stuck that into the binding config and it came straight up.

Thanks again to the creator for the work! :slight_smile:

1 Like

Hello, would this be fixed in next Version.

upgraded to the latest openhab 3.0.1 and i dont see gpio binding anywhere…How can i install it?Is it included or do i have to download it from somewhere?

Look here: GPIO - Bindings | openHAB
You have to install the Binding manually.

Hello everyone.

If for some reason the local installation (OpenHAB on a RPI3B+, build 3.0.1. or 3.1.0.M2) of GPIO Binding

does not work properly here is the installation procedure:

I will try to explain the procedure.
The installation consists of two steps.

  1. You need to install the PIGPIO daemon first (takes care of communication with GPIO):
  • ssh to OpenHAB and type
    sudo apt-get install pigpiod

  • then type
    sudo mkdir -p /etc/systemd/system/pigpiod.service.d/

  • then type
    sudo nano /etc/systemd/system/pigpiod.service.d/public.conf

  • paste or write to a file
    [Service]
    ExecStart=
    ExecStart=/usr/bin/pigpiod

  • Ctrl x
    Y (Save file)

  • then type
    sudo systemctl daemon-reload

  • then you can test if the local PIGPIO daemon is running (optional test)
    sudo systemctl restart pigpiod
    sudo systemctl status pigpiod

…answer is something like:

● pigpiod.service - Daemon required to control GPIO pins via pigpio
Loaded: loaded (/lib/systemd/system/pigpiod.service; enabled; vendor preset: enabled)
Drop-In: /etc/systemd/system/pigpiod.service.d
└─public.conf
Active: active (running) since Wed 2021-02-17 13:06:50 CET; 46min ago
Process: 375 ExecStart=/usr/bin/pigpiod (code=exited, status=0/SUCCESS)
Main PID: 396 (pigpiod)
Tasks: 6 (limit: 2181)
CGroup: /system.slice/pigpiod.service
└─396 /usr/bin/pigpiod

… the normal way to start the pigpio library.

  • Then type command
    (to automate running the daemon at boot time)
    sudo systemctl enable pigpiod

…answer is something like:
Created symlink /etc/systemd/system/multi-user.target.wants/pigpiod.service → /lib/systemd/system/pigpiod.service

  • If you want to be sure that the PIGPIO daemon will be active even after a reboot type (optional test)
    sudo reboot

After restarting OpenHAB

  • ssh to OpenHAB and type
    sudo systemctl status pigpiod

…answer is something like:

● pigpiod.service - Daemon required to control GPIO pins via pigpio
Loaded: loaded (/lib/systemd/system/pigpiod.service; enabled; vendor preset: enabled)
Drop-In: /etc/systemd/system/pigpiod.service.d
└─public.conf
Active: active (running) since Wed 2021-02-17 13:06:50 CET; 46min ago
Process: 375 ExecStart=/usr/bin/pigpiod (code=exited, status=0/SUCCESS)
Main PID: 396 (pigpiod)
Tasks: 6 (limit: 2181)
CGroup: /system.slice/pigpiod.service
└─396 /usr/bin/pigpiod

The normal way to start the pigpio library during boot.

Note:
The procedure is the same for both versions of OpenHAB (build 3.0.1. or 3.1.0.M2).

  1. The second step is installation GPIO Binding
    (takes care of communication with the PIGPIO daemon which you installed in the first step),
    you have three options:

a) manual installation:

  • ssh to OpenHAB and type
    openhab-cli console

Password: (default is “habopen” or “your password”)

the answer…

   |_|       3.0.1 - Release Build

… answer
Bundle ID: XXX

  • then type
    bundle:start org.openhab.binding.gpio

  • then type
    logout

b) download file from
https://openhab.jfrog.io/artifactory/libs-pullrequest-local/org/openhab/addons/bundles/org.openhab.binding.gpio/3.1.0-SNAPSHOT/org.openhab.binding.gpio-3.1.0-SNAPSHOT.jar

  • and copy it to
    \192.168.XXX.YYY\openHAB-addons
  • wait a moment
    and then you can configure GPIO via the OpenHAB Main UI:

Things
Add (+)
GPIO Binding
Add Manually (Pigpio Remote)

Create Thing

c) normally install GPIO binding via OpenHAB Main UI
this option only applies to 3.1.x bundle users (not for 3.0.1)

Main UI:
Settings
Bindings
Add (+)
GPIO Binding
Install

I hope this helps…
:slight_smile:

4 Likes

Check out the following link for setting GPIO in config.txt

GPIO control in config.txt - Raspberry Pi Documentation

Add this to the [all] section in the /boot/config.txt
I added gpio=17,23,24=ip and all of those pins were set to input after boot.

There are a lot of options you can do at boot.

  • ip - Input
  • op - Output
  • a0-a5 - Alt0-Alt5
  • dh - Driving high (for outputs)
  • dl - Driving low (for outputs)
  • pu - Pull up
  • pd - Pull down
  • pn/np - No pull

Hope this helps.

It does not seem to work on a reboot, just a boot

Does anyone know what this error is about.

2021-03-21 14:44:30.644 [WARN ] [.core.thing.binding.BaseThingHandler] - Handler PigpioRemoteHandler of thing gpio:pigpio-remote:c4f39c377e tried updating channel GarageDoor1Sensor although the handler was already disposed.

Thanks

that looks a little like a bug to me
this is in the OpenHAB logs right? (because core.thing.binding.BaseThingHandler) maybe describe situation when WARN log entry is thrown and maybe head over to github and ping Nils

Problem solved. It seems to have not liked being called a contact. As soon as I changed it to a switch, the handler error went away. So now I will just have to do some transformation to show the garage door OPEN instead of OFF.
Thanks

1 Like

I did it the same way, but created a rule for cron to run it every 10 minutes. Works great.

Thank you for contributing this binding, glad to see this will be included in the 3.1 release!

I have managed to install the binding on OH 3.01, created a thing, and then two items (as switches) (setting both up through text files, not the UI) to read two input pins. But trying to read them through OH, things do not go as expected. I am not sure whether this is an issue with the binding, my circuit, or just me not understanding well enough gpio.

For context: I have a setup that worked well under OH2 with the old GPIO binding. Basically two sets of window contacts, one for each floor, which I feed from the 3.3V pin of the Pi and then read each through a simple circuit with a pull down resistor connected to pins 17 and 18. That circuit definitively continues to work, as eg pigs r 18 will show me the correct state of the window contact, and changes when I open or close a window.

Now, after configuring the thing and items, that seems to work in principle, as the item does sometimes get a state assigned. However, more often than not it does not (the state is NULL), and it does definitively not update states when windows are opened or closed. Also, the pigs r 18 command now ceases to work as expected, ie it will report 0 regardless of whether the window is open or not. In order to get back to the expected behavior of the pigs read command I had to reboot the Pi with the gpio contact; eg restarting the pigpiod service alone did not help.

I have tried this both on the raspi 4 on which OH is installed, as well as on a seperate raspi 3; same behavior in both cases.

I am increasingly thinking this might have much to do with my circuit. There is a lot of wiring in there, basically about ten windows on each floor; so the voltage coming back to the Pi might not be that much. But given this worked well with the OH2 binding, I was thinking perhaps the new binding is perhaps too aggressive in rapidly polling the gpio pins? Is there perhaps a way to significantly slow that down?

I know this is difficult to diagnose remotely, but any thoughts or input would be much appreciated.

1 Like