
Simba unser Kater, geboren am 20.07.2017 ist eine sehr gelungene Mischung aus einer British-Kurzhaar-Katze (Vater) und einer Siamkatze (Mutter).


Simba unser Kater, geboren am 20.07.2017 ist eine sehr gelungene Mischung aus einer British-Kurzhaar-Katze (Vater) und einer Siamkatze (Mutter).
Wir haben ein paar Philips® hue Lampen im Esszimmer und Wohnzimmer die man bisher nur über die SmarPhone App oder einem Taster von Phillips bedienen konnte.Die Wand-Schalter machten daher wenig sin. Diese möchte ich gern durch Wand-Taster austauschen. Die über ein ESP8266 die ensprechende PUT Nachricht zu der Philips hue bridge sendt um die volgenden Lampengruppen ein und aus zu schalten:
Das Pinout ist durch die geringe anzahl von Pins sehr übersichtlich wir brauchen daher auch keine so aufwendige Verkabelung damit es laufen wird.
Zum Programmieren habe ich mich eines USB zu TTL-Konverter-Modul von Silicon Labs mit eingebautem in CP2102 bedient. Und mit der Beschreibung zur verkabelung und der anpassungen an der Arduino IDE von StudioPeters Philips hue Switch war es mir dann möglicht das Modul zu Programmieren. Im gegensatz zu der StudioPeters wollte ich zwei Lampen schalten, daher konnte ich das nicht mehr mit einem DeepSleep des ESP und eines auslösen eines Resetzs bewerkstelligen. Daher sieht mein Programm ähnlich aber nicht gleich aus.
/* Project name: ESP8266 - Philips® hue Switch (Push Button)
Project URI: Originaly from https://www.studiopieters.nl/esp8266-philips-hue-switch/
Description: Switch to use with the Philips® Hue bridge and controll two light groups with one module.
Version: 2.3.3
License: MIT Copyright 2020
Note: Adapted to switch Philips HUE groups on or off via a button on the wall that works via an ESP8266.
Adapted and modifyed by Klaus, this will not deep sleep anymore and use the GPIO 0 and 2 to push the light on/off
*/
#include <ESP8266WiFi.h>
#include <SPI.h>
#include <Bounce2.h>
// Network Parameters
IPAddress ip(<a fix IP in your network, e.g. 192, 168, 1, 222);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);
// WLAN Parameters
const char ssid[] = "<WLAN SSID>"; // Network SSID (name)
const char pass[] = "<WLAN-Password>"; // Network password
// Philips HUE Bridge Parameters
const char hueHubIP[] = "<Philips hue bridge IP>"; // Hue hub IP
const char hueUsername[] = "<Philips hue bridge user ID>"; // hue bridge username
const int hueHubPort = 80;
// Lamp group parameters
int living_room_table = 4; // Group number of the lights at the livingroom table
int living_room_door = 3; // Group number of the lights at the terrace door
// Varaibles for internal usage and defined here one time
Bounce Button0 = Bounce(0, 10); // Define a unbonce the Button on GPIO 0 by 10ms
Bounce Button2 = Bounce(2, 10); // Define a unbonce the Button on GPIO 2 by 10ms
boolean Ignore0 = false;
boolean Ignore2 = false;
// Setup the WiFi Client
WiFiClient client;
boolean getHue(int group)
{
boolean onOffState = false; // To store actual on/off state of group
if (client.connect(hueHubIP, hueHubPort))
{
client.print("GET /api/");
client.print(hueUsername);
client.print("/groups/");
client.print(group);
client.println(" HTTP/1.1");
client.print("Host: ");
client.println(hueHubIP);
client.println("Content-type: application/json");
client.println("keep-alive");
client.println();
while (client.connected())
{
if (client.available())
{
client.findUntil("\"on\":", "\0");
onOffState = (client.readStringUntil(',') == "true");
break;
}
}
client.stop();
}
return onOffState;
}
void setHue(String command, int group)
{
if (client.connect(hueHubIP, hueHubPort))
{
client.print("PUT /api/");
client.print(hueUsername);
client.print("/groups/");
client.print(group);
client.println("/action HTTP/1.1");
client.println("keep-alive");
client.print("Host: ");
client.println(hueHubIP);
client.print("Content-Length: ");
client.println(command.length());
client.println("Content-Type: text/plain;charset=UTF-8");
client.println(); // Blank line before body
client.println(command);
client.stop();
}
}
void toggelLightGroup(int group)
{
if (getHue(group) == true) // If the Table light is 'off', turn it 'on' and reverse
{
String command = "{\"on\": false}";
setHue(command, group);
}
else
{
String command = "{\"on\": true}";
setHue(command, group);
}
}
void setup()
{
WiFi.config(ip, gateway, subnet);
WiFi.begin(ssid, pass);
pinMode(0, INPUT);
pinMode(2, INPUT);
while (WiFi.status() != WL_CONNECTED)
{
delay(1);
}
}
void loop()
{
Button0.update();
Button2.update();
if (Button0.fell() == true) // If the button is pressed
{
toggelLightGroup(living_room_table);
}
if (Ignore2 == false && Button2.fell() == true) // If the button is pressed
{
Ignore2 = true; // As long Ignore is true, this part will not execute again
toggelLightGroup(living_room_door);
}
if (Ignore2 == true && Button2.fell() == false) // Reset the Ignore if the button is released again
{
Ignore2 = false;
}
}
Die Hardware sieht wie folgt aus. Ich habe eine einfache Lochsäge in mein Akkuschrauber gespannt und ein Stück Streifenrasterplatiene ausgesägt ca. 55mm im Duchmesser. Das Loch in der mitte ist nicht weiter Tragisch und konnte mit dem rest des Anschlusspin eines Wiederstandes überbrückt werden. Alle Bauteile passen bequem auf die runde Platine 🙂
Viel Spaß beim nachbauen/optimieren 🙂
Gruss
Klaus