Anybody Use GPIO Pins for Input?

I’m just starting to look at OH. I had it installed once, just for testing and to confirm it works. I have a Raspberry Pi 3B+.

What I’d like to do is monitor the states of a bank of 4-5 relays which are powered from my heating system. When a zone or burner comes on, a relay closes the contacts. Those contacts are wired directly to the appropriate RPi GPIO pins. It’s just like a switch; either open or closed. Electrically, this part is rock-solid.

I’m not looking for GPIO output. I just want to be able to see and record the times the components are “on” and “off.”

I’m seeing some indications here in old posts that maybe OH isn’t that reliable at detected the change from on to off, or off to on (edge detection.) I see the same thing in other, similar home automation projects on the RPi.

However, there seem to be other RPi projects out there which monitor GPIO pins reliably.

So, my question is simple: Has anyone done this successfully in OH?

Just to be clear, I don’t really care about edge detection. If I could simply poll the state of the pins every 30 or 60 seconds, that would work, too.

Did you check this

1 Like

I specifically did not do this in openHAB because one almost never wants to host their “big” home automation server in the same location as the stuff you want to hook up to GPIO pins. So I wrote https://github.com/rkoshak/sensorReporter which does reliably detect the changes and report them over MQTT. From there OH or anything else can pick the message up and deal with it.

If all you want out of OH is the ability to monitor these GPIO pins, it’s probably way overkill. If you have other jobs for OH, you need to ask if hosting it on a computer where these relays are located is the ideal physical location to run your home automation. Things to take into consideration include WiFi and other wireless signal strength, access to power, environmental concerns, etc.

If this location is suitable to host your home automation, my understanding is the GPIO binding works well for detecting GPIO signals. Most of the problems I’ve seen reported about it have to do with pins going to HIGH during reboot and then falling back to LOW when OH starts up and stuff like that.

2 Likes

Like Rich I’ve also written a separate program that communicates over MQTT to control the GPIO pins among other things. If you are looking to add temp sensors it supports OneWire and I’m working on an I2C module that will support any I2C device just by adding a device module.

If you’re interested check it out on github https://github.com/CrazyIvan359/mqttany

Yes, thanks. I was looking for first-hand experience with it, doing something similar to what I’m doing (reading GPIO pins direct.y.) I’m also very new to OH and a lot of that is beyond my current experience level.

Fortunately (or maybe not) there’s a good, central location in my house where both the RPi can live, and the heating and cooling system controls are not far away.

I see in the linked information that you also poll the GPIO pins, not depend on edge detection. From my reading, I’m beginning to think that’s the only reliable solution. Does your script run on a separate hardware platform? I could do that, but it seems sort of redundant to have two RPi’s (or whatever) living side-by-side.

Same question as Rich; is this separate hardware? Do you poll the GPIO pins or detect changes?

I used to but the current code has been updated awhile back to detect the event instead of polling. See the rpiGPIOSensor.py script for details.

It does because my OH server is running on a VM upstairs in my office but one RPi is running sensorReporter in the garage and another is in the basement utility closet. But there is nothing preventing it from running on the same RPi as openHAB. It doesn’t require much of anything to run. When I was using it for BT presence detection (the reason I wrote it in the first place) I ran it on the same machine as my openHAB without problem.

1 Like

You can run it on the same hardware as openhab or separate, as long as the MQTT server is reachable.

Both polling and edge detection are supported and configurable. They can be used at the same time as well.

1 Like