Lamp Mechanical Switch

I would like to Sonoff some lamps but am not keen on losing the use of the physical buttons. I realise I can use the header pins on the board to toggle the relay, but I am wondering how easy it would be to wire this up?

My lamps have switches in various guises, some are inline on the cord, some are on the head of the lamp itself either as a pull cord or a push switch.

I guess I would need to run a cable back from the switch to the sonoff, which I have connected inline on the cord to make it work?

Are there any links to this being done, any and any suggestions on how to keep it looking OK aesthetically? Or anyone got any better ideas? I love the idea of automation but I don’t want to compromise functionality/simplicity to do it.

Depends where you put the sonoff. Inside the lamp base would be the tidiest imho.

Yep, good idea. Might be possible but probably not while keeping them in the case.

What are the thoughts on installing them bare?

Another option would be to use a Shelly 1. It operates similar to a Sonoff, but has a built in switch input which also controls the relay. It sits inside the light switches electrical box.
As such, you can control the load (the lamp in this case) with either MQTT commands, or via the physical switch. In this case, the switch can remain exactly the same and does not need to be replaced.
If you want energy monitoring, there is also a Shelly 2 (more costly) with an energy monitoring chip built-in.

Sonoff also offers a Touch switch that has a built in relay and thus can do local or remote commands to turn it on/off. I have a few of these, but do not particularly like capacitive touch buttons, as they are hard to find in the dark sometimes, but the benefit is they make 1, 2, and 3, switch/relay versions that really save space.

A third option would be to buy a “generic” wifi wall switch, and reflash it with tasmota. I’ve personally bought this model and reflashed them and they work great.

The main drawback of these other options is cost. The shelly 1 is $12, the Sonoff Touch is $15, and the generic wifi switch is $14. None of these are very costly, but still many times more than a basic sonoff.

There’s also Z-Wave switches with relays built in, but those are much more, at around $30 each, not including the Z-Wave usb stick or hub needed to talk to them.

With a Shelly you still need to run wires from the lamp switch to the Shelly along with the two power leads for the light.

Your probably best decoupling the switch and running that to gpio on sonoff but will require soldering. If you use Shelly you need to run mains voltage wires for switching where as the sonoff uses 3.3V wires.

For me the Shelly way seems perfect as long as it can be placed in the switchbox

you cant install anything inside the light base.
when you use the wall switch to turn things off there is no power anymore for the light, so it cant be turned on with automation anymore.

the only real options are
a) forget the wallswitch (leave it there but only use it when automations dont work)
b) replace the wallswitch by any kind of wallswitch that can talk to HA.

Lamps don’t use wall switches usually.

“My lamps have switches in various guises, some are inline on the cord, some are on the head of the lamp itself either as a pull cord or a push switch.”

sorry thats my poor understanding from english then :wink:
still my point remains.

if you put something inside the lightbase it will probably not be replacing the switch.
and the only way to get manual AND home assistant switching possible is by replacing the switch.

You can wire the lamp switch to the switching input of the Shelly or gpio of the sonoff so the lamp’s switch no longer controls the mains voltage it controls the smart device.

No one mentioned a wall switch.

Its interesting. I have a 330 sqm house with loads of lamps and 100% of them use wall swoitches. That is what I based my answer on. Sorry for the misunderstanding

but then you need a new power cable.
with a switch on the lamp base that can be done very well, but with a switch that is inline on the cord that means bypassing the switch and putting 2 more lines besides it after the switch.
not a real nice option.

Yes, the Sonoff Basic can have a switch wired to GPIO14 and ground. I have a few in my home wired this way- you can control the switch over Home Assistant, NodeRed and MQTT, or with the switch on GPIO14. But this would require a rewiring of the existing switch so that it is not connected to the line and run a pair of wires from the switch to the Sonoff. The wires from the switch can be really small because they would be carrying very little current.

I have taken a Sonoff basic, placed it inside a small project box and just wired up a push button to GPIO 14 it works great and you can even make it waterproof for outdoor use. I just plug them inline to my lamps and if I need to toggle the light manually I just press the button.


Here’s an example by SuperhouseTV

Skip to 18:36 or watch the whole video if you want its got some useful info.

Thanks for the replies. I have added a Sonoff to two types of lamps and they are working well, still keen to get the mechanical switches working.

Of the two, one is on an inline foot push button, the cable currently is 2 core, so I am thinking of getting some 4 core cable to replace the current cable from the switch back to the sonoff, then wiring 2 cores to the foot switch, the other 2 to send power straight through.

The other I have is a lamp with a lamp socket switch. The problem I have on this one is that the mechanical switch is on the bulb holder and I don’t see how I can make the switch independent from powering the light. Pictures attached but I think I might need to replace the socket here.


Pushing the swtich from left to right aligns the lamp contacts to the power contacts below:

Power contacts with switch removed:

I would be to lazy and will end up with new lamps

i just put a remote controlled switch before it or i replace the lightbulb for 1 that i can control. :wink:
the switch would be on a dashboard.

but still its always nice to see what others decide and do.

I dont want to do my wife a murderer. That would happen if not every switch work as normal. No delays and always work even when ha is down