Control Raspberry Pi GPIO Using Amazon Echo (Fauxmo)


16,460

20

42

This project covers controlling Raspberry Pi GPIO using an Amazon Echo.
It uses Fauxmo which enables the RPi to pretend as a WeMo device. Fauxmo is a Python 3 module that emulates Belkin WeMo devices for use with the Amazon Echo.

To get a confirmation of change in state for GPIO you either look at the terminal in which you will run the code or use this instructable to connect GPIO ( for this project 16-26) to an LED for visual check.

Inspired by Home Automation With Amazon Echo Voice Control by FabricateIO

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Setup and Test

You will need an Amazon Echo, Raspberry Pi ( I am using a RPi 3 Model B) and copy of source code.

  1. Download a copy of the source code in your RPi 'home' (~/)
    git clone https://github.com/kanesurendra/echo-pi.git
  2. Move to source directory:
    cd echo-pi
  3. Execute the script using:
    python gpio_control.py
  4. Say to your Echo : "Alexa, discover devices"
    Each GPIO is registered as a independent device and can be controlled separately.
  5. To change a state of GPIO say : "Alexa, turn on gpio21" or "Alexa, turn off gpio21

Step 2: Summarizing ...

Although this allows you to control individual GPIO's, by experimentation found that it allows only about 9-10 devices (GPIO's) to be discovered. The Echo discovery ends in 20 secs; before the script can respond to discovery if all 26 gpio pins are included.

Hence in the above source code only the gpio16 - gpio26 are added as devices and can be controlled.
Looking for a fix or alternative ....

Microcontroller Contest 2017

Participated in the
Microcontroller Contest 2017

1 Person Made This Project!

Recommendations

  • Made with Math Contest

    Made with Math Contest
  • Multi-Discipline Contest

    Multi-Discipline Contest
  • Robotics Contest

    Robotics Contest

42 Discussions

None
SharjeelG

2 years ago

Traceback (most recent call last):

File "/home/pi/gpiocontrol.py", line 6, in <module>

from debounce_handler import debounce_handler

ImportError: No module named 'debounce_handler'

While i am trying to run the program it showing this error.

Can u help me plz?

1 reply
None
JoM98SharjeelG

Reply 2 months ago

Sounds like /home/pi directory does not have debounce_handler.py python3 script is missing.

Your gpiocontrol.py script on line 6 has the following python3 statement:

from debounce_handler import debounce_handler

this imports debounce_handler.py python3 code

You will need this code to stop Alexa from making multiple calls to device_handler when you Ask Alexa to control your fauxmo Wemo device.

None
bvis222

1 year ago

Hi and Thanks,

I have one working and only using 3 gpio ports...I'm trying to get another rPi running with a different 3 ports but can't get Alexa to discover the ports.

Is it possible to run more than one rPi this way??? or do I need to change a setting???

thx

1 reply
None
JoM98bvis222

Reply 2 months ago

each raspberry pi should be using a static IP address, so you can use the same port numbers.

The way fauxmo.py python3 script works, the fauxmo.py uses the following as the TCP port number

(Static IP Address of your raspberry pi):51000 for one “named device 1”
(Static IP Address of your raspberry pi):51001 for one “named device 2”
And so on

So if my raspberry pi’s static IP address is 192.168.1.30

So, Then each “named device 1” would be at 192.168.1.30:51000

and

“named device 2” would be at 192.168.1.30:51001

Again, as long as your raspberry pi have unique static IP addresses then you can use the same port numbers for each raspberry pi.

Of course each raspberry pi will HAVE different IP addresses otherwise you would not be able to talk to each raspberry pi over your Ethernet. You DHCP server (or your router) does this for you automatically.

To assign a static IP address to your raspberry pi, you will need to access your router’s LAN setup and reserve an IP address for the MAC address of your raspberry pi. To find the MAC address of your raspberry pi do the following at a command prompt “ifconfig”

Look at the output from ifconfig and either on “eth0” or “wlan0” you will see an address assigned 192.168.x.xx then look for “ether” string. The MAC or “ether” is in the following format for raspberry pi:
b8:27:eb:xx:xx:xx where xx:xx:xx is different for each raspberry pi

93D5882D-87CF-49D9-84BE-92FBF4F2623D.png
None
GerdH3

1 year ago

I installed it, It runs with no errors, but Alexa does not find any device. I am in Germany, my Alexa speaks German. Is there a problem with this?

PI Alexa.JPG
8 replies
None
IvánC166GerdH3

Reply 1 year ago

Having same problem but in English... Did you found a solution?

None
GerdH3IvánC166

Reply 1 year ago

not yet. I tried something. I wrote the IP:Port in my browser - an the raspeberry reacted. So I am sure, the script is running. But Alexa still cant find the devices from raspberry. But it finds the Hue-Lamp from Philips.

