User Tools

Site Tools


supported_hardware:alexapi

Alexa Plugin For The Raspberry Pi

Since a recent update to Amazon’s Alexa forces us to run our hue hub emulation on port 80 only a single instance of the alexa plugin can be run on any one machine. This would limit you to only 20 devices shared through Alexa. In order to work around this limitation in a way similar to running multiple instances of the old plugin you now have to run the different instances on different machines. In this case inexpensive raspberry pi machines.

If you haven’t already please review the main Alexa Plugin Page as all the information other than the XTension setup is identical for this remote plugin. For more information you may wish to also see the Alexa With Sudo plugin page as well which has more discussion of the nature of the problem and how it is fixed for the first instance of the Alexa plugin and why you may need a raspberry pi for additional instances.


Setting Up Your Raspberry Pi

This is not an extended tutorial on setting up a Raspberry Pi. Set it up as per the regular instructions on the raspberry pi site. This plugin will happily run on either the desktop or the command line only version of the Pi OS.

If you change the username or create a separate user for the application to run as please make sure that the same sudo without having to enter a password us setup for that user as well,

It is also important to give your Pi a static IP address. Instructions for this can be found on the raspberry pi documentation site but I also outline them in the setup for the APC UPS monitor here.

While the Alexa plugin does require port 80 be available for it to use it is not otherwise a very heavy load on the processor or cf card space on the Pi. You should be able to use the same pi for any number of other things at the same time without causing any problems. It will run equally well on the newer Pi4 all the way down to the Pi Zero or Pi Zero W devices. If you use a Pi without built in WiFi or Ethernet port you’ll need a USB or “Hat” to provide for a network connection. These all work fine with the plugin.


Requirements:

  • The Alexa On Raspberry Pi plugin requires at least version 9.4.28 of XTension.
  • The plugin requires Python 3 which is installed by default on both the desktop and command line only versions of the current Raspbian OS.
  • Obviously a valid network connection and interface is required. If your Pi does not have either wifi or wired ethernet you will need either a USB/Ethernet adaptor or a “Hat” that provides for an ethernet jack.
  • No other non-default Python packages are used by the plugin.

Installing the Plugin

Once your Pi is up and running you need to install the software. If you are using the desktop version of the raspberry pi OS you can run the browser and download the file from https://MacHomeAutomation.com/files/xt_alexa_current.gz If you’re running from the command line you can download and unzip the file by running:

curl -o /home/pi/xt_alexa.gz https://machomeautomation.com/files/xt_alexa_current.gz ; tar zxvf /home/pi/xt_alexa.gz

The rest of this will assume you installed it inside the /home/pi/xt_alexa directory as shown. If you move it to a different place you will have to alter the XTension settings.


Configuring XTension

In the Outgoing Network Connection section enter the IP address or bonjour/mDNS name of your Raspberry Pi. Unless you’re running the SSH server on a different port or are passing through a NAT router leave the port at 22.

Database Sharing Settings: Selecting what to share with this Alexa instance is identical to the same setup for the original Alexa plugin. If you haven’t already done so review that page here. Alexa limits the number of devices you can share to just 20 in any instance of the plugin. This is why this may be necessary for some folks who wish to share more items.

Raspberry Pi SSH Login: XTension will run the plugin code via an SSH connection so enter the User and Password for the account that you want to run the plugin as. The account must be setup as the default Pi account is and be able to sudo a command without having to enter your password or the plugin code will not be able to listen on port 80. If you use a different account or have altered the default settings for the Pi user you may been to specifically set that up for it but by default this will work fine.

Command To Run On The Remote Machine: If you installed the plugin code in the default location that the command above would have used then the default for this field is fine. The default is “sudo /home/pi/xt_alexa/alexa.py” if you have moved the install or are running it as a different user you may have to change the path to the program.

XTension Connection Settings: The data connection back to XTension is not run through the SSH connection but rather through a standard TCP pipe. In the XTension Connection Settings please enter the static IP address or bonjour/mDNS name of your XTension server. If you have changed the default port that XTension runs it’s plugins on or are passing through a NAT router you may need to change the port number. Otherwise leave it at it’s default of 52301

At this point your plugin should be ready and you can save and then enable the plugin from the Interface List Window. You will see a line in the log from XTension that it is starting up the interface and then shortly thereafter you should see another line that comes from the plugin code running on the raspberry pi saying that the plugin is ready.


Converting an Existing Alexa Interface:

It may be possible to convert an existing interface to a remote Raspberry Pi interface and keep all the devices in Alexa the same. By switching the plugin type from the original Alexa plugin to the Alexa On Raspberry Pi type all the device ID’s and hub ID’s will be preserved so it is possible that Alexa will simply think that your previously configured interface has gotten a new IP address and pick up right where it left off.

If this does not work then it will be necessary to have Alexa forget the devices on this interface and re-discover them. This is easiest to do from the https://alexa.amazon.com/ site or via their mobile apps. If you have no other interfaces you can do a forget all and then rediscover them all. If this is one of several interfaces you don’t want to forget every thing. In that case go down the list and have her forget only the devices assigned to this interface and then ask her to discover devices to re-find them.

There were other changes to the requirements for the data output with the other Alexa firmware changes that may make it unreliable to convert an existing interface. I have seen some that were successful but many that had to forget and rediscover. Once you have the shared units re-discovered you can go back in to the Alexa app and fix up any name changes or action phrases that you made there to reflect the new devices.


Troubleshooting:

If you see a file not found error in the log please verify that the path in the Command To Run On The Remote Machine field holds the word “sudo” then a space and then the shell path to where you installed the plugin code on the pi.

If you see a permission denied error the most likely cause is that the execute bit on the program got lost during the transfer or unzipping. You can restore that by executing the following command. If you’ve changed the user or have installed it in a different location you will need to change the path to the plugin program.

chmod a+x /home/pi/xt_alexa/alexa.py

It is also possible that the user you’re running as does not have the ability to sudo without entering the password. By default this is turned on for the Pi user. If you need to turn it on for a different user you may need to create a new sudoer file for the user. You can see the existing sudoers files by going to /etc/sudoers.d directory in the command line. Running ls will show you the files and there should be one there named something like “O1O_pi-nopasswd” all the files in this directory are owned and only writable as root so anything you do to them you must always do with the sudo in front of. To make a copy of this file for a different user do something like:

sudo cp /etc/sudoers.d/010_pi-nopasswd /etc/sudoers.d/020_otherusername-nopasswd

and then you need to edit that file to hold the proper new user name:

sudo nano /etc/sudoers.d/020_otherusername-nopasswd

you’ll see a line that looks like this:

pi ALL=(ALL) NOPASSWD: ALL

change the initial reference to the “pi” user to the username that you are running the program as and save the changes and try again.


History:

  • The Alexa On Raspberry Pi plugin was introduced in XTension version 9.4.28 in February of 2020
/home/e805485/machomeautomation.com/data/pages/supported_hardware/alexapi.txt · Last modified: 2023/02/13 14:52 by 127.0.0.1