Why would you try to control you home automation with your voice? Because its possible:) With Alexa's price tag falling below USD 100, the time has come to get it connected with the PLC.
I used the latest Amazon Echo (2) to connect it to my PLC-base home automation system via a small Raspberry Pi server. The first step involved installing pimatic (at this moment it is the only system I found that works with the new Echo). The pimatic platform can itself be used to control home automation system based on RPi. With some scripting it can be used as an interface to the PLC. I prepared two pimatic plugins:
- pimatic-wago, which adds new devices to the pimatic platform,
- wago-common, as an universal module for interfacing with a PLC.
What are the necessary steps?
{
"plugin": "echo",
"port": 80,
"active": true
}
{
"plugin": "wago",
"addressPLC": "192.XXX.XXX.XXX,
"visuFile": "visualization_name",
"active": true
}
The first time you run pimatic, it downloads all the referenced plugins, what means that it will take a lot of time. I suggest you read the messages displayed on the screen to check if the plugins are installed in their latest versions. If pimatic installs an outdated file of my plugin (pimatic-wago), you can do it manually running 'npm install pimatic-wago' in the pimatic-xxx directory.
Once pimatic is ready you can check if it works by opening a web browser, entering the IP of your RPi (the IP can be checked with 'ifconfig') and adding the configured port, for example: 192.168.1.200:8011.
Once you log in to pimatic, go to Devices -> Add device. In the Class field choose WagoSwitch and fill:
In the "Echo" part, which is needed by Alexa, you need to fill:
After you click 'Save' you should leave the menu 'Devices' by clicking the 'Back' button. To add the new device to a given scree, click the gearbox in the top-right corner, then "Add new item", and click the line with the new device we have just added. Here is how an example of a screen can look like:
Now you should check if the new device we have created is discovered by the Echo. Log in to alexa.amazon.com, click "Smart Home", click "Devices" and "Discover". At the same time on the pimatic site click "Devices", and "Discover devices" at the top-right corner. After 20 seconds Echo should finish searching and under Smart Home -> Devices you should see the discovered elements:
If your device is on the list you are ready to test the voice commands like: "Alexa, turn on/off XXX", meaning, for example: "Alexa, turn on dining room". If all goes well, Alexa will reply "OK", and the light will turn on :)
* * *
As a reminder - a few words about how to prepare your PLC in CoDeSys for such a form of communication:
The first step is to create a new visualization (for example named "example"). Then add all your elements, which should be available to pimatic (or any other external software):
Your new visualization should be made available via www (right click on the name of the visualization -> Object Properties -> checkbox near Use as -> Web-Visualization)
The visualization should be zipped/packed: go to Resources tab -> Target Settings -> Visualization tab -> checkbox at "Compression".
Once you program is compiled (go to on-line mode) the new file (example_xml.zip) will be placed in the "plc" directory at your PLC:
This file will be downloaded by the plugin wago-common, then extracted and analyzed. Each variable (for example: PLC_PRG.Light1_VIS) will be assigned the address in the memory (for example 4,101240,2,1), which is later used for communication with the PLC.