Read AC 220V status with GPIO Raspberry PI2


I have wired the most important lights in a star shape, so all wires lead to a electric panel
There I have a hardware step-by-step relay that turns the lights on/off according to a push-button input (hardware push buttons on walls)

Now I want to controll the lights using my Raspberry PI2 and OpenHAB2
Right now I am working to set-up push-buttons in my sitemap to use GPIO pins to turn the lights on/off. It’s not working very well atm, I will post it later

However I have another problem that needs solving: as I also control the lights from the physical push-buttons on walls, I need to monitor and update the lights status in OpenHAB2.

To drive the input pin high I will use one of the solutions presented here:

Probably the AC relay is the simplest

Now I know I have to set up a GPIO pin as “contact” , but I have no ideea on what to do next
Do you know any examples reading GPIO status?

How about using the search function first ?
The GPIO binding should do what you’re looking for.

There’s also scripts like this
They’re meant to run on a non-openHAB Pi and report /allow for remote control via MQTT because not everybody has attached all of his lights to the central Pi running OH.

Thank you, I have been searching for the last 2 days, but probably I searched for wrong text.
I will look at the link and hopefully I can learn from it

Dear Dan,

The GPIO binding should suffice in terms of status and control. You could also use MQTT for the GPIO bindings if your OH server is not hosted on the Raspberry Pi that controls the inputs/outputs, as Markus already suggested.
Be careful though with the outputs (relays) - depending on the type of load (resistive, inductive, or capacitive) and power, the relays should be chosen accordingly.

Best regards,


OH is on the raspberry pi. Is there any reason why I should host it elsewhere?
I plan to use relays for Arduino, they have optocouplers and they draw very low mA - I guess that’s the primary concern, right?

Nothing wrong with that. It just means that you need to have cables going from everywhere to your Pi.
If you deploy Arduinos anyway, you could have them speak MQTT, then you just need a single cable (or WiFi) towards the Pi to transmit MQTT over IP. Same as to deploy another ‘slave’ Pi to run a script.

I got involved when I installed the electrical wires, so the most important ones are routed in a central panel where I can control them.
I struggled with arduino webserver, it’s very limited because of the low memory. I managed to do this with arduino:
I published the code for this, so it’s available

the data is parsed by cacti runnin on a linux box and producing these graphs:

I was planning on implementing buttons on arduino, but seems so much nicer on OpenHab, so I decided to switch to raspberry pi + openhab.
I haven’t red about MQTT yet, I probably will if need to communicate with other boards like arduino

I use arduino for all I/O (generally nano) and a radio network to move data back to a raspberry pi (via ethernet arduino gateway). The pi runs OH. The radio are very cheap (less than cost of nano) and this gives a very versatile system and low cost system. It also limits the risk of I/O issues, e.g. noise pickup, earth loops etc crashing the system.

My system is based around



1 Like

what do you mean by radio? IP wifi?

I could do this too, as the IO will be connected to 220V. This way I don’t risk loosing the RPI

can you give me more details? What radio board for arduino, what board for raspberry pi?

The radio’s are RFM69HW - see []


wow, there’s a lot of reading on the instructables link. but that’s good
the radio parts arrived and I’ll continue my work, I’ve decided to do as you did, a arduino gateway

Also see