ESP8266 / Sonoff Controlled Ceiling Lights

In my ESP8266/MQTT projects, the if (!client.connected()) { reconnect(); } in the loop works just fine and I have no disconnection issues whatsoever. It’s several months that I’m running my units with no problems.

On the other hand, while I’d very much like to build similar, dual-activated units (mqtt + local switch), I can’t think of a way to fit the esp board and relay and the switch in the limited space in the hole-in-the-wall (don’t know the name for that, would it be called a junction box?)

I echo lexam79’s question - where do you put the esp8266? And, how are you powering it? Your circuit diagram doesn’t show the VCC connection for the esp8266.

@marthocoo +1 for power supply !! I already tried to install Fibaro relay or dimmer that goes behind existing wall switches (it’s more than tricky to fit everything in the box and all the more be able to close it back without any wires going away…

Why not a Sonoff or Broadlink for 5-8 dollars?

Good solution for UK where we don’t have neutral!

How are you powering the Wemos?

By the way, I like the “smart debounce”, might have to steal that for my doorbell that I’ve had to disconnect because for false triggers :slight_smile:

1 Like

Fun and sense of achievement :slight_smile:

1 Like

Hopefully I can answer some of your questions:

First of all it’s worth saying that I have the massive benefit of my partner being an electrician. Basically I built the micro controller part and said “fit this please” :smile:. I’ll try and do my best to explain what she has explained to me in terms of the wiring side of things.

Fitting it all in…

When I first tried to come up with a solution to this my aim was to fit it all behind the light switches. Space was indeed an issue but before I even tried to tackle that I found out that the lights in our house are “3 plated in the ceiling”. This means that essentially only the live part of the AC circuit gets to the switch, there’s no neutral. The result of this is that as well as the space issue I couldn’t easily get AC power to the micro controller behind the switch either.

The plus side of this however is that I can put all of the controller stuff in the ceiling / loft (attic) space. This is put in at the point the live cable gets run down to the switch.

  • This is how our lights were wired even before we made any changes.
  • The round circle is a joint box in the ceiling / loft (attic).
  • The dashed green line is where we essentially cut the wires and sat the controller in-between. Also in the ceiling / loft (attic).

Getting power to the micro controller…

Oh I forgot about this bit! For this we “simply” wired an new plug socket in the loft / ceiling (attic). I say simply, it was simple for me as my partner did it but maybe not so simple for others. I could have used an AC to 5v DC converter but we already had the bits to just put a plug in.

Why not a Sonoff or Broadlink for 5-8 dollars?

This was about the same cost and the custom software gave me extra flexibility such as allowing the switch to be used as normal (I don’t think Sonoff type devices can do this but I might be wrong) and the double click functionality is great to duel purpose light switches.

Note: I know you can probably flash your own software onto Sonoff devices but as I say, this was just as cheap.

3 Likes

Really like this, i to am an uk electrian and have been looking in to similar projects was going to replace sx’s with retractable sx’s for signal inputs. Hadn’t thought about the ability of still being able to control lights when the wifi goes down :slight_smile: . Dont surpose you have found a solution for being able to dim lights (intill someone make a smart g9 lamp) need to find enougher solution. Only idea i’ve had is esp controling latching relay wired as 2way sx to standed wall dimmer. Not perfect by any means.

I did have a look at this but didn’t get far unfortunately. From what I found it adds a whole load of complication and so I left it :smile:.

Do they have Sonoff/Broadlink switches for that cheap that let you use the switch like normal? I would be interested!

@Dullage very interesting, wish I had thought about this before I finished boarding my attic.

You mention adding a new socket to power the ESP8266, was this added to your light ring or on the socket ring/spur.

If the socket is purely used for the ESP8266 the I would presume it would be fine on a light ring, but I’m no electrician which is probably obvious.

Yes, with custom firmware:

2 Likes

In the loft we used the socket ring as it was convenient but in the ceiling we used the light ring. It’s very low current so should be no problem and hey, it’s our house :smile:.

Be safe.

I might give a Sonoff a go for the next one. It’s probably only slightly cheaper but it does has the benefit of having it’s own case. Good shout hijinx.

This said, I would think in cases where you can plug more than one relay into a single micro controller then it’s probably cheaper to buy the separate bits.

1 Like

Completely agree re the flexability of a custom solution - I didn’t want to take away from your nice project in any way!
Buying a sonoff is a kind of short cut for people who lack either the knowledge or time or both to build from scratch.
Building out a microcontroller project is super fun, but its an investment in time and tools etc.
A sonoff allows you to get straight into the software aspect (assuming you want to flash a custom f/w) with only a minor bit of modification (hooking up serial link).
Also that built in PSU is a winner :slight_smile:

2 Likes

Oh I hadn’t considered that it has it’s own PSU, that is a massive bonus and does bring the cost down even more!

I’m going to order one and give it a go.

Sonoff also do multichannel 2 and 4 channels.

Here is their PCB:

BTW I dont have one yet… I haven’t had the time available to dedicate to play it with it.
Now very tempted though :slight_smile:

1 Like

Oh wait, I forgot, in order to continue using the wall switch as a switch my software needs to monitor it on a GPIO pin. :disappointed:

Do you happen to know if the Sonoff exposes any of the ESPs other GPIOs for custom use?

Thats what it mentioned in the youtube I linked:

it is possible to connect a physical switch between GPIO14 and GND on the Sonoff board. This allows the device to connect to UK lightswitches that do not have a neutral connection.

The internet to the rescue:

GPIO0 = push switch
GPIO12 = relay
GPIO13 = LED
GIOP14 = available :smiley:

1 Like