Using a knob (potentiometer) with the raspberry pi

Tags: #<Tag:0x00007f6182d6f278>

I am developing a small “button board”, which will be used to control some home appliances. So far, I just wired up some buttons to the GPIO pins of my raspberry and added them via the GPIO-binding. Here is a picture of the prototype:

So far this was really simple, but now my housemate asked for a volume knob. This is not possible via the binding, right? Right now my solution would be to get one of these:


and query them with some sort of script

I was wondering if there is any direct way to read the values to openhab. I am pretty sure somebody tried something like this before, but I haven’t found anything in the forum. Hint me in the right direction. Thanks!

I would use MQTT with node-red to transfer the data.

Well I’m fairly sure you’re right about not being able to use the encoder directly with openhab. A quick google search reveals the TinkerForge binding, but that would require additional hardware.

MQTTany might be an option, though I don’t have an encoder module yet. You could take a stab at writing one if you like, I’m sure there are libraries out there to handle the encoder. I could write one but I don’t have a lot of time wrote now so I couldn’t give you a timeframe. Using MQTT would also remove the requirement that the Pi also be your openhab server, allowing you to have more than one or faster hardware for the server.

Whatever you do, don’t use the built in broker Moquette, it is no longer maintained and barely works. You’ll want to use Mosquitto for a broker, it’s lightweight and fast.

I am currently working on a water meter reader for Raspberry written in Python 3. And it is possible to read the pins from a Raspberry pretty easy with Python.

So far I am only able to send an API post to an item and am still working on the link with MQTT.

I already have a perfectly working MQTT broker with Node-red to translate some silly commands from other devices. As soon as I have a script I will post it.

@Charley you might want to look into MQTTany as well. It already does GPIO and if your water meter needs special handling or multiple GPIO pins to interface, you could turn your existing code into a module for MQTTany and not have to worry about the MQTT side of things. If you’re interested feel free to PM with questions, we shouldn’t hijack this thread any further.

Thanks for the recommendations! For my specific (and simple) case, the node-red solution looks most promising and quickly implemented.
@CrazyIvan359, if I’d opt for MQTTany, can you recommend a module to base my encoder on?

@andrelung that depends on what’s out there for libraries that support this type of encoder.

I think you’d have to do board/pin validation, look to the GPIO module for that. I think each encoder should be setup like a device in the OneWire or I2C modules, that way more than one type can be supported by the module (if it’s needed, I’m not too familiar with encoders).

1 Like