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


Reading Exetel Usage Data With PowerShell

The de facto standard for control in house is our PLC, things mainly happen autonomously, but when things don’t happen magically the tool of choice is a smart phone running NetIO.

NetIO is a multi platform smartphone application, a generic remote controller for almost everything. It simply sends and reads strings over a network socket.

I have a NetIO server integrating with my PLC (Homevision Pro) written in TCL/TK and I write jSON code for our smart phones to leverage my PLC. This allows us to control everything the PLC has on offer. The PLC talks to everything in my house from heating and cooling, security, TCP/IP devices, power, lights, audio, and so on all in a consistent manner.

The other day I thought, wouldn’t it be great if I had a page showing all of my bills and how much I have used in real time, most places have API’s. So here goes my first example trying to read my usage data from Exetel.


Step 1: How Do I Talk to Exetel?
After hitting Google I am came across a page on Whirlpool that contained exactly what I needed.,password’

Sounds simple enough and really it is. Putting this in your browser returns malformed XML, which isn’t great as an XML parser can’t be used but there are ways.

Step 2: Manipulating The Data
My language of choice these days is PowerShell so that is what we will write this in.

Dealing with Exetel  (and most other API’s) usually throws in a few curve-balls and here is what I found when writing my code.

  1. Malformed XML, the output is malformed and because of this I can’t use PowerShells’ built in XML parser. We will need to use regular expressions to pattern match and this is what I have done.
  2. It’s not a total, when I login to Exetel’s members page I get a total amount of data used but when I download XML I receive it split in to off-peak / peak and upload / download, we will need to combine

Step 3: My Code
My code for this solution can be found here. So after executing if you are wondering how did he get this to his PLC I have removed the function to post the results back to my PLC because unless you have exactly the same PLC I do it will be useless and cause compilation failure


Execution will return a variable called $TrafficTotal which will be the sum of downloads, uploads, peak and off-peak in GB that is rounded to whole integer. What you do with this is up to you

Step 4: Displaying in NetIO
The cherry on the top. My solution updates my PLC with this variable data and I use NetIO to read this and display it as a gauge. The max value on the gauge is my internet plan’s maximum consumption
















Shane Baldacchino

Installation and Integration of a Hydreon RG-11 Optical Rain Sensor with a PLC

This is an article I have been meaning to write for some time. I guess I haven’t as this sensor has been something that has just worked out of the box and hasn’t skipped a beat in almost 2 years.

I have written about integration between OpenSprinklerand Homevision Pro in this article. Just a refresh, OpenSprinkler is a commercial irrigation controller based on an Arduino platform. It is controllable by a web-interface or a HTTP based API.

It is pretty good and I think I would rate it an 8/10, its the best controller on the market for the modern age for stand alone control but there are limitations. Do I just want to water based on a schedule (No). Do I want to water when its raining (Maybe).

The problem with OpenSprinkler is that it has no context of how much rain has fallen. If we receive 50mm of rain yesterday and its sunny today do we need to irrigate? Here lies the problem and hence why I utilise a Hyrdeon RG-11 in my house.

The task this sensor performs is to measure rain-fall and the whole process looks something like this

Hydreon RG11 –> PLC (HomeVision Pro) Input Port –> PLC Logic –> OpenSprinkler

You can buy cheaper sensors but the reason why I bought the Hydreon RG-11 is simple. Reliability. It has no moving parts and if my automation journey has taught me anything it is that things with moving parts will eventually break. The Hydreon RG-11 Rain Gauge senses water hitting its outside surface using beams of infrared light. It uses the same sensing principle used in millions of automotive rain sensing windshield wiper controls.

Being optical (and not mechanical, chemical, or conductive) it’s far more rugged, sensitive and reliable than other offerings. Leaves cant clog its mechanism and it just works. In the last 2 years I have no experienced any false positives


Enough about the sensor, lets get started

