more notes for backup and a bad memory - - -
Using Amazon Alexa to control network devices
Objective - Control devices on my home network by verbal commands to an Amazon Alexa Dot
This project demonstrates control by Amazon Alexa of Raspberry Pi GPIO,
an ESP8266 by html code and the use of external bash or python etc. scripts running in the Pi
I experimented with Alexa running on a Raspberry Pi - it can work well but I was not able to get it to boot up after a power loss.
Also it would not find faux wemo devices.
So I bought an Alexa Dot - it can control 16 WeMo devices and I modified this software that can make a a single python program on a Raspberry Pi simulate up to 16 WeMo devices.
This version of the basic program can control GPIO pins on the Pi
The python program fauxmo.py is for use with an ESP8266 - developed after this Sonoff work - see after "FAUXMOS =" where the list of devices can be modified
"kitchen radio" is the Sonoff in my list
The scripts on the Pi that the main program will run depending on the request to Alexa
These are simple Python GPIO controls but they could have any function in any language.
#!/usr/bin/env python # /home/pi/Alexa-gpio/both_off.py import RPi.GPIO as GPIO |
#!/usr/bin/env python # /home/pi/Alexa-gpio/both_on.py import RPi.GPIO as GPIO |
#!/usr/bin/env python # /home/pi/Alexa-gpio/yellow_on.py import RPi.GPIO as GPIO |
#!/usr/bin/env python # /home/pi/Alexa-gpio/yellow_off.py import RPi.GPIO as GPIO |
#!/usr/bin/env python # /home/pi/Alexa-gpio/yellow_on.py import RPi.GPIO as GPIO |
#!/usr/bin/env python # /home/pi/Alexa-gpio/red_off.py import RPi.GPIO as GPIO |
An ESP8266 - 01 program that uses the Arduino IDE - it uses a fixed IP address
GPIO 0 and 2 have LEDs connected via a resistor (>500 ohm) to earth
/home/pi/Alexa-gpio/Alexa_Pi_bridge-1.py -d above is now adapted for my Sonoff ESP8266 switch
/* #include <ESP8266WiFi.h> // from a terminal send curl "http://192.168.0.104/ followed by - const char* ssid = "my SSID"; // Create an instance of the server void setup() { // prepare GPIO0 // prepare GPIO2 // Connect to WiFi network WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { // Start the server // config static IP // Print the IP address // Wait until the client sends some data // Read the first line of the request // Match the request if (req.indexOf("(00)") != -1) //not equal to -1 means it was present if (req.indexOf("(01)") != -1) if (req.indexOf("(20)") != -1) if (req.indexOf("(21)") != -1)
Serial.print("old_val0 = "); Serial.println(old_val0); old_val0 = val0; //else { // Set GPIO according to the request client.flush(); // Prepare the response - for later use???? String temp; // Send the response to the client // The client will actually be disconnected |
Please email me if you want to swap notes