Control Raspberry Pi GPIO Using Amazon Echo (Fauxmo)

7,177

16

39

Posted

Introduction: Control Raspberry Pi GPIO Using Amazon Echo (Fauxmo)

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

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 ....

Share

Recommendations

  • Microcontroller Contest

    Microcontroller Contest
  • Science of Cooking

    Science of Cooking
  • Pocket-Sized Contest

    Pocket-Sized Contest
user

We have a be nice policy.
Please be positive and constructive.

Tips

Questions

Hi, I get the folowing error:
File "/home/pi/Desktop/echo-pi-master/gpio-control.py", line 66
print "State", state, "on ", name, "from client @", client_address, "gpio port: ",gpio_ports[str(name)]
^
SyntaxError: invalid syntax

how can I resolve this?

Capture.PNG

25 Comments

I have added a group in the alexa app containing four of the gpio pins. When I ask alexa to turn on the group of devices, only one device turns on. is this a limitation of this script?

is there any way to change the names so instead of asking for 'GPIO23' you can ask for 'lights' ??

Once the you find the devices you can change the name of the device in the alexa app. This is what I did.

All i did was to change the names of the gpios in gpio-control.py:
my line for gpio_ports = ... ends like this:

'red light':21,'green light':22,'yellow light':23,'gpio24':24,'gpio25':25,'gpio26':26}
so you can see the yellow light is connected to GPIO 23, the green to GPIO 22 and the red to GPIO 21.
Then I changed the names for the triggers like this:

{"gpio15":50015,
"gpio16":50016,
"gpio17":50017,
"gpio18":50018,
"gpio19":50019,
"gpio20":50020,
"red light":50021,
"green light":50022,
"yellow light":50023,
"gpio24":50024,
"gpio25":50025,
"gpio26":50026}

i then saved the gpio-contro.py and re-ran the script.
It works like a charm for me.ATM I'm struggling to create a sequence since this kind of 'device' is not yet supported in the 'routine' section of the Alexa App (Android)

good luck

I'm trying to add a small simple script to this code where as I only want one of the relays to switch on for one second.
this is my script:
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(16,GPIO.OUT)
GPIO.output(16,False)
time.sleep(1)
GPIO.output(16,True)
GPIO.cleanup()
just wondering when to put it in the code to make it work only for that particular GPIO pin.
any ideas or help would be good.

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?

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

Hello, I do not have an Amazon Alexa however i currently use my RapPi as my Homebridge device so that i am able to control wifi enabled devices with my iPhone using the Home App.

I set up Fauxmo on the same RapPi and got it running however the Fauxmo/Wemo device doesn't show up in the apple home app.

Is it possible to get these two applications running together? I have a feeling there is an issue with using the same IP address. Is it possible to change the IP address the Fauxmo Application uses?

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

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