-
Notifications
You must be signed in to change notification settings - Fork 0
Home
The objective is to give Amazon's echo, Alexa, the ability to turn on and off X10 devices.
Prerequisite Reading and References:
- UPDATED Amazon Echo X10 Home Control. This uses heyu to control X10 devices. My adaptation uses bottlerocket, br, and adds some user security changes as well. However, this article provides the basic framework that I expanded on. And, has useful examples of how to use ha-bridge's web interface.
- Home automation bridge that emulates a Philips Hue light system, ha-bridge by BWS Systems does the real work in bridging the gap between home automation APPS and the X10 devices.
- bottlerocket web site A command-line interface for Unix systems to use the X10 FireCracker, CM17A. The X10 FireCracker is a, simple RS232 driven and powered, X10 RF remote controller.
- bottlerocket at gethub Current sources
- Using /opt vs /usr/local My usage of /opt may be wrong. Not 100% sure.
Hardware required:
- Raspberry Pi 3 or Raspberry Pi 2 with stable Power Adapter (5.1+ Volt)
- Running
2017-11-29-raspbian-stretch.img
.
- Running
- USB to RS232 converter (Full RS232 voltage levels, not the TTL stuff)
- X10 FireCracker, CM17A
Amazon's Echo has native support for the Philips Hue light system. BWS Systems' ha-bridge emulates a Philips Hue light system providing a path for Amazon echo to interact with devices it does not natively support. Ha-bridge supports many action methods for responding to Phillip Hue light commands. Of these methods we use the ability to run a bash script,
x10ctrl.sh
. This in turns buffers/queues and sends X10 commands via bottlerocket, br
. The X10 FireCracker is powered and signaled by toggling the RS232 control lines. From the computers perspective this is a very slow process. So x10ctrl.sh
manages a named pipe to queue the X10 commands and slowly feed them out with br
.
Rather than having ha-bridge run with root privileges, The service habridge
runs under its own user of same name, habridge
. authbind
is used to allow permission to port 80 from the non-root user, habridge
.
With 2017-11-29-raspbian-stretch.img
, this no longer appears to be needed.
This command will show what is running and available. (source)
pi@raspberrypi:~ $ sudo update-alternatives --display java java - manual mode link currently points to /usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/jre/bin/java /usr/lib/jvm/java-7-openjdk-armhf/jre/bin/java - priority 1063 slave java.1.gz: /usr/lib/jvm/java-7-openjdk-armhf/jre/man/man1/java.1.gz /usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/jre/bin/java - priority 318 slave java.1.gz: /usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/man/man1/java.1.gz Current 'best' version is '/usr/lib/jvm/java-7-openjdk-armhf/jre/bin/java'.
If you need to switch the default Java version among available Java JREs.
Run the following command:
pi@raspberrypi:~$ sudo update-alternatives --config java There are 2 choices for the alternative java (providing /usr/bin/java). Selection Path Priority Status ------------------------------------------------------------ *0 /usr/lib/jvm/java-7-openjdk-armhf/jre/bin/java 1063 auto mode 1 /usr/lib/jvm/java-7-openjdk-armhf/jre/bin/java 1063 manual mode 2 /usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/jre/bin/java 318 manual mode Press enter to keep the current choice[*], or type selection number: 2
In this case enter 2 to select
.../jdk-8-oracle-arm32-vfp-hflt/jre/bin/java
In the commands listed below we will: Create user, habridge
, for ha-bridge to run under, and add users root
and pi
to the habridge
group. Build habridge
directory tree under /opt
. Link the new tree under the user habridge's directory.
If you are doing copy/paste of the commands listed. Do the first two lines first. The adduser
command will want to ask some questions.
sudo -i
adduser --disabled-login habridge
A copy paste of the commands listed here should work.
adduser habridge dialout
adduser root habridge
adduser pi habridge
chmod ug+s ~habridge
mkdir /opt/habridge
mkdir /var/opt/habridge
chown habridge:habridge /opt/habridge /var/opt/habridge
chmod ug+s /opt/habridge
su habridge
ln -s /opt/habridge ~habridge/opt
cd /opt/habridge
mkdir bin etc src log data
ln -s /opt/habridge/log /var/opt/habridge/log
The commands shown in the block below will: Download the ha-bridge java program, install, and setup a link to the java program from the /opt/habridge/bin
directory.
cd /opt/habridge/src
wget https://github.com/bwssytems/ha-bridge/releases/download/v5.1.0/ha-bridge-5.1.0.jar
ln -s /opt/habridge/src/ha-bridge-5.1.0.jar /opt/habridge/bin/ha-bridge.jar
These files will be added:
This block of commands will: Change to user habridge
's home directory, create a link over to the /opt/habridge
directory, and restore the downloaded files to /opt/habridge/src
and /opt/habridge/bin
. The symbolic link can be removed once finished. Or left for installing updates, when available.
cd ~habridge
wget https://github.com/mhightower83/x10ctrl/archive/master.zip
ln -s /opt/habridge ~habridge/x10ctrl-master
unzip master.zip
rm x10ctrl-master # optional, link may be useful for applying future updates.
As shown below, verify you have the following files in the /opt/habridge/src
directory.
ls -l /opt/habridge/src
...
-rw-r--r-- 1 habridge habridge 8341874 Dec 12 13:54 ha-bridge-5.1.0.jar
-rw-r--r-- 1 habridge habridge 392 Dec 22 19:32 habridge.service
As shown below, verify that your files and permissions in directory /opt/habridge/bin
look similar to this:
ls -l /opt/habridge/bin
...
lrwxrwxrwx 1 habridge habridge 37 Dec 16 19:01 ha-bridge.jar -> /opt/habridge/src/ha-bridge-5.1.0.jar
-rwxr-xr-x 1 habridge habridge 754 Dec 22 19:32 start.sh
-rwxr-xr-x 1 habridge habridge 5127 Dec 22 19:32 x10ctrl.sh
If needed, set permissions as shown:
chmod 744 /opt/habridge/bin/start.sh /opt/habridge/bin/x10ctrl.sh
In this block of commands, we exit the user habridge
's account and add some system links as needed.
exit
whoami # this should report root
ln -s /opt/habridge/etc /etc/opt/habridge
ln -s /opt/habridge/src/habridge.service /etc/systemd/system/habridge.service
In this block we install and setup authbind
so a non root
user, habridge
, can create a socket on port 80. If you are doing copy/paste, this must be done into two separate copy/paste steps. One with the apt-get
command by itself, then the remainder as a second copy/paste.
apt-get install authbind
cd /etc/authbind/byport
touch 80
chmod 700 80
chown habridge:habridge 80
These commands will enable and start the habridge
service
systemctl daemon-reload
systemctl start habridge.service
systemctl enable habridge
Use the command below to check the service's status.
systemctl status habridge.service -l
You need to install bottlerocket program br
.
apt-get install bottlerocket
USB serial ports do not always map out to the same device name, /dev/ttyUSBnn
. To make things more reliable you need to create a rules file to setup a reliable symbolic link to the USB RS232 device.
Follow the instructions here: FriendlySymlink.
bash /opt/habridge/bin/x10ctrl.sh J2 on
bash /opt/habridge/bin/x10ctrl.sh J2 off