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…
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” . 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.
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 . 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.
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 .
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.
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
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.