Hier zeige ich wie einfach es ist ein oder mehrere Lampen oder andere Geräte mit einem Amazon Echo Dot zu schalten.
Voraussetzungen:
Amazon Echo
Einen gültigen Amazon Account
WeMos mini mit ESP8266
Relay Karte
Steckboard Kabel 6 Stück
Steckboard
Hardware:
Original Software:
https://github.com/CharlesJGantt/LinkNode-R4-Controlled-By-Amazon-Alexa/tree/master
Schaltung:
Pin D0 -> IN1 (Lampe 1)
Pin D5 -> IN2 (Lampe 2)
Pin D6 -> IN3 (Lampe 3)
Pin D7 -> IN4 (Lampe 4)
5V -> Vcc (braun)
G -> GND (blau)
Software mit meinen Änderungen
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
#include <ESP8266WiFi.h> #include <ESP8266WebServer.h> #include <WiFiUdp.h> #include <functional> #include "switch.h" #include "UpnpBroadcastResponder.h" #include "CallbackFunction.h" #define EIN LOW #define AUS HIGH // https://www.youtube.com/watch?v=t5QEt-vX5Ng // prototypes boolean connectWifi(); //on/off callbacks void lampe1On(); void lampe1Off(); void lampe2On(); void lampe2Off(); void lampe3On(); void lampe3Off(); void lampe4On(); void lampe4Off(); // Change this before you flash const char* ssid = "xxx"; const char* password = "xxx"; boolean wifiConnected = false; UpnpBroadcastResponder upnpBroadcastResponder; Switch *lampe1 = NULL; Switch *lampe2 = NULL; Switch *lampe3 = NULL; Switch *lampe4 = NULL; // Set Relay Pins int relayLampe1 = 16; int relayLampe2 = 14; int relayLampe3 = 12; int relayLampe4 = 13; void setup() { //Set relay pins to outputs pinMode(relayLampe1,OUTPUT); pinMode(relayLampe2,OUTPUT); pinMode(relayLampe3,OUTPUT); pinMode(relayLampe4,OUTPUT); digitalWrite(relayLampe1, AUS); digitalWrite(relayLampe2, AUS); digitalWrite(relayLampe3, AUS); digitalWrite(relayLampe4, AUS); Serial.begin(115200); // Initialise wifi connection wifiConnected = connectWifi(); if(wifiConnected){ upnpBroadcastResponder.beginUdpMulticast(); // Define your switches here. Max 14 // Format: Alexa invocation name, local port no, on callback, off callback lampe1 = new Switch("Lampe eins", 80, lampe1On, lampe1Off); lampe2 = new Switch("Lampe zwei", 81, lampe2On, lampe2Off); lampe3 = new Switch("Lampe drei", 82, lampe3On, lampe3Off); lampe4 = new Switch("Lampe vier", 83, lampe4On, lampe4Off); Serial.println("Adding switches upnp broadcast responder"); upnpBroadcastResponder.addDevice(*lampe1); upnpBroadcastResponder.addDevice(*lampe2); upnpBroadcastResponder.addDevice(*lampe3); upnpBroadcastResponder.addDevice(*lampe4); } } void loop() { if(wifiConnected){ upnpBroadcastResponder.serverLoop(); lampe1->serverLoop(); lampe2->serverLoop(); lampe3->serverLoop(); lampe4->serverLoop(); } } void lampe1On() { Serial.print("Switch 1 turn on ..."); digitalWrite(relayLampe1, EIN); // sets relayOne on } void lampe1Off() { Serial.print("Switch 1 turn off ..."); digitalWrite(relayLampe1, AUS); // sets relayOne off } void lampe2On() { Serial.print("Switch 2 turn on ..."); digitalWrite(relayLampe2, EIN); // sets relayOne on } void lampe2Off() { Serial.print("Switch 2 turn off ..."); digitalWrite(relayLampe2, AUS); // sets relayOne on } void lampe3On() { Serial.print("Socket 1 turn on ..."); digitalWrite(relayLampe3, EIN); // sets relayOne on } void lampe3Off() { Serial.print("Socket 1 turn off ..."); digitalWrite(relayLampe3, AUS); // sets relayOne off } void lampe4On() { Serial.print("Socket 2 turn on ..."); digitalWrite(relayLampe4, EIN); // sets relayOne on } void lampe4Off() { Serial.print("Socket 2 turn off ..."); digitalWrite(relayLampe4, AUS); // sets relayOne on } // connect to wifi – returns true if successful or false if not boolean connectWifi(){ boolean state = true; int i = 0; WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); Serial.println(""); Serial.println("Connecting to WiFi"); // Wait for connection Serial.print("Connecting ..."); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); if (i > 10){ state = false; break; } i++; } if (state){ Serial.println(""); Serial.print("Connected to "); Serial.println(ssid); Serial.print("IP address: "); Serial.println(WiFi.localIP()); } else { Serial.println(""); Serial.println("Connection failed."); } return state; } |
Konfiguration:
Smart Home -> Geräte -> Suche -> (Geräte werden gefunden) – >Speichern
Gruppe erstellen um alle Lampen durch die Befehle „Alexa Lampen ein/aus“ ein- oder auszuschalten.
SmartHome -> Gruppen -> Gruppe Erstellen -> Gerätegruppe -> „Lampen“ (Geräte zuordnen) -> Speichern