Skip to content

micropython code that toggles a philips hue lamp to be used with a hardware switch making that existing wall switch not cutting the current off but using the api to toggle the lamps state.

License

Notifications You must be signed in to change notification settings

costastf/philips_hue_switch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Philips hue switch

Micropython code that toggles a philips hue lamp using wemos d1 mini or esp8266-01s

This project is to be used with a hardware switch making that existing wall switch not cutting the power off but using the api to toggle the lamp's state.

Some electrical assembly required :)

WARNING

Only mess with high current if you really really know what you are doing. If not certified to do so please refrain from it. It can definitely kill you, which is not a desired outcome for any hobby project.

Problem statement

Philips hue lamps are amazing, providing a wonderful solution for home lighting. The only problem is that the way they are operated leaves some things to be desired.

When the traditional switch is off the lamps of course can not be operated through the app, but only using the app is not realistic for all lights and all conditions. Also people coming over do not have access to the app and many people in a house create confusion.

The current solution is to purchase a separate wireless switch from Philips to use with the lamps but that can get really expensive really quick if you want one for each lamp and of course that does not solve the problem of the traditional switches that either will disrupt the usage of the lights or have to be taken out. Not fun.

Solution

All lights can be operated through the api provided by the hue bridge. Instead of using the switch to cut the power to the lamp leaving it useless, we rewire the lamp to be constantly powered and the switch to an esp8266-01s board to toggle the lamp through the api. That way our switch works as before for all, toggling the state of the lamp and the lamp continues to be accessible through the app all the time. Sweet right?

so we want to go from this initial state:

alt text

to this state (schematic depicting an esp01s):

alt text

Requirements

Enable hue api access to your bridge

If project is based on a wemos D1 mini

If project is based on an esp8266 01s (Current documentation mentions this case.)

Physical Connection

You can see pictures of the connectivity under the images directory.

Schematics

Images in png format and a fritzing project for each case can be found under schematics.

Configuration

Rename configuration_sample.json to configuration.json and edit accordingly. If the board used is a wemos D1 mini the pin should be set to gpio3 (D0) whereas if the board used is the esp8266-01s the pin should be set to 3 (RX) Everything else should just work out of the box.

Flashing micropython

To load this project the microcontroler needs to be running micropython and you need ampy

Required tools:

esp8266-01s specific

To flash the esp8266-01s a component to connect it to usb is required. Remember that it is 3.3v power and will fry with 5v.

In order for the board to be flashed it has to be booted up with d0 pulled low. That means that when the board is booted d0 should be connected to ground.

The easiest way to do that is to stick a thin cable in the appropriate holes as can be seen here. This of course can get pretty old pretty quick if you have a few boards to flash.

A better solution is to add a jumper between ground and d0 as can be seen here and here and choose the appropriate mode of booting by using the jumper cap or not.

Of course in order for the project to work properly when used the esp8266-01s has to be booted with d0 and d1 high, so it does not enter in flash mode.

In order to fix this a 10K pull up resistor has to be connected between d0 and VCC (3.3v) and between d1 and VCC so the pins are kept high and the board boots into running mode even if rebooted.In order to not make the board unflashable by permanent pull ups I have installed jumpers on the pull ups so the board can boot into flash but also be able to be programmed. Images of this connection can be found under images and the final end result with the two pull ups installed is this

In order for the switch to not interfere with the booting process we are using RX (gpio03) as input pulled high through software. That of course will interfere with the serial console so depending on the state of the switch when the board boots you might not have access to the serial console.

common for both wemos d1 mini and esp8266-01s

esptool (Follow installation instructions)

With the board connected to a usb port of your linux box assuming that the port is ttyUSB0 (check with dmesg after connecting to see what is assigned)

After the first command you might have to reboot the board, or just disconnect and connect again.

esptool.py --port /dev/ttyUSB0 erase_flash
esptool.py --port /dev/ttyUSB0 --baud 460800 write_flash --flash_size=detect 0 MICROPYTHON_FIRMWARE_FOR_ESP8266.bin

I have had some wemos d1 mini boards having trouble flashing with the above with garbage on the serial and the led staying on. On those boards this command works.

esptool.py --port /dev/ttyUSB0 write_flash -fm dio -fs 32m 0 MICROPYTHON_FIRMWARE_FOR_ESP8266.bin

Loading the project

Required tools:

ampy (Follow installation instructions)

export AMPY_PORT=/dev/ttyUSB0
ampy put library
ampy put configuration.json
ampy put main.py
ampy put boot.py

About

micropython code that toggles a philips hue lamp to be used with a hardware switch making that existing wall switch not cutting the current off but using the api to toggle the lamps state.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages