GPIO Contact not Updating

  • Platform information:

    • Hardware: RaspberryPi 3B+
    • OS: Raspbian
    • Java Runtime Environment: openjdk version “1.8.0_232”
    • openHAB version: 2.5.0M5
  • Issue of the topic:

I have two Window Contacts connected to my GPIOs and I can see GPIO value changing as expected using "gpio read ". The command returns 0 for an open and 1 for a closed window. Unfortunately, openHAB does not seem to pick any change of state: When I open a window, there are no updates in the event.log.

openhab is already a member of group gpio.

  • Please post configurations (if applicable):
    • Items configuration related to the issue
Contact	GF_Kitchen_Window	"Küchenfenster [MAP(]"	(gWindow)	{ gpio="pin:1 activelow:yes" }
Contact	GF_LivingDining_Window	"Terrassentür [MAP(]"		(gWindow)	{ gpio="pin:0 activelow:yes" }
  • Sitemap configuration related to the issue
Text item=GF_Kitchen_Window
Text item=GF_LivingDining_Window
  • events.log related to the issue
2019-12-01 15:22:54.204 [ome.event.ItemUpdatedEvent] - Item 'GF_Kitchen_Window' has been updated.
2019-12-01 15:22:54.206 [ome.event.ItemUpdatedEvent] - Item 'GF_LivingDining_Window' has been updated.
2019-12-01 15:22:56.212 [vent.ItemStateChangedEvent] - GF_Kitchen_Window changed from NULL to UNDEF
2019-12-01 15:22:56.215 [GroupItemStateChangedEvent] - gWindow changed from NULL to CLOSED through GF_Kitchen_Window
2019-12-01 15:22:58.220 [vent.ItemStateChangedEvent] - GF_LivingDining_Window changed from NULL to UNDEF
2019-12-01 15:22:58.718 [vent.ItemStateChangedEvent] - GF_Kitchen_Window changed from UNDEF to CLOSED
2019-12-01 15:22:59.221 [vent.ItemStateChangedEvent] - GF_LivingDining_Window changed from UNDEF to CLOSED

I don’t have any experience with the GPIO binding, as I don’t run openhab on a Raspberry Pi, but as a result I have an alternate solution.

In order to control the GPIOs on a remote Pi I wrote MQTTany which allows you to use MQTT to send and receive GPIO states. It can also be run on the same Pi as openhab if you want.

You can set it up to either poll the pins or detect any transition, or both.

Good to provide this. But it shows state changes for the Items you say do not change. Can you expand on your problem? You get a change to UNDEF when you expect OPEN, perhaps?

After initializing the new GPIO item, it’s status goes from UNDEF to CLOSED, no matter whether the window is open or not. The gpio command however always gets the expected value (0 for OPEN and 1 for CLOSED).

MQTT would be a workaround, but I’d prefer to work with a built-in solution.

Sounds like you’re simply missing a pull up or pull down resistor.

Quite possible, this is my first time connecting external components to GPIO. I’ve built everything according to this howto. I was under the assumption that the 10k resistor is the pull-up/-down resistor you mentioned. But maybe I’m missing something.

You might need either a pullup or a pulldown depending on how your circuit is configured. It’s to ensure a wire connected to an open circuit switch is pulled to a known voltage, not left “floating”. If the resistor pulls to the same voltage as the switch when active … then nothing ever changes.

Get a meter and check voltage at your GPIO pin in both states.

I know little about the binding but this looks relevant

This might help

Quick update: I ended up writing a few lines of code (NodeJS) that watch my GPIOs and trigger MQTT messages once any changes are detected. So far, this seems to be working quite well.

var Gpio = require('onoff').Gpio,
    garden_window = new Gpio(27, 'in', 'both', {debounceTimeout: 10});
    kitchen_window = new Gpio(22, 'in', 'both', {debounceTimeout: 10});

var mqtt = require('mqtt')
var client  = mqtt.connect('mqtt://localhost:1883'), value) {
    if (err) exit();
    if (value == 1) {
        console.log('registered rising GPIO27');
        client.publish('openhab/window/livingdining', 'CLOSED')
    } else {
        console.log('registered falling GPIO27');
        client.publish('openhab/window/livingdining', 'OPEN')
});, value) {
    if (err) exit();
    if (value == 1) {
        console.log('registered rising GPIO22');
        client.publish('openhab/window/kitchen', 'CLOSED')
    } else {
        console.log('registered falling GPIO22');
        client.publish('openhab/window/kitchen', 'OPEN')

function exit() {
    console.log('window.js exit');
process.on('SIGINT', exit);