Introduction: DIY Complete Philips Hue Home Automation

This project will show you how to create a complete Philips Hue system based on EPS8266 sensors/lights and a RaspberryPi or any similar board as Hue Bridge. Hue API is used so all smartphone applications must be able to control the lights.

Update: starting with version 2 is possible to use ZigBee lights, sensors and switches with Raspbee module for RaspberryPI.

Step 1: Deploy Philips Hue Bridge Emulator (obtional)

  1. Download entire project from https://github.com/mariusmotea/diyHue
  2. install nmap package: $ sudo apt install nmap
  3. start hue emulator: $ sudo ./HueEmulator.py

Step 2: Lights

IKEA Tradfri

Open http://{bridgeIP}/tradfri, type Ikea bridge ip and security key in form and then click "Save". If everything was fine you will see all lights paired with Tradfri bridge in Hue application. Important: coap-client-linux binary is compiled for arm devices like raspberry pi. If you will use an x86 computer then you will need to recompile this.

Mi-Light

esp8266_milight_hub is required https://github.com/sidoh/esp8266_milight_hub. Open http://{bridgeIP}/tradfri complete the form and click Save. You need to repet this step for every light as there is no way to retrive the list of lights from milight hub.

Neopixels strips

In lights directory you will find Arduino sketches to both WS2812B (rgb) and SK6812 (rgbw) smart leds. Data in pin of the strip must be connected to RX pin on any ESP8266 device (i work with ESP-12E and WEMOS D1 mini). Before project compilation there are a few options that you must setup:

  • lightsCount x #number of emulated lights per strip, available only for neopixels strip.
  • pixelCount xx # number of leds in strip, available only for neopixels strips

  • IPAddress strip_ip ( xxx, xxx, xxx, xxx); # if you want to use static ip uncommented this

Generic PWM Lights

Here i include all bulbs and strips controllers from the market that are ESP8266 based and use PWM to control the brightness of the leds. The only real difference between them is the order of output pins. If you intend to buy some cheap wifi bulbs/strips and want to use this project you will need to check how hard is to flash the firmware in that light. So far i use only "Color Dreams" wifi bulbs and i was not able to flash the firmware easy using external serial adapter connected directly to ESP8266 pins. However for me was not that hard to replace the SPI flash chip from these bulbs with ones already flashed on WEMOS d1 mini pro, but i have some electronics skills and was not first time when i replace an SOT8 chip.

Setup Lights

Lights use WiFi manager in order to setup wifi connection. You will need to connect to SSID "New Hue Light", open the browser and access https://192.168.4.1. From there you will setup you wifi credentials.

After successful connection to wifi open in browser and enter the light ip address. From here you can control the light, choose power mode (if Last State is selected there will be a short flash on every light power off because of eeprom data write), and default scene from available list.

Lights API

If you want to control the lights from your own application....

"http://{light ip}/set?light=1&r=0&g=60&b=255&transitiontime=2000"

"http://{light ip}/discover"

list of arguments that can be passed in url:

"on": 1 to set light on, 0 to set the light off.

"r", "g", "b": setup light color using rbg values between 0 and 255.

"x" and "y": values between 0.0 and 1.0 to setup light color in CIE chart.

"ct": value between 153 (max warm white) and 500 (max could white) http://en.wikipedia.org/wiki/Mired

"hue": value between 0 and 65535, represent the hue of the light.

"sat": saturation of the light. 255 is the most saturated and 0 is the least saturated.

"bri": brightness of the light, 255 is the maximum brightness,

"transitiontime": duration of the transition from the light’s current state to the new stat. default 4 represent 0.4 seconds.

"bri_inc": increase or decrease the brightness with a specified value

Step 3: Sensors

Require basic knowlege of electronics, in order to build the circuit from picture!

If is used an ESP-12E module, then must connect pin gpio15 with a 10k resitor to ground and pin CH_PD with a 10k resistor to VDD. If everything is ok on first power on you will be able to see and configure a new switch in application. Is important to use static ip's because dhcp require extra time to perform the action. Switch will stay alive just 5 seconds, then will enter in deep sleep mode and will consume just 17uA. Once a button is pressed there will be a short negative pulse on RST pin that will wake up the module. This operation will take about 0.5 seconds. If the button is released in this period the chip will be unable to detect what button was pressed and will not send any requests to bridge.

Step 4: Control the Lights From Hue Applications

  1. Open Philips Hue official application
  2. Scan for new bridge. Auto discover must work, if not click Help button and manually type the ip address
  3. Scan for new lights (if there are many devices that are listening on port 80 not all lights may be discovered on first scan)
  4. Create rooms and map the lights to them.
  5. Play with the lights, try more hue applications.
  6. Optional - create routines, Wake Up and Go to Sleep tasks.

Is important to watch my github page because there are fast updates.