├── LICENSE ├── README.md └── hueremote.ino /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Matt Kunkel 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # esp8266-arduino-hueremote 2 | Simple Hue remote based on the Sparkfun ESP8266 Thing created in Arduino IDE 3 | 4 | Follow the [Sparkfun Tutorial](https://learn.sparkfun.com/tutorials/esp8266-thing-hookup-guide/all) to get started with your Thing. 5 | 6 | To use this remote you'll need to do a few things: 7 | 8 | Install the restclient library files [from github](https://github.com/modulusx/esp8266-arduino-restclient) to the arduinosketches/libraries/restclient directory. You should end up with libraries/restclient/restclient.h and .cpp 9 | 10 | I recommend you set your bridge to have a static IP, then create a new key by following these steps: 11 | 12 | 1. Browse to http://your.hue.bridge.ip/debug/clip.html 13 | 2. Enter /api for the URL 14 | 3. Enter something like {"devicetype":"Thing#hueremote"} 15 | 4. Click POST 16 | 5. You should receive an API key back in the username field. 17 | 6. If this doesn't work, use the real [instructions](http://www.developers.meethue.com/documentation/getting-started). 18 | 19 | To Use: 20 | 21 | 1. Update the Hue Bridge ip in hueremote.ino 22 | 2. Update your Wireless SSID and Password 23 | 3. Update the API key in the remote with your key. 24 | 4. Update or change the buttons to suit your needs. 25 | ..* You can GET /api/yourkey/ to view the names/numbers of each light/group. You can also manage all of the lights and groups using the API, refer to the Hue developers page for more info. 26 | 27 | By design, buttons 1,2,3,4 are wired to pins 0,4,13,12 respectively, and exploit internal pullup resistors, so you just need to GROUND the pin with your switch to trigger it. 28 | -------------------------------------------------------------------------------- /hueremote.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // Global variables 5 | #define ESP8266_LED 5 6 | #define ESP8266_BTN1 0 7 | #define ESP8266_BTN2 4 8 | #define ESP8266_BTN3 13 9 | #define ESP8266_BTN4 12 10 | 11 | // Wireless Network Configuration 12 | const char WIFI_SSID[] = "YOUR_WIFI_SSID"; 13 | const char WIFI_PSK[] = "YOUR_WIFI_PASSWORD"; 14 | 15 | // Hue Configuration 16 | const char HUE_IP[] = "YOUR.HUE.BRIDGE.IP"; 17 | const int HUE_PORT = 80; 18 | restclient hue(HUE_IP,HUE_PORT); 19 | 20 | const char LIGHTS_ON[] = "{\"on\":true}"; 21 | const char LIGHTS_OFF[] = "{\"on\":false}"; 22 | const char EFFECT_COLORLOOP[] = "{\"effect\":\"colorloop\"}"; 23 | const char EFFECT_NONE[] = "{\"effect\":\"none\"}"; 24 | 25 | // App Configuration 26 | bool btn1 = false; 27 | bool btn2 = false; 28 | bool btn3 = false; 29 | bool btn4 = false; 30 | bool party_on = false; 31 | int duration = 0; 32 | int button_press = 0; 33 | 34 | void blinkLED(int dlay, int count = 1) 35 | { 36 | for (int c=0; c < count; c++) { 37 | delay(dlay); 38 | digitalWrite(ESP8266_LED, HIGH); 39 | delay(dlay); 40 | digitalWrite(ESP8266_LED, LOW); 41 | } 42 | } 43 | 44 | void setup() 45 | { 46 | pinMode(ESP8266_LED, OUTPUT); 47 | pinMode(ESP8266_BTN1, INPUT_PULLUP); 48 | pinMode(ESP8266_BTN2, INPUT_PULLUP); 49 | pinMode(ESP8266_BTN3, INPUT_PULLUP); 50 | pinMode(ESP8266_BTN4, INPUT_PULLUP); 51 | 52 | // Set WiFi mode to station (client) 53 | WiFi.mode(WIFI_STA); 54 | 55 | // Initiate connection with SSID and PSK 56 | WiFi.begin(WIFI_SSID, WIFI_PSK); 57 | 58 | // Blink LED while we wait for WiFi connection 59 | while (WiFi.status() != WL_CONNECTED) blinkLED(100); 60 | if (WiFi.status() != WL_CONNECTED) while(1) blinkLED(1000); 61 | } 62 | 63 | void loop() 64 | { 65 | btn1 = (digitalRead(ESP8266_BTN1) == LOW); 66 | btn2 = (digitalRead(ESP8266_BTN2) == LOW); 67 | btn3 = (digitalRead(ESP8266_BTN3) == LOW); 68 | btn4 = (digitalRead(ESP8266_BTN4) == LOW); 69 | duration = 1; 70 | button_press = 0; 71 | analogWrite(ESP8266_LED, 0); 72 | 73 | while (btn1 || btn2 || btn3 || btn4) { 74 | analogWrite(ESP8266_LED, duration * 100); 75 | if (btn1) button_press = 1; 76 | else if (btn2) button_press = 2; 77 | else if (btn3) button_press = 3; 78 | else if (btn4) button_press = 4; 79 | duration = (duration > 9) ? 10 : ++duration; 80 | btn1 = (digitalRead(ESP8266_BTN1) == LOW); 81 | btn2 = (digitalRead(ESP8266_BTN2) == LOW); 82 | btn3 = (digitalRead(ESP8266_BTN3) == LOW); 83 | btn4 = (digitalRead(ESP8266_BTN4) == LOW); 84 | delay(75); 85 | } 86 | 87 | if (1 < duration && duration < 10) { // short press 88 | if (button_press == 1) 89 | hue.put("/api/4ebe05cb477824dd933911f54ebe878/lights/1/state",LIGHTS_ON); // Turn on light 1 90 | else if (button_press == 2) 91 | hue.put("/api/4ebe05cb477824dd933911f54ebe878/groups/1/action",LIGHTS_ON); // Turn on light group 1 92 | else if (button_press == 3) 93 | hue.put("/api/4ebe05cb477824dd933911f54ebe878/lights/3/state",LIGHTS_ON); // Turn on light 3 94 | else if (button_press == 4) 95 | hue.put("/api/4ebe05cb477824dd933911f54ebe878/lights/2/state",LIGHTS_ON); // Turn on light 2 96 | } 97 | else if (duration >= 10) { // long press 98 | if (button_press == 1) 99 | hue.put("/api/4ebe05cb477824dd933911f54ebe878/groups/0/action",LIGHTS_OFF); // Turn off all lights 100 | else if (button_press == 2) 101 | hue.put("/api/4ebe05cb477824dd933911f54ebe878/groups/1/action",LIGHTS_OFF); // Turn off light group 1 102 | else if (button_press == 3) 103 | hue.put("/api/4ebe05cb477824dd933911f54ebe878/lights/3/state",LIGHTS_OFF); // Turn off light 3 104 | else if (button_press == 4) { 105 | party_on = !party_on; 106 | hue.put("/api/4ebe05cb477824dd933911f54ebe878/groups/2/action",(party_on)?LIGHTS_ON : LIGHTS_OFF); 107 | hue.put("/api/4ebe05cb477824dd933911f54ebe878/groups/2/action",(party_on)?EFFECT_COLORLOOP : EFFECT_NONE); 108 | } 109 | } 110 | } 111 | --------------------------------------------------------------------------------