Control Raspberry Pi GPIO Using Amazon Echo (Fauxmo)

14,641

19

34

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

  • Fandom Contest

    Fandom Contest
  • Gardening Contest

    Gardening Contest
  • Woodworking Contest

    Woodworking Contest

34 Discussions

0
None
oneharrydude

1 day ago

To those who have been issues with discovery it is because of the new Alexa app and newer echo devices.... I had an older original echo dot do device discovery and it worked like it should! Once it has been discovered by the older echo you can use it in the current app.

0
None
EmmanuelB74

Question 5 months ago on Step 2

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

0
None
Ronin316

7 months ago

I got all of the gpio pins to work. Only problem is I'm not sure how. I first replaced 15 through 26 with 1-14 by cutting and pasting to see if it was a time issue or something else. I was able to recognize 1-14. Then I changed the file back to original and made sure 15-26 still worked. I realized that there is more in 1-14 thank 15-26. So I cut 12-14 from the top list and added them to the 15-26. Rebooted rediscovered and they showed up. I cut and pasted from the top list to the bottom list 5 of a time. Rebooting and checking until the top list was empty and the bottom list contained them all. I can now access all gpio pins from my echo or from the alexa app on my phone

0
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?

2 replies
1
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

0
None
StuartW60nobbygreen

Reply 10 months 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.

0
None
pcook10

1 year ago

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

3 replies
0
None
shaggs31pcook10

Reply 1 year ago

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

0
None
StuartW60shaggs31

Reply 10 months ago

This is what I did. There's no point in changing the script since you can rename them once they are discovered.

0
None
ChucheSpcook10

Reply 1 year ago

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

0
None
shaggs31

1 year ago

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?

1 reply
0
None
StuartW60shaggs31

Reply 10 months ago

I have the same issue, although I get random number of pins responding. Sometimes only one, sometimes zero, sometimes two.

0
None
BradS139

Question 10 months ago

When I try to connect this to a power relay board the modules stay on always. Is there a way to fix this? I have it connected to the VCC of the pi, with a jumper on the VCC and JD-VCC of the relay board. If I give the relay its own power source will that allow the voice commands to control the relay through the gpio commands?

1 answer
0
None
StuartW60BradS139

Answer 10 months ago

If you supply the relay board with its own power, then you will still wire up vcc, gnd, and each relay control pin to the raspberry pi as normal. The problem is that the pi doesn't have enough power to run itself, the control circuit of the relay board, and the relays itself. Disconnect the jumper and connect a separate 5V power supply to the JD-VCC and GND pins to the side of the main bank of pins.

0
None
nobbygreen

1 year ago

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.

0
None
ItamarV3

Question 1 year ago on Step 2

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
0
None
kingphil123

1 year ago

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?

0
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
2 replies
0
None
IvánC166GerdH3

Reply 1 year ago

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

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