RPI3 GPIO's - How to set input/output mode?


I’m running OH 2.2.0 on Raspbian stretch on an RPI3 and seem to be missing something around setting the mode of GPIO pins prior to using them within OH.

Switch items appear to work out of the box as documented, I have this clicking a relay on & off:
Switch GateTrigger { gpio=“pin:23 initialValue:low force:yes” }

Contact items do not work for me using OH alone:
Contact GateOpen “Button [%s]” { gpio=“pin:25 activelow:no debounce:0” }
This will always read “CLOSED” no matter what is connected to the pin. Nothing happens when shorted to ground.

To troubleshoot I stopped OH and ran a simple python script to query the pin:
import RPi.GPIO as GPIO
import time
import os
GPIO.setup(25, GPIO.IN, pull_up_down=GPIO.PUD_UP)
while True:
input_state = GPIO.input(25)
if input_state == False:
print(‘Button Pressed’)

Not only did that work but from this point on the Contact item also started working in OH so clearly that Python pin setup does something which persists at the OS level to change that pin to input mode.

What is the official/best way to set these pin modes in Raspbian either within or before starting openhab? Do I have to just run a setup script prior to the OH service starting on each boot or is there a way to have OH itself set these pin modes? The gpio binding docs don’t have any recommendations beyond possibly needing to do ‘something’: “NOTE: Some boards may need additional pin configuration prior using them…”

Thank you,

It seems after a reboot that OH does set these gpio in/out modes by itself.
Don’t know what sequence of events caused it to not do so when I first created the items but this seems to all be working correctly now.

Also since found the methods to query & set these from the OS:
[23:28:39] root@pi-kitchen:/sys/class/gpio# cat gpio12/direction
[23:28:45] root@pi-kitchen:/sys/class/gpio# cat gpio18/direction
[23:28:49] root@pi-kitchen:/sys/class/gpio# cat gpio23/direction
[23:28:52] root@pi-kitchen:/sys/class/gpio# cat gpio25/direction