Bill of Materials
– 1 x Hyrdeon RG-11 ($99AUD)
– 1 x 12VDC 500ma PSU ($0AUD – Leverage existing PLC PSU)
– 1 x Galvanised L Bracket ($8AUD)
– 1 x Quad Core Cable Between Hyrdeon RG-11 And PLC ($15AUD)

Total Cost = $122AUD

Tools used
– Pliers
– Screw Driver
– Electric Drill

Step 1: Configure the Hyrdeon RG-11
The device includes a series of dip switches that allows it to be set up for the mode of operation that best matches the application. The output is a NO/NC which can interpreted by your application. Depending on your mode selected the output will vary


Tipping Bucket – Replace your tipping bucket with a low maintenance alternative
It’s Raining – Close a skylight at the first sign of rain, and open it when it stops raining
Condensation Sensing – In this mode, the Rain Gauge continuously monitors the clarity of the sensing surface.
Wiper control – This mode will control the wipers from off through intermittent and steady-slow speeds.
Irrigation Control – This mode will measure both rain accumulation and rain intensity.
Drop Detection – Use this mode if you want to do your own external data interpretation.

So for my use case given I want all of the logic to be controlled by the Homevision Pro I have gone for “Drop Detection” with the NO/NC pulsing every time 1mm of rain is detected.

Step 2: Mount The Device
It should go without saying but this device needs to be mounted in a position that isn’t susceptible to shade by buildings. I have chosen to mount this off my garage using a galvanised L bracket to distant it even further from the house.



Step 3: Connect It All Up
Following the instruction push your cable through the cable gland, wire up your power (get the right polarity) and PLC input settings, validate your dip switches and grease the O-ring before sealing it all up. Connect the PLC end, enable your port if you need to and away you go.



Step 4: Test and Add Your Logic
That’s it, simple. You now need to add your logic. My logic is to
– track the total rain fall (mm) stored in a variable
– roll up to a per hour (mm) stored in a variable
– graph rainfall by the minute using the Google Graph API
– display data via NetIO on a phone (see below)
– Depending on the maximum temperature of the day subtract 3-5mm from total rainfall, when rainfall is at 0mm fire OpenSprinkler early in the morning and again at night if outside temp was greater than 25C and send push notification to state what happened.









Shane Baldacchino

Cooling Home Audio with a PLC using X10 and Dallas DS18S20

WARNING : Electricity can be lethal, this work should only be attempted by a licensed electrician

We recently purchased a new TV unit. High on my priorities was ventilation. I own two NAD C272 stereo power amplifiers (one to power inside the house and another to power my shed and garage). I really like these devices, they are serious no nonsense premium power amps and have the same effect on your ears as moving from crop sensor based D-SLR to a full frame. The bad news is earlier revisions of this power amplifier lacked thermal cut out, I found out the hard way. Boom, look at that cap.

Even though this new entertainment unit is quite open, the NAD is 190mm high and only fits in by 17mm, this surely wasn’t going to cut it and with NAD posting a warning on their website I didn’t want to test my warranty, again.
A solution needed to be found.

My solution was to leverage my PLC to drive fans which I have mounted in the back of my cabinet.

Breakdown of parts (for one Power Amplifer)
– 2 : 119mmx119mmx39mm 240V fans (2 per power amp)
– 1 : X10 Lighting module with dimming functionality, I used an LW12
– 1 : Electrical junction box
– 1 : Patch cable
– 1 : Dallas DS18S20
– 1 : Wall plate for RJ45
– 1 : Electrical cord terminated to your countries wall sockets
– 1 : A length of heat shrink
– 1 : Various screws

Tools used
– Soldering Iron
– Pliers
– Screw Driver
– Device to drive X10 modules and read Dallas thermometer, I am using a HVPRO
– Hole-saw to match your fan diameter
– Drill to drive hole-saw
– Compass & Pencil