None
GerdH3GerdH3

Reply 1 year ago

Maybe the new Alexa plus is the problem? WhichAlexa do you use?

None
TLSBrenttimeGerdH3

Reply 1 year ago

I am having the same issues I have an echo dot gen 2

None
JoM98TLSBrenttime

Reply 2 months ago

This is critical:

Your raspberry pi MUST BE ON THE SAME WiFi network as the Alexa devices (Amazon Echo, Amazon Echo Dot or Amazon Echo Plus)!!! If you raspberry pi is on a different subnet then your Echo devices Alexa will NOT discover them. Also use a static IP address on your raspberry pi. Because if your raspberry pi’s IP address changes AFTER Alexa has discovered your fauxmo Wemo devices, Alexa will no longer work. If your raspberry pi IP address changes you will have to have Delete the fauxmo devices from the Alexa App and redo the discovery process again

Hint:
When trying to discover your fauxmo devices place fauxmo.py into DEBUG mode so you can see the fauxmo print statements. WAIT until you see “searching for device” printed to the screen BEFORE you tell Alexa to discover devices. The fauxmo.py python3 script has to enter a polling state so it can respond to the discovery process

None
AlexanderW21GerdH3

Reply 1 year ago

Hey there, i also have that problem... i'm using the V2 Medium sized Alexa.
My pi is also reacting when i try to contact it via browser. Still Alexa can't find the device...

None
TLSBrenttimeAlexanderW21

Reply 1 year ago

I ended up fixing mine, but I am unsure exactly how; however, I narrowed down a couple things I did.

A) I manually restarted the network

B) Made sure the network was given more IP address

1) I actually figure it was this one considering it only had 32 IPs that could be assigned, and, as such, my entire family of 7 easily dominated the network with all of their devices.

None
nobbygreenGerdH3

Reply 1 year ago

which echo are you using? I had a problem using the amazon echo, but I tried my sons amazon dot and it worked flawless. maybe you could try?

None
nobbygreen

1 year ago

my Alexa is not finding any devices? any help would be appreceiated

1 reply
None
JoM98nobbygreen

Reply 2 months ago

This is critical:

Your raspberry pi MUST BE ON THE SAME WiFi network as the Alexa devices (Amazon Echo, Amazon Echo Dot or Amazon Echo Plus)!!! If you raspberry pi is on a different subnet then your Echo devices Alexa will NOT discover them. Also use a static IP address on your raspberry pi. Because if your raspberry pi’s IP address changes AFTER Alexa has discovered your fauxmo Wemo devices, Alexa will no longer work. If your raspberry pi IP address changes you will have to have Delete the fauxmo devices from the Alexa App and redo the discovery process again

Hint:
When trying to discover your fauxmo devices place fauxmo.py into DEBUG mode so you can see the fauxmo print statements. WAIT until you see “searching for device” printed to the screen BEFORE you tell Alexa to discover devices. The fauxmo.py python3 script has to enter a polling state so it can respond to the discovery process!

None
troberts618

1 year ago

When I add a crontab entry "@reboot sudo python /home/pi/gpio-control.py", the discovery fails. Is there another way to autostart the script without using crontab?

3 replies
None
nobbygreentroberts618

Reply 1 year ago

boot your pi as normal, then from the directory you have it saved run this:
nohup python gpio-control.py > /dev/null 2>&1&
then it will run in the background and after you close your terminal

None
StuartW60nobbygreen

Reply 1 year ago

I'm having the same problem. Adding the cron with @reboot directive or adding to rc.local doesn't launch the script for some reason. Logging in when the device boots up to run a command is not the same functionality as a @reboot directive in cron.

None
JoM98StuartW60

Reply 2 months ago

You must use “sudo crontab -e”. For the gpio pins to be manipulated by the system you must add the following to “sudo crontab” not the pi user’s crontab which it sounds like you are using.

Do the following:

At the command prompt:

$ sudo crontab -e
$ pick nano as your editor

Make sure each entry in crontab has a blank line after it. I put in comment lines by using “#” on the next line

Add the following line to run your python3 script in sudo crontab:

#
@reboot (/bin/sleep 30; sudo /usr/bin/python3 /home/pi/IOT-Pi3-Alexa-Automation-master/JoAnn_RPi_name_port_gpio11.py > /home/pi/IOT-Pi3-Alexa-Automation-master/JoAnn_log11.txt 2>&1)
#

now press control-X to save the file
Press Y then hit the return key

This will save the sudo crontab and now reboot the pi by typing in sudo reboot at the command prompt

If you ever want to stop the python3 script from running just place a “#” before the @reboot to temporarily disable that line in the “sudo crontab” Table

None
EmmanuelB74

Question 11 months ago on Step 2

Does anyone have an alternative way to do it using a raspberry 2?