Controlling A PLC With Amazon Alexa

I recently purchased an Amazon Echo which is a hands-free speaker you control with your voice. Amazon Echo connects to the Alexa Voice Service to play music, provide information, news, sports scores, weather, and more—instantly.

It’s the ‘more’ this article will explore. Unlike other services, Alexa exposes itself via the Alexa Skills Kit

According to Amazon

“The Alexa Skills Kit is a collection of self-service APIs, tools, documentation and code samples that make it fast and easy for you to add skills to Alexa. You can also use the Smart Home Skill API, a new addition to the Alexa Skills Kit, to easily teach Alexa how to control your cloud-controlled lighting and thermostat devices.”

This article serves as an architectural pattern on how to interface Amazon Alexa with any PLC. I will provide an example of using an Amazon Echo to control a function of my PLC which is my heating. I have a regular multi zone gas ducted heating system which I drive via my PLC. This post assumes the gas ducted heating system is already being driven by the PLC and the theory can be transposed to any device controlled by the PLC. Details on how I built my thermostats, relays and logic can be found in this blog post – Interfacing Zoned Gas Heating with an Automation System (Homevision Pro)

Step 1: How Do I Interface Alexa To My PLC?
The first step I took was to look for an existing Alexa Skill on the odd chance their was a bridge. The skills at the time of writing focus on domestic products and not industrial PLC’s so I need a way to bridge Alexa with my PLC. After hitting a combination of Google and forums I am came across HA Bridge by BWS Systems. BWS Systems describe HA Bridge as follows

“HA Bridge allows connectivity from the Amazon Echo or other automation controllers to various Home Automation systems. There are features that allow connections to any http/https/TCP/UDP or scripts or programs on the host machine.”

Sounds simple enough and really it was. It emulates a Phillips Lux light for every device you add. The application can be downloaded from GitHub and comprises of a Java archive that requires JRE 8.

Step 2: Invoking HA Bridge
I will not delve on how to install JRE but will assume this is installed and working.
Worth noting is the archive includes a .DOCKERFILE so this could be ran on Docker or a service such as Amazon EC2 Container Service

To start HA Bridge simply execute the jar file with JRE.
Screen Shot 2016-08-04 at 8.26.23 PM
Once invoked the bridge will JettySparkServer on TCP port 8080
Screen Shot 2016-08-04 at 8.26.55 PM

Step 3: Configuring HA Bridge
HA Bridge is very simple, it’s not a complex offering nor does it need to be. The premise of the bridge is two fold

  1. Expose devices as a Phillips Lux light for devices such as the Amazon Echo that natively communicate to Phillips Lux lights
  2. Broker and pass calls to a HTTP(s)/TCP/UDP endpoint

Let’s add a device by browsing to (or your machines IP)
Screen Shot 2016-08-04 at 8.31.19 PM

Next lets configure the settings, this will be dependent on your PLC or device you are communicating to
Screen Shot 2016-08-04 at 8.32.49 PM

So what I have configured is as follows

  1. On URL : A URL to turn my heater ON. I do this by setting a variable to 1
  2. Off URL : A URL to turn my heater OFF. I do this by setting a variable to 0
  3. Dim URL : A URL to turn adjust the zone’s temperature. This is dynamic and I pass in an intensity percent.

Hit ‘Update Bridge Device’ to save.

Step 4: Test HA Bridge
HA Bridge has a test function that will allow you to test ON/OFF/DIM(either raw or percentage). Before we get to linking the Echo to HA Bridge and talking to Alexa lets test that what we have done actually works.

Screen Shot 2016-08-04 at 8.46.35 PM

After hitting ‘Test ON’ I can see the PLC has received a VARUPDATE and the value for the variable is now 1.

Screen Shot 2016-08-04 at 8.48.50 PMNetIO registers this instantly as seen on the phone.

Step 5: Discover New Devices On The Echo
Device discovery can be completed multiple ways. The easiest way is to just ask Alexa.

“Alexa, Discover My Devices”

If there i an issue you can go to “Menu / Settings / Connected Home’ at and run through the wizard.

Step 6: What Should I Say To Alexa?
There are many ways to invoke ON, OFF and DIM commands with Alexa. Below is a handy table which can be found in the HA Bridge Documentation on GitHub

To do this… Say this…
ON Commands
Alexa, turn on <Device Name>
Alexa, start <Device Name>
Alexa, unlock <Device Name>
Alexa, open <Device Name>
Alexa, boot up <Device Name>
Alexa, run <Device Name>
Alexa, arm <Device Name>
OFF Commands
Alexa, turn off <Device Name>
Alexa, stop <Device Name> (this one is tricky to get right)
Alexa, stop running <Device Name> (also very tricky)
Alexa, lock <Device Name>
Alexa, close <Device Name>
Alexa, shutdown <Device Name>
Alexa, shut <Device Name>
Alexa, disarm <Device Name>
DIM Commands
Alexa, brighten <Device Name> to <Position>
Alexa, dim <Device Name> to <Position>
Alexa, brighten <Device Name>
Alexa, dim <Device Name>
Alexa, raise <Device Name> to <Position>
Alexa, lower <Device Name> to <Position>
Alexa, set <Device Name> to <Position>
Alexa, turn up <Device Name> to <Position>
Alexa, turn down <Device Name> to <Position>

Step 7: Lets Test It
We are now going to test turning on the heater, setting the temperature and turning it off and will use the following commands

“Alexa, Turn On Upstairs Heater
Alexa, Set Upstairs Heater To 21
Alexa, Turn Off Upstairs Heater”

Conclusion & Disclaimer
Amazon Alexa can be used to control almost anything and products like BWS Systems HA Bridge make connecting disparate systems possible.

I work for @AWSCloud but opinions expressed are my own

Shane Baldacchino


Leave a Comment