Today, I want to talk about one of the coolest features of a Home Automation Project. I am talking about Controlling your Smart Home with your voice. A few years ago, voice control was expensive, unreliable and difficult to implement but this is no longer true thanks to devices like the Amazon Echo or Google Home. Voice control is now affordable and simple for everyone. Stick around for the step by step guide on how to integrate OpenHab and Alexa.
Once you have installed it you will be able to do things like…
- 1# “Alexa, turn on the Kitchen Light”
- 2# “Alexa, turn off the Kitchen Light”
- 3# “Alexa, dim the Kitchen Lights to 30 percent”
- 4# “Alexa, what’s the downstairs temperature?”
- 5# “Alexa, set the downstairs temperature to 22 degrees”
Needless to say that Amazon Echo is just an interface. You need to configure OpenHab items that you can control first. If you want to see an example of things that you could interface with, check How to Control your Smart Lights with the OpenHab Milight.
Required: Amazon Fire TV Stick Review
Components Required
The first thing you need is pretty obvious…You need an Amazon Echo.
The echo family has different members at different price points. They will all cover your needs when it comes to voice control.
The main difference between them, besides the price, is that they are packed with different features.
Amazon Echo Dot
The smallest brother is the Echo Dot. It includes all the capabilities of its bigger brother, the Amazon Echo, for half the price.
What is the catch then?
The speaker on the Echo Dot sucks…
Having said that, the Echo Dot is by far my favorite member of the family:
- It is inexpensive so you can have a few of them to cover several rooms.
- I already have speakers with decent sound quality, don’t need another one…
Amazon Echo (Second Generation)
The Amazon Echo was the first product of the family of Smart Speakers. The brain is the same one as in the Echo Dot, however, the sound quality of the speaker is very good. The Amazon Echo is probably a good choice if you don’t have a good quality speaker yet.
If you have a big apartment/house you can get additional Echo Dots to cover other rooms.
Echo Spot and Echo Show
The Echo Spot and Echo Show are the Echo products that include a screen. I can’t really say much about them as I haven’t had the opportunity to test them. Here you can find a review in case you want to check them out.
Check it out on Amazon in case you want to know more about the product.
OpenHab And Alexa – Step By Step Guide
1. Connect to The OpenHab Cloud.
There are several ways to integrate OpenHab and Alexa.
Today, I will only focus on leveraging the OpenHab Cloud for this since,in my opinion, is the easiest way.
If your OpenHab instance isn’t connected to the OpenHab Cloud yet, check How to Use the OpenHab Cloud Connector. It will only take you a few minutes.
If you have already done this, the longest part of the tutorial is over 🙂
2. Install the OpenHab Alexa Skill
1. Go to http://alexa.amazon.com and select Skills on the left sidebar.
2. Look for the OpenHab Skill and Enable it.
3. It will take you to the OpenHab Cloud page to provide your cloud credentials. You should have them from the first part of the tutorial.
3. Configure Your Items
OpenHab and Alexa are already able to communicate with each other.
Does it mean we are done?
Not quite yet…
Although Alexa is able to fetch your items it doesn’t understand what they are yet. In order to solve that problem, you need to use tags.
The OpenHab Skill for Alexa uses the same syntax as HomeKit binding. You don’t need to but in case you are curious, here is some extra info about the HomeKit Binding.
So…What tags do OpenHab and Alexa support?
Lights and Switches:
- Lighting: You can use this tag for lightbulbs, dimmable lights and things like that. Items with this tag will give you the ability to turn lights ON and OFF, dim them and change the color.
- Switchable: This tag is pretty self-explanatory. You can use it for things that can have a binary state, ON or OFF.
Switch KitchenLights "Kitchen Lights" <light> (gKitchen) [ "Lighting" ]
Dimmer BedroomLights "Bedroom Lights" <light> (gBedroom) [ "Lighting" ]
Dimmer CoffeeMachine "Coffee Machine" <coffee> (gKitchen) [ "Switchable" ]
Thermostat:
Alexa sees our thermostat as a group with different items associated with it. Here is how you declare a thermostat so Alexa can communicate with it.
First of all, you need a Group that will represent your thermostat as a whole. The group will have to be tagged as [ "Thermostat" ]
Inside of the group thermostat you need at least 3 elements with the following tags.
- CurrentTemperature: An accessory that provides a single read-only temperature value. The units default to celsius but can be overridden globally using the useFahrenheitTemperature global property
- homekit:HeatingCoolingMode: Indicates the current mode of the device: OFF, AUTO, HEAT, COOL. The string’s value must match those defined in the thermostat*Mode properties. This is a homekit-specific term and therefore the tags needs to be prefixed with “homekit:”
- TargetTemperature: A target temperature that will engage the thermostat’s heating and cooling actions as necessary, depending on the heatingCoolingMode
Here is how the definition of a thermostat looks like:
1 2 3 4 |
Group gDownstairsThermostat "Downstairs Thermostat" (gFF) [ "Thermostat" ] Number DownstairsThermostatCurrentTemp "Downstairs Thermostat Current Temperature" (gDownstairsThermostat) [ "CurrentTemperature" ] Number DownstairsThermostatTargetTemperature "Downstairs Thermostat Target Temperature" (gDownstairsThermostat) [ "TargetTemperature" ] String DownstairsThermostatHeatingCoolingMode "Downstairs Thermostat Heating/Cooling Mode" (gDownstairsThermostat) [ "homekit:HeatingCoolingMode" ] |
Adding Tags to your Items
If your items are all defined in the items file, you are good to go. You can go straight to the step 4 if you have already modified the *.items files.
Chances are that you have also defined items using PaperUI. if that is the case, there is a bit more work to do.
PaperUI doesn’t currently support tagging which means that we have to use the RestAPI to tag the items. No worries, it is a lot simpler than it sounds.
Adding Tags using the OpenHab RESTApi
The RestApi is an awesome tool and it deserves its own post. For this tutorial though, I just want to use it in the most basic way.
We are going to use a linux command called curl.
- SSH into your Raspberry Pi
- Execute the following command to add the tag to an item
1 |
curl -X PUT --header "Content-Type: application/json" --header "Accept: application/json" "http://192.168.1.110:8080/rest/items/{Item Name}/tags/{Tag Name}" |
There are two parameters in the command that you need to edit before executing it.
- Item Name: The name of the item for which you want to add the tag.
- Tag Name: The name of the tag that you want to add. For Example, Lighting if it is a light bulb.
Remeber that you need to execute this command for every item that you want Alexa to control.
If you made it until here you are already out of the woods. This was the only part of the tutorial that could be a bit tricky. If you don’t get it right no worries, post your questions in the comments and I will try to help you.
4. Items Discovery with the OpenHab Alexa Skill
If you have already tagged all your items you are ready for the last step.
1. Go to http://alexa.amazon.com and click on the Smart Home section, left sidebar.
2. Click on Devices.
3. Alexa will take you to an empty screen. Click on the button Discover, bottom right.
4. After a few seconds, the items that you tagged in the step 3 will start showing up on the list.
This is it! OpenHab and Alexa are connected.
You just got yourself a voice control system for your Home Automation. If you found the post useful please post it in the comments or share it on social media, it helps to get the word out there.
Does openhab sever and alexa need to be in same network?. Will alexa discover openhab if not in same network?..I was doing this integration from different network.Alexa is at home and openhab server is with me in the office.Alexa is not able to discover openhab.
Hi Rakesh,
If you are using the openHAB cloud it shouldn’t need to stay in the same network. Can you authenticate from the alexa skill?
Great post. Was curious if you knew or could explain the Alexa bindings that exist on the OpenHAB site and what they are used for? Posts like yours and others talk about the items and labeling them and how to tie them to Alexa thru the skill and OpenHAB skill but never talk about these bindings or why/if you need them. I struggle sometimes to visualize the communication path for when you speak to Alexa how it all talks and what is actually doing what. Like when you say “Alexa, turn on the kitchen light”, who is doing that? Alexa or OpenHAB?
Thanks.
JR
Hi JR,
I can add some info to the post but just to answer your question, it is actually both, Alexa and openHAB.
When you talk to Alexa, the Amazon Cloud processes the speech and tries to understand it. Once it knows that you want to turn ON a light, an Amazon skill is invoked (the openHAB skill) and communicate with the openHAB instance (through the openHAB cloud) to do a simple sendCommand.
Bottom line,
1. Speech recognition is done in the Amazon Cloud
2. The openHAB alexa skill connects translates the command into something openHAB can understand and send the command to the command through the cloud.
3. openHAB does his thing and turn on the light.