Sensing AC switches and buttons states

Hello everyone !
I'm in the process of building my home automation system: I have a relay shield and I'm going to control it via the GPIOs of the same Raspberry pi that runs Node Red (I'll eventually have to use some multiplexers since I want every light in my house to be controllable)
So far so good.
But I still want to be able to control the lights with the wall switch (pushbuttons, precisely) and, moreover, I'd like to let my dashboard "know" the state of a light, whether it was manually operated or via MQTT
So I ultimately need my wall switches to send an MQTT message, somehow.

My question, sounded a lot simpler in my head in my native language, so I've probably been verbose and convoluted :slight_smile:

But basically:
Kitchen light, controlled by wall pushbutton, wired in parallel to my relay shield, subscribed to home/kitchen/light_1
Wife walks in, turns light on via the wall switch, and walks away.
I check on the dashboard, and I can see that the manually operated light is ON.

I'm not retrofitting an existing electrical system, house is still being built, so I can ask the electrician to install whatever I need, but would hate being charged some fancy domotics, when i'm 99% there :wink:

I have a plethora of arduinos and ESP8266, that I can use to publish on MQTT, I just don't know how to sense efficiently (from a cost and size perspective) 30+ lightswitches.
Since I asked for all pushbuttons in my electrical system, there may be a relay box for them already (am I right ?) where i can put my electronics, both for controlling and sensing.
I thought about AC Current sensing sensor, but I'm not sure the 5Amps they are rated, would be enough, but above all I can't see any shields containing more of them as for relay shields, and hooking up 30+ would be horrific.

So, I'm open to cunning dirty cheap, mind-stimulating solutions :slight_smile:
Thank you all for reading all this!


Big project and interesting.

However, I certainly wouldn't use a Pi to control everything since if that has an issue, you can't do anything at all. One dead house? Not very wife friendly!

At the very least, I would think about distributing controls such that relays can be controlled locally and independently if the main controller goes down.

If you need to keep costs down, I would probably use a combination of ESP8266 with relay boards and local switches. If you need to be less dependent on WiFi, I would probably look at some Zigbee base solutions. Possibly a Zigbee controller driven by Node-RED - but again with local Zigbee switches and possibly keep a spare controller with easy instructions to swap it out (in case you are not around).

The advantage of Zigbee is that it is 2-way, it creates a mesh which makes installation simpler and costs are falling. There is at least 1 open-hardware Zigbee controller and plenty of options for commercial switches and lights, etc.


Have a look at superhouse tv

John has done this a number of different ways and gives the pros and cons of both - he also sells the small board that create the magic if you choose to go that way


and here is the write up about the latest version

Certainly an interesting approach though expensive if you need >12 switches since that seems to need another controller. You also have the issue of wiring RJ45 connections through the house which probably needs shielded cabling and I guess will have length limitations (not an expert so I'm just guessing there).

Actually, that is REALLY expensive no matter which way you look at it. The 1U case alone is over AUS$60. The RJ45 connectors a further 3xAUS$15. Plus all the other stuff.

Still, I suppose that if you are building your own house from scratch, the cost may be bearable.

Hi everyone!
thanks for the feeback. I also gave it some more thoutght.
first of all, a clarification: the pi would be parallel to the manual control of all the switches, you know, just like a plain old regular home electrical system.
All lights are controlled via pushbuttons, and not switches, so all contacts already go into a relay box.
My latest idea, is to use DPDT relays, so when I push the button of a light, relay coil momentary closes two separate switches: one with 220 power, and the other one, isolated, runs my 5v signal into the raspberry pi (via a multiplexer, given the expected number of contacts).
What do you think ?

Not really that expensive

  1. The case he specified is generic - instead of a 1RU unit you could use a 3 RU unit (for example) and fit many more connections in there
  2. Each RJ45 connector can connect to 4 light switches in a single enclosure
  3. If i was wiring a brand new house i would be pulling at least a single CAT6 (as a minimum) to every light switch, power outlet and light fitting
  4. No the Arduino Mega shield will control upto 40 switches from a single Mega

As a nice tidy contaned solution i think it is brilliant - particularly with the options for different arduino sketches that others have added to - such as single, double, triple press and hold down etc - you can get many different effects from a single switch, and all outputting MQTT - his other company also sells a product called an Arduino Ethermega - very expensive ($120) but it is a Mega with Inbuilt Ethernet and SD Card - brilliant to then pump out MQTT over ethernet to your central controller


1 Like

I think that we have different definitions of what "expensive" is for home automation projects :slight_smile: but of course, that is absolutely fine and what makes these discussions interesting.

I still have a slight concern over resilience, the unit as designed will control 12 switches so if it dies, what would be the impact? I'm afraid I haven't had the time to go through the video so I'm not sure whether he covers that at all.

By contrast - and bear in mind that I've not tried any of these solutions myself so I'm kind of guessing here.

The cheapest Zigbee switches I could see on Amazon UK (after extensive searching ... for 2 minutes :blush:) come in at about £10 (AUD$18) each switch.

With a controller for about £30 (AUD$55). Unsurprisingly a fair bit cheaper on AliExpress.

So around AUD$270 for 12 switches and controller) - not clear whether they would still control the light if the controller is down which is the key point I guess. Does anyone have this kind of setup who can inform us?

Some spare switches and a spare controller would likely take care of resilience enough for most people. There are also open hardware Zigbee controllers available which would connect direct to a Pi.

I should also say that I am genuinely interested in the outcome of the discussion. While unfortunatley, my 1900's house in the North of England is totally unsuitable for flood wiring, WiFi works OK and I have some SONOFF's and ESP devices around but most of my switches are from an earlier era and are HomeEasyEU or LightwaveRF neither of which have any feedback and are slowly dying anyway so I need to replace them with something better over the next few years. So for me, wireless is the only practical solution. The question is, which will be better: WiFi or Zigbee?

1 Like

Sounds like an easy way to drive up the costs; I recently saw the prices of CAT7 cable, plus fitting RJ45 connectors. The good part is that there’s two of those cables downstairs now, four of those connectors in total.

But yes firm agree CAT6 or CAT6e is usually fine. Here it helped having a network engineering electrician in the family with a 100 metres CAT7 cable reel lying around :slight_smile:

It's strayed a little off-topic from the original post, but I'd have to agree that the "Superhouse" system looks like an expensive approach, and possibly not one which will "fail gracefully".

Given the ready availability of wireless solutions, whether off-the-shelf or home-brew, it seems this would be a more cost-effective way to go - and it's what I'm working towards. There's no extra wiring, which is a fair amount of extra work even in new builds, and the controller can easily be moved or replaced whenever needed.

I think the simplicity and flexibility of wireless solutions makes them a big win over the wired option.


Why not just get your new house wired as normal, but replace the lights switches with flashed with Just make sure the electrician runs a neutral wire to each switch position and I would specify deep back boxes as the sonoff switches can be tight in a normal back box but all that is minimal extra cost when if your house is still under construction.

The wall switches will still work normally even if your WiFi fails, your node-red control will work in parallel so you can turn a light on / off via the switch or via node-red ui all via mqtt, and if a switch is operated manually it does send notification via mqtt, you will not be adding complexity to the installation ie no relays or mixing voltages in the switch boxes or mains panel so no fire / insurance issues, no Cats involved, most importantly the electrical installation can be tested and certificated as a normal house with out problems and if you move house later you can just remove all the sonoff switch plates and replace with ordinary light switches so no issues with a prospective buyer it will be just the same electrical installation as any other house.

You can also add or if you want to hide the socket control maybe mounted behind the socket also flashed with tasmota.

Then just develop node-red flows with ui buttons, timers, pirs, alexa etc to control everything via mqtt I even have miLight bulbs in some lamps for dimming all controlled via nr / mqtt.

1 Like

That is certainly a cost effective and flexible approach, it also satisfies the maintainability requirement since all of the hardware is accessible and easily swapped out. Just keep a couple of spares pre-flashed so that an ordinary electrician can swap one out in case you are not available at the time.

Of course, you also need to make sure that your WiFi coverage is good so allow for >1 Access Point. The Ubiquiti UniFi range are great and will mesh together very easily. If you are adding some wiring to the house, try to ensure that you at least have some spread out to further reaches so that you can wire in a 2nd AP, meshing over WiFi itself works just fine but is much faster if done over wire.

You could also consider Sonoff Mini's instead, keeping your existing switches, they keep working and automate them via wifi.
I have a couple here and unfortunately in my house, the light switches only contain a L(ive) and S(witch) wire, so cannot connect them, but in other countries it might work. They are a little harder to flash with tasmota but it is doable.

While searching, sonoff have a switch without neutral, pretty clever actually.

@dynamicdave was faster :wink:

I've just ordered two of these SonOff WiFi wall touch switches (from Ali Express) that don't need a NEUTRAL wire.
Just wire it in in place of the original rocker switch.

1 Like

They are quite hard to flash with tasmota/or something else, I need to give these some thoughts...

I don't like the sound of the anti-flicker module that comes with the Sonoff wall switches...

The main advantage of fitting fluorescent or LED bulbs is increased efficiency, but adding the anti-flicker module across the load effectively bypasses 300mA around the load, which is wasted energy.

Current x Voltage = Power
0.3 x 240 = 72 Watts wasted

Surely that can't be???

1 Like

Thanks guys,
Your suggestions tho, all seam to to focus in rendering the wall switch itself somehow smart, making it my fault with my wife :slight_smile:
the idea, is that I will probably have a relay box, where all my traditional momentary switches converge, and where I'll put in parallel to them, my fat (couple of) 16Channels relay shield
directly connected (via multiplexers) to the GPIOs of my raspberry pi running node red.
so I'll just have to deal with one device connection, I really like having one network enabled device, whether it be wired or wireless, rather than having a wifi enabled device for every light i want to control in the house. Also, I think that on the scale of this project, being 16 or 32 contacts, a couple of these shields easily beat the price of the same amount of sonoffs, of course given the advantage of having them already in the same "box"
that said, I will end up using sonoffs for everything that will be slightly off that control box, or even not tied to the wall switches at all, so that design choice not to use them only applies to that particular scenario.

So the pushbuttons all go into the box where the relays "A" when excited, turn the respective light on.
In parallel to them, my relays "B" controlled by raspberry pi via gpio also do the same job, but via some relaxing node red mandalas.
IF there is a way of having this setup untuched but "adding" one more isolated pole to the "A" relays, I can use that "redundant" channel to send a HIGH to raspberry pi GPIs , and issue an mqtt command for the physical switch hit.
pretty much I'm wondering if I can achieve this, just swapping the "A" relays, from the standard used in home systems where there's all pushbuttons, with the same type of relay, but with another isolated channel that will close simultaneously.
Will gladly accept feedback on the system I presented, and if anyone understood the relay I tried to describe, please suggest me the part.

One thing, you can make life a lot easier by making sure that you have full power to the switch boxes rather than just the single split wire that is common and mentioned in the referenced video. That way, you don't have to faff with special units, anti-flicker, etc. Also make sure to fit deep wall boxes throughout so that you have room to fit things.

Unfortunately due to our regulations in Australia - Zigbee is horrendously expensive - last i looked a singel Fibaro Zigbee switch as $100 AUD

His controller is just a Arduino Ethermega - so easy and cheap to have them as spares

In Australia we have extremely tight regulations on DIY solutions and anything that comes into the coutnry has to go through a rigorous process to become certified - this coupled with our relatively small population means that all of the solutions that we get here (such as Zigbee are usually twice as expensive as overseas and many of the modules are not even made available as they have not been certified)


1 Like

I might be accused of dragging this conversation off on a tangent...

One thing you might want to consider is having some SMART lights and controlling them via Alexa and/or Node-RED, so the wall-switch becomes redundant.

I've got five of these lights in my lounge and can control them all using verbal commands via Alexa.
I've also written some NR flows that incorporate the Yeelight node so I can sense the status of the lights and control them with sliders and/or buttons on NR dashboard.

Just my two-penny worth.