Integrating physical buttons on RPi

Thanks so much for al, the assistance so far.

Hopefully getting to the last part of the project, which is connection in physical buttons to control three elements on a hot tub. Using the virtual buttons, I have control of three relays, Pump, Light and Heater, and these work when activated from the dashboard menu. The final system should have a dedicated physical button for each relay, but at the moment just testing with a single button for ease.

I have connected a physical button to GPIO 17 (Pin 11), and used the magic script to set this to toggle in the same way as the virtual buttons, but nothing happens. Using the GPIO read pin 11 command, I can see that the value is changing, which implies that the wiring is correct,but still not getting any control of the relay.

I also tried using magic to get the physical button to “press” the virtual button, but still don’t get any control of the relay.

The physical button is set up as a switch using the GPIO things option and is a normally open style switch.

Thanks in advance!

can you give some more input on what thing classes you’re using (see configure things → … → Thing Class → Type) and the script you’re currently trying with?


This is what I have configured using the “add things dialogue”

The Pump, Light and Heater things are relays fed by GPIO pins going into a Waveshare 8 channel relay board.

The things that end in “indicator” eg Heater Indicator are led’s that will be driven from GPIO outputs to show the state of the device eg when the pump in on, the Pump Indicator will light up to show it is active

The magic scripts for all three that are currently working from virtual buttons are:

This works fine.

For the physical button, I have copied the virtual button script as shown below, but to no avail…

The idea is to have a physical button panel on the side of the hot tub with the basic control and then any advanced controls such as setting the temperature can be done via the nymea app.

Let me know if you need any more info, or if there is a better way to share the info you need!

When you open the pump test Button in the things view. Do you see the button being pressed there in the log?

I’ve tried to look in the log, but it always seems to be empty. Is there a guide on which log and how to enable logging of things like i/o presses?

Just added the Pump Test button to the dashboard as a thing, and it’s constantly registering as a long button press (see below)

I’ve tried toggling the “active low” to setting and get the same response.

I have just disconnected the button to check of this made a difference, and haven’t had a long press registered until I’ve plugged the button back into the holder.

Found the log for the button.

Have set the test button to “active low = true”, and now see this being logged on the thing view.

Strangely it doesn’t seem to be logging any short presses, only long ones, no matter how quickly I press the button. I’ve tried dropping down the “long press time out” value, but still get the same issue.

Hmm. Interesting… Will need to check the code why its not picking up the short presses. Sounds like a bug maybe. Will do asap, on a holiday today. In the meantime you may change the magic rule to use longpress instead.

Thanks Michael. So from an evening of pressing buttons and changing configs, I now have the button pressing reading correctly when I view the log through the “Things” screen.

Not sure if it’s the way it’s logged, but each short push is registered three times on the logs.

I have tried switching the magic script to long press to get around this and now have the output relay “bouncing” and not latching.

When I press the button, the output relay is closing and opening repeatedly while the button is held down, and not latching.

As another update, I tried to see if changing the GPIO type from switch type input would change anything. I deleted and re-added the GPIO pin, but not as a “switch” type thing, just an GPIO input. I then replicated the same magic script as the virtual switches and while the relay doesn’t latch, it also doesn’t bounce like it did when using the “switch” thing type.

Not sure if this points to anything in particular, but I thought I would add to my experience so far…

I noticed the latest update include a new module for the Raspberry Pi I/O. Did this update include any changes to help with the short push issues?

Hi all

Is it possible to get some help with this, as I’m still stuck!

Hi, I’ve just tried this. I’ve set up a GPIO Button thing on GPIO 4 (pin 7), and activated the active low switch during setup. Then it seems to work fine if I pull the GPIO to GND with a button.

Also works if leave the active low disabled, in which case the pin should be kept on GND while the button is not pressed and moved to 3.3V when it is pressed.