Close
0%
0%

Smart switch for hubless smart bulbs

A switch to turn on, off, and dim hubless smart bulbs

Similar projects worth following
I bought some cheap smart bulbs from Magiclight to try out before jumping fully into home automation. They're incredibly inexpensive, but pretty good for the price. They do have some shortcomings though.

After a month or so of facing issues with the wall switch not being useful, I decided to make one that can dim my lights and turn them off without cutting power completely. Most cheap hubless wifi bulbs use the same firmware. I found a python library that allows communication with these bulbs. A Pi zero w is small enough to fit in the switch wall box with room to spare, and is a surprisingly inexpensive way to turn button presses into code. Coupled with some momentary switches and 3D printed parts, it should end up looking just as good as any other switch.

Please do not try this unless you are comfortable with both home wiring and soldering. You will need both hot and neutral wires to power the pi. Please only wire it in parallel with other loads. If you are confused, don't try it my way. You can get the same result by plugging it into a nearby power outlet and running the cable in through the faceplate. I'll make a print file with a hole just for that purpose.  It won't look as nice but you won't burn your house down because you missed up the wiring. 

I originally made some simple tasks in IFTTT to turn my lights on full, dim, and off when webhooks are triggered. Since I have two bulbs in my master bedroom, I had to make six tasks: 3 for each bulb. Even though I made six tasks, the same actions on both bulbs were triggered with the same webhook command. This made the python script simpler for my pi.

My beadboard prototype worked perfectly with IFTTT so I soldered up a through hole prototype board to take up less space. The lights changed one at a time and there was a bit of a delay, but it does what I wanted. 

Meanwhile, I designed and 3D printed a custom faceplate that will hold three large button faces on the front, with holders for the prototype board, pi, and a power supply inside. From the front, it looks almost like something you'd find in a hardware store, but on the back there will be magic. 

After finishing the prototype build with proper wiring and printed parts, I discovered a portion library to directly control my bulbs. Huzzah! No more IFTTT! After rewriting my python code, the lights responded instantly to button presses! 

I'm already planning the next revision with a button switch to actually kill power to the bulbs in case something goes wrong with the wifi.

JPEG Image - 3.21 MB - 03/09/2019 at 22:58

Preview
Download

JPEG Image - 3.55 MB - 03/09/2019 at 22:58

Preview
Download

  • 3 × Momentary pushbutton switch
  • 1 × 110VAC to 5VDC power supply/converter
  • 1 × Through-hole prototype board
  • 1 × Wire Resistors (Fixed) / Zero Ohm Jumpers
  • 1 × 3D printed parts

View all 6 components

  • A tale of two IP addresses

    Sean04/12/2019 at 17:59 0 comments

    It was the best of scripts, it was the worst of scripts. Ok, mostly it was the worst. I don't actually know python so that doesn't help. 

    I built some fancy error handling into my script so that if it doesn't find the bulbs right away it keeps trying until it connects before starting the main loop that waits for button presses. I also added some code to reconnect if it can't find the bulbs when trying to send them commands. Yay! No more breaks in the script. 

    Except it never connected. It just kept trying and trying and trying. I finally looked up the IP addresses for my bulbs. Imagine my surprise when they were different than they used to be!  That's when I remembered that the utility company recently cut power for a few hours to do repairs. When my router came back online, it reassigned IP addresses. 

    Now I know I could easily work around this by setting fixed addresses for my bulbs, but that isn't user friendly to other people who want to use my project. I guess I'll have to double down and figure out how to find bulbs by MAC address instead. 

    Bleh.

    I'll let you know if it ever works. Meanwhile my new code is awesome. I'm still afraid of my power supply thing that I bought for $3 and I might never actually test it for fear of burning my house down. 

  • Error handling!

    Sean04/11/2019 at 01:47 0 comments

    Hey guys. So I've been thinking about my python code lately and I've realized that it really sucks. I understand now exactly why my script never seemed to work with rc.local or most other methods of auto starting. It throws exceptions like Kobe throws 3-pointers. Is Kobe still relevant? I don't watch sports. 

    Anyways... what I really need is some error handling. I finally read up on handling errors in python and it's super convenient. I've made a new roadmap for my script with new, better loops and real error handling. I just need ten minutes or so to sit down and rewrite it. Maybe after the baby goes to bed. Once it's all updated, it should run better, look cleaner, and be able to start from rc.local!

  • It works, completely

    Sean03/28/2019 at 08:11 0 comments

    My run on boot issues are a result of the script failing when it couldn't connect to the bulbs. I tried adding a timer before it connected in hopes that it would give other tasks time to initialize. No luck. 

    Eventually, I discovered daemontools. It automatically runs what you tell it to, but it will restart the script if it fails. Finally! Now all I have to do is give power to the pi and my switch works without any further setup. All that's left is printing the parts in white and putting it in the wall. I guess I should test my power supply first as well. 

    This project is almost complete!

  • It works. Mostly

    Sean03/27/2019 at 13:43 0 comments

    The new code using the flux_led library works perfectly. It turns the lights on and off with so little delay it might as well be a normal switch. This is exactly what I wanted! 

    The problem now is that I can't get it to run on boot. I tried rc.local, which worked with my old code. Nope. I tried crontab. Nothing. I even tried systemd. Nothing seems to make it run on boot. I'll have to dig through the boot logs for clues. 

    At least it works if I SSH in and start it through the terminal. 

  • Better code!

    Sean03/26/2019 at 05:12 0 comments

    You guys!

    I just discovered the flux_led python library. It's compatible with almost all cheapo smart bulbs including my magiclight bulbs. This is a game changer! I can use this script library to directly control the bulbs from my pi zero instead of using IFTTT as a middle man. This had loads of benefits so I'm taking some time to rewrite my script. It will be more code but should be totally worth it. 

  • Prototype is mostly built. Test video linked.

    Sean03/09/2019 at 23:03 0 comments

    Test of the prototype. I printed the plastic faceplate and buttons, and got the pushbutton switches mounted. I didn't have the right size standoffs for the pi so that will come in a few days. The connection is good though and it works as it should. My next step is testing the 5V power supply I bought for this project. 

View all 6 project logs

  • 1
    Configure Pi

    in addition to basic setup of your wifi, add the python script (to be linked somewhere later) to the pi and use pip to install the flux_led library. Modify rc.local to run the script on boot. Make sure you add an ampersand to run it in a forked process.

  • 2
    Wire it up

    solder the switches with connections to pin headers or direct wiring to the pi GPIO pins. Make a cable for power to the pi.

  • 3
    Print plastic bits

    yep. I'll put them on thingiverse once I know it works. 

View all 5 instructions

Enjoy this project?

Share

Discussions

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates