As I speculated, HA Bridge is a very good proxy between Amazon Alexa and IoT devices defined in Domoticz. Installation was straightforward, aside from a little bit of fumbling adding Java which is a prerequisite. The details are provided below.
It would be just as viable to install HA Bridge of the same Raspberry Pi that is hosting the home automation server. However, that Pi has a relatively anemic single core ARMv6 CPU so spreading the load may be a good strategy.
Table of contents
- Installing Java
- Installing HA Bridge
- Importing Domoticz Devices
- Using HA Bridge Devices with Alexa
- UPNP
- HA Bridge Database Backup
- Conclusion
Installing Java
Begin with the usual update and upgrade before attempting to install the required Java SDK.
After the update, Armbian is using version 4.19 of the Linux kernel.
There is an "untrusted" PPA (Personal Package Archive) belonging to the "WebUd8" team which contains the Oracle Java 8 runtime environment JRE. The instructions on that page do not include details about importing the GPG signing keys, while the page entitled Install Oracle Java 8 (both JDK8 and JRE8) in Debian contains the missing information.
This is not an Open source package, and it is necessary to accept the licence agreement with two clicks.
After the last installation message is displayed, test for the presence of the run time interpreter and the compiler.
Since javac
, the compiler, is installed, the Java Development Kit (JDK) was installed. The JDK is a
superset of the JRE capable of creating and compiling Java programs.
As can be seen, the version of Java that was installed was not open source which is why the Oracle licence had to be accepted. There is an open source version. I did not test it on Armbian, but I did install it on a Raspberry Pi 3 running Raspbian Stretch.
That did not go very smoothly. There was a problem with getting the
source from the repository, so I retried a few minutes later. The whole
package was downloaded but there were problems. I had to repeat yet again the
install command and found that dpkg
was having problems setting
up ca-certificates
. Others had bumped up against this problem
and some clever people found the solution and posted it on the Raspberry Pi
Forum topic missing jvm server. Either of the last two replies (as of the
time of writing this) by gasi12 or by amal.barman give a working solution. I applied the last one.
As can be seen, the last installation did yield some complaints but the run time environment appear to be in place. After that I added HA Bridge as described below and it did work with OpenJDK.
I did not test this in Armbian. It does look as if OpenJDK could be installed along with Oracle JDK8 following How To Install Java with Apt on Debian 9 by Brian Hogan. I decided to leave well enough alone. Perhaps at a later date, I will try the OpenJDK on the Orange Pi Zero.
Installing HA Bridge
Installing HA Bridge is pretty straightforward following the instructions in Manual installation of ha-bridge and setup of systemd service. Just make sure to check the name of the latest release on the GitHub site. Currently this is version 5.2.2 Release candidate #3 available since November 14, 2018.
First download the latest release, which is a .jar
file, and
then create a unit
file.
Do not forget to adjust the WorkingDirectory
and
ExecStart
lines so that the current user name is used.
Importing Domoticz Devices
HA Bridge has a Web-based interface at the
default HTTP port: 80. Hence the URL to reach
the bridge is http://opi.local
or
http://192.168.1.32
assuming that is the DHCP assigned
address of the Orange Pi Zero or, in my case, because I set a static address
using armbian-config
.
Of course when first started, HA Bridge does not have links to any devices as can be seen on the initial login page screen.
However, it is very easy to import all of the devices already set up in Domoticz. Click on the Bridge Control button/tab.
And then scroll down to Domoticz Names and IP Addresses
.
Only three fields had to be filled in: Name
, which
can be anything, IP
and Port
which must be
the address of the Domoticz server. The latter's
website is protected with a username and password but clients on the
local network do not have to supply these as defined in its
Setup/Settings
page.
Once these three values are set, two buttons must be pressed. First the HA Bridge pops up a "wait until initialization is completed" message. I found it necessary to refresh the page after that message disappeared and then a new button/tab appeared: Domoticz Devices. Clicking on it, reveals list containing all devices, groups and scenes defined in Domoticzs.
button to the right of the fields and then the button at the top of the page. As soon as that button is pressed,I checked the devices and groups that I wanted to control with voice commands to Alexa on the Echo Dot. There were 14 of them. Then I clicked on the button at the bottom of the page. I waited a little while, refreshed the page and found the added devices in the tab.
Using the HA Bridge
treated them as switches but Domoticz uses slightly
different JSON URLs for switches and groups/scenes. Click on the
button
of each scene or group and modify the Target Item
of the On Items and Off Items.
The change is minimal, ¶m=switchlight
should be
¶m=switchscene
as shown below.
If you wish, it is possible to change the device type to group
or scene
as appropriate. This is cosmetic and does not change
anything.
Do not forget to click the
button at the top of the page after both edits to complete the operation. Test that these scenes or groups now work with the , buttons.And that is basically it, HA Bridge is now functional. You can click on the My Echo button at the top of the page to let Alexa discover all the devices that HA Bridge now makes available.
Using HA Bridge Devices with Alexa
Because of my previous experimentation Amazon Alexa and HA Bridge, I had to undo some things. Unfortunately, I did not record exactly what I did, which in any case would not be very useful. Quickly, here is how I went about getting Alexa back to its initial status.
- I stopped the Philips Hue and Wemo emulation on two Sonoff with
Tasmota firmware. This is done with the Web
interface of each switch and clicking on the , buttons and then selecting
None
in theEmulation
section. - In the Amazon Alexa application, I clicked on Smart Home and then removed all the groups, scenes and devices that I had previously created when first testing the application. The only exceptions were the Echo Dot and the Amazon Smart Plug.
I used the Amazon Alexa web interface to initiate discovery. Apparently, this can
be done with a verbal command but the Echo Dot is
down two flights of stairs, and I am much too old to run up and down stairs
and was too much in a hurry to leisurely do the round trip. I clicked on
Smart Home then Devices
and then on the button. I am
"guessing" about these names translating them from the French terms.
I pressed the discover button twice, perhaps I was too impatient. And I may have refreshed the page but before long all the devices known to HA Bridge were found by Alexa.
At this point, it was possible to turn on or off any lamp or device with verbal commands.
Universal Plug and Play
Echo Dot finds devices on the network using the Universal Plug and Play (UPnP) protocols. When starting, the ha-bridge
service advertises itself as a UPnP listener.
The Echo Dot, looking for connected devices, can obtain from ha-bridge
its list of all connected devices. It works seamlessly and reasonably quickly if the UPNP service is enabled in the router. By default this capability is enabled on the consumer grade router supplied by my Internet service provider. However, some time ago, I disabled this feature and just now I have lost about a half an hour trying to figure out why Alexa could not find the latest added Wi-Fi switch running Tasmota even though HA Bridge picked it up from Domoticz without fail. Note to myself: do not forget to enable UPNP capability of the router when adding an IoT device.
And once the new devices has been added by Alexa, I must not forget to disable the UPNP capabilities. Just why I disable UPNP would take too long to explain here. Suffice to say that there are many articles on the Web on that very question.
HA Bridge Database Backup
After adding a device to the HA Bridge database, it is probably a good idea to backup the later. This is easily done in the Home
page. The last entry in the page is Bridge Device DB Backup. If a + appears to the right of the title, click to expand the table.
Clicking on the data
directory.
Presumably it would be very simple to restore any backed up database any time later. It would probably be a good idea to save the backup database and the configuration file to another machine.
Conclusion
I am glad to have found a good use for the Orange Pi Zero which is now
enclosed in the very small black plastic cube that I purchased with it. It
sits near the television set, not too far from the Echo
Dot, running two programs: HA Bridge as
outlined above and an IR remote control bridge I wrote in Python called
ir-rem.py
. Now I can turn on or off any IoT device in the house
with verbal commands or with an IR remote. So far it all works very well.
Time will tell how stable this solution is. Among things that could go wrong,
I include a possible decision by Amazon, imitating
Google, to remove local handling of Philips devices. If that happens, the IR remote will still
be available.
Installation of HA Bridge and integration with Alexa was a pleasure. It took much less time to do that than to write it up. It seems pretty clear that the procedure would be quite similar if using other supported open source home automation programs such as OpenHab and Home Assistant or commercial products as well. Thank you very much BWS Systems.
I wish the third generation Echo Dot and the French Canadian version of Alexa had been available sooner.