ESP8266 / Sonoff Controlled Ceiling Lights

The internet to the rescue:

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

1 Like

Interesting project. this is something i am in the process of doing and decided to try the sonoff devices. they seem to work ok so far, if you are happy to reprogram them. here is an excellent video on how to control the light by wireless and by the light switch with a couple of hacks into the sonoff. Might be worth a look.

Superhouse sonoff hack

1 Like

There are of course these (UK specific variation), tooā€¦https://www.itead.cc/smart-home/sonoff-t1.html

For the super lazy :slight_smile: person who does not mind changing the cosmetics of the switches in their home.
Shame they dont do dimming, too!

I love that Itead is a company that sees hacking as an opportunity not a threat.

I ordered a couple of these switches. Works great with tasmota+hass, but I really would love to see a non-touch version of this.

Ooops, hadnā€™t watched that yet. Iā€™m definately giving the Sonoff a go then.

Presumably these switches require power at the switch. For those of us with the 3 plate in the ceiling theyā€™re probably not an easy option.

Dimming lights is a whole different kettle of fish, particularly with the new LED lights.

This PDF describes the problem, and a solution: http://large.stanford.edu/courses/2012/ph240/johnson2/docs/CD00003922.pdf

TL;DR: You canā€™t just use a Triac, and LEDs need to be dimmed differently to downlights.

You can however buy conventional dimmers that are smart(ish).
For about Ā£10 I have bought and use a number of these v-pro varilight dimmers: https://www.varilight.co.uk/dimmers/v-pro.php

They support all types of loads: incandescent, LED and florescent. Also you can change whether leading or falling edge, and trim the min dim for leds that only dim down to a certain level before extinguishing.

All they need now is an esp2866 :slight_smile:

My Sonoff finally arrived and Iā€™ve had a play tonight. Happy to confirm that with a few small tweaks my code does indeed run on a Sonoff and you can still use the wall switch and the special / double click functions :smile:.

Good call @hijinx. This is a neater hardware solution :+1:.

If anyoneā€™s interested let me know and I will post the updated code on Github.

5 Likes

Iā€™m currently building a ESP8266 enabled mouse trap. Not because itā€™s some great need or because itā€™s a cheap solution, but because Iā€™m learning so much, challenging myself, and learning fun stuff along the way. IMO itā€™s a great way to learn how to build custom solutions to your own specific HA setup that end up making you (and it) much better off.

1 Like

Iā€™d be interested to see your code, please.
Also, as a fellow UK resident, Iā€™d be interested to see your wiring diagram with the sonoff and wall switch.
Iā€™ll be honest that my knowledge of UK lighting ring topologies is not particularly goodā€¦ although a cursory inspection revealed the presence of brown and blue wires behind some of my switches, so my working assumption is that I have both live and neutral.
Caution suggests I dont necessarily rely on wire sleeve colours though :slight_smile:

No problems, Iā€™ll try and publish my code and some pointers on wiring over the weekend :smiley:.

New repo added for use on a Sonoff device. The README.md in the repo explains how to use it and includes a wiring diagram.

Hopefully this is useful to someone :slight_smile:.

1 Like

Thanks for sharing.
I have a couple of Sonoff basics on their way.
I think I have L and N connections at (at least some of) my light switches.
Iā€™m going to try to incorporate a pot or rotary encoder to act as switch and also to allow soft on/off and dimming via mqtt of smart bulbs.

Iā€™ve spent some time on my SwitchedSonoff repository and now you can configure all of the WiFi, MQTT and Other settings over WiFi and you no longer need to make any changes to the code. This should make it easier for those who donā€™t want to get into Arduino / C++. :smiley:

1 Like

I really love all this info. Iā€™ve been very keen to find a way to make my kitchen light accessible both manually via the wall switch and also via HA automations.

However, has anyone had any experience or luck with the idea of having a wifi bulb and doing something similar. In the sense that it could be triggered off by a wall switch and controlled in HA as well. I would assume the wall switch would be completely detached from the wiring for the actual light socket and simply be a trigger to tell HA to turn it off and on.

That way scenes and dimming of the light could be used as well as turning it off and on.

Of course the desire to do this is based on the better half stating there is no way the kitchen light can only be turned on via an app or even controlled by a motion sensor.

I created a soft switch that looks like a normal uk 1gang dimmer. Rather than dimming directly it sends mqtt messages to HA, which then in turn controls smart bulbs etc

There are many other such projectsā€¦

But doesnā€™t the MQTT message either say to HA for the light to be on or off? With a smart wifi bulb you donā€™t want to turn the power off, you want it to control itā€™s on and off state at the bulb. My current LIFX bulb in the loungeroom requires that the wall switch be left constantly on and the bulb itself does all the work.

Iā€™m just thinking about a way to have a physical wall switch not wired to the bulb in any way that is almost like a mini version of the HA UI for just that one light. Perhaps a touchscreen is the way to go.

I donā€™t know for sure but I can imagine hijinxā€™s project has a HA automation listening out for the correct MQTT message. This in theory could trigger any action including the toggling of a wifi bulb.

I actually have a similar use case that I will be working on shortly. Hereā€™s my current setup:

I have 2 lights in my bathroom, the ceiling lights and the lights in the mirror. Both are connected separately to HA using MQTT. The light switch is plugged into the micro-controller looking after the main lights and turns them on and offā€¦then an HA automation triggered by the main light turning on and off turns the mirror lights on and off in sync.

There is also a motion sensor that will turn on the mirror lights if anyone walks in the bathroom at night (kind of a night light). The trouble is, when the night light is on and the main lights are off I would like to be able to turn the night light out by switching the switch (instead of waiting for the motion sensor to time out). At the moment this will turn the main lights on.

What I plan to do is, in the case of the main bathroom lights, instead of the switch controlling the light and then updating HA, I want it to tell HA that the switch has been switched and then HA can make a decision on what to do. In my case, if either of the lights are on, turn them all off, if both are off, turn them all on.

This could be used in your use case to toggle the wifi bulb instead.

Iā€™m sure there are plenty of projects out there that do this already, hijinxā€™s project for example does a great job if you need dimming functionality. If you just need a on / off switch and canā€™t find anything else then Iā€™ll let you know when Iā€™ve updated my repo.

I hope this helps.

1 Like

So many great project to be inspired by and fork :smiley:

Youā€™re quite correct. The on/off/brightness is sent from the switch via mqtt, picked up by ha and then drives automation to tell a philips hue bulb to turn on/off or set brightness.

If you only want on/off then you could use the same setup but with a conventional light switch wired to the esp8266 rather than the rotary encoder + small change to espeasy config (rocker switch instead of the momentary in the rotary encoder).

If youā€™re using smart bulbs though I guess they can be brightness controlled so why not consider dimming too?

1 Like

This is a crude sequence diagram of how it works:

1 Like