Step 1: Wire in LW12 to cord
The LW12 will be driving the fans. As high voltage is being used, for safety purposes this is enclosed in an electrical junction box. The electrical donor cord was cut in two. The first segment is used to go from the wall socket to the LW12, the second segment is used from the LW12 to the fans. The connections are as follows.

Cord Segment 1 : Brown (active) –> Red (active input)
Cord Segment 1 : Blue (neutral) –> Black (shared neutral)
Cord Segment 2 : Brown (active) –> Brown (active output)
Cord Segment 2 : Blue (neutral) –> Black (shared neutral)

Step 2: Create the thermometer
In order to deem when we need the fans to turn on and their appropriate speed (more thinking sound) we must first know what the temperature is. I am using a Dallas DS18S20 thermometer to achieve this.
A few things need to occur here, as these thermometers all connect to the same bus we must know the address of the device. Unfortunately this is not provided and the only way to read this 64-bit address with my PLC (Homevision Pro) is to disconnect all other sensors from the bus and just have this unit connected. So that is what we have done. Maybe yours is better?

In the above we can see the address of this device is, save this to a new variable. In this case it is my 4th sensor and given we start counting from 0, this is digital temp sensor number 3 in my system.

Once we have the address we can connect everything back up (dont forget to test if you have broken anything) and solder the DS18S20 to the end of a patch lead. I decided to use brown for negative, orange for 5V DC and blue for data.

Add heat shrink and enclose in container. I used a plastic container from a cutting tool and covered this in heat shrink and slid the DS18S20 and secured with two cable ties. These are really not needed as the fit should be snug

Step 3: Establish the link between the Dallas DS18S20 and HVPRO

I now needed to get the HVPRO talking to the thermometer. For all of my other sensors I use a 4 core multi strand cable but I didn’t think of this earlier and I have a double storey house. My solution was to use the existing Cat 6 cable I left beind my wall. I luckily have 4 ethernet cables behind this wall unit. 2 are used for data, 1 is used for RS232 and the 4th is now used for thermo.

The DS18S20 sensor can now be connected and placed on top of the NAD C272.

We now need to build our X10 driven fans.

Step 4: Link the LW12 to the fans
We need to link the LW12 to the fan. As a test I have connected the LW12 to a fan in my garage to test the variable speeds. Please note I did not insulate connections for this test. This can be very dangerous and extreme caution should be taken during these steps. The LW12 is speed limiting the fans which are an inductive load via a resistive coil.

Step 5: Wire the two fans and LW12 together
After testing in Step 4 it is time to make things a little bit more permanent. I used heatshrink to double insulate the wires, given the voltage / amperage combination is fatal I dont wish to take chances.

Step 6: Putting it all together – mounting the fans
It is now time to mount the fans. I would suggest using a hole saw to get a nice round cut. I had used a 130mm hole saw to mount the fans. Take your time, measure twice. The fans are designed to suck air from behind and push over the power amplifer

Measure twice, cut once. My pants are awesome.

130mm hole saw

First fan mounted

Both fans mounted, a few cable ties used to take load of any of the connections

Both fans mounted, very neat fit

Step 7: Add logic
Everything is connected but the PLC doesn’t know what to do. We better help it so here is some code to turn to the fans on (including a fail safe). It will need modification to log more data. Integer values are in degrees Fahrenheit + 50.

Step 8: Test
After about 15 minutes of hard load on the power amp the temperature has risen from the ambient 16c to 32c, you can see in the graph the fans flick on for around 1 minute, reduce the temperature and then power off. I have found I am unable to get the fans to spin faster than the first defined threshold

Given the data from thermostat is stored in a variable in the PLC we can keep track and model this in our NetIO front end which is displayable on phones / tablets that we use in our family


All in all, this solution has solved my problem and over the last two years I haven’t had any thermal related issues. The fan’s do their job when seldom needed and if I can’t poll the thermostats the fail safe logic cuts the power to the units.

Shane Baldacchino