Today we’re going to have some fun and try using Amazon Alexa to control our light.
You will need:
- Your going to need an Alexa enabled device, I’m using the Echo Dot.
- You’re also going to need a working openHAB 2 installation, see my previous posts.
- Finally you’ll need something to control, In my case a lamp equipped with a Sonoff switch updated with the Tasmota firmware.
This update is going to be quite simple as openHAB has done pretty much all the work for us. There is also a comprehensive guide here.
myopenhab.org
The way openHAB have implemented their Alexa integration is via their cloud hosted service https://myopenhab.org/ this is great for us as most of the hard work is done. Some people may not like the fact we’re using an online service, but hey why are you using Alexa?
First we need to install the openHAB Cloud Connector
- So back to the Paper UI at http://openhabianpi:8080.
- Navigate to Add-ons in the left hand menu, then the MISC tab.
- Find openHAB Cloud Connector in the list and install it.
- Lastly we need to check configuration Configuration>Services>IO>openHAB Cloud.
Now the cloud connector is installed we can create our account over at https://myopenhab.org/.
To register we’re going to need a couple of bits of information the UUID and Secret. Fortunately they are easy to find.
- To get the UUID ssh into your openHABian machine.
- Execute the following command
cat /var/lib/openhab2/uuid
. - Copy the string of characters shown.
- Next get the secret in a similar way
cat /var/lib/openhab2/openhabcloud/secret
. - You can now register for your account at https://myopenhab.org/.
- Annoyingly I needed to reboot in order for my device to show up.
You can now remotely access your openHAB UI.
Items
The Alexa integration uses a tagging syntax to identify which items it can control.
We need to edit our items file: \\OPENHABIANPI\openHAB-share\openhab2-conf\items\sonoff.items, and add the Lighting tag:
Switch My_Light "My Light" <light> (gLight) ["Lighting"] { mqtt=">[mybroker:cmnd/sonoff-mylamp/power:command:*:default], <[mybroker:stat/sonoff-mylamp/POWER:state:default]" }
Alexa
Lastly in you Alexa app navigate to Skills and search for openHAB, and tap Enable. You will be prompted to enter the username and password you just used to create your myopenhab.org account, and authorise the Alexa to use the service.
Alexa will spend a few minutes searching for devices then you’re good to go.
Try saying “Alexa turn on my light”.
Alexa Groups
One last tip. The Alexa app will allow you to create smart home groups. These can be used to associate a number of devices with a specific Echo device.
Whats the point? Well lets create a group for the room we’re in, in my case the study. Then add the Echo Dot located in my study to the group, and also our light.
Now we can control all the lights in a room together. Even better the Echo knows which group it’s part of so can control the lights without you having to define which ones.
Try saying “Alexa turn the lights on”.
Lastly if you change Alexa’s wake word to Computer, you can say “Computer turn the lights on”. It’s almost we’re living Star Trek!
One thought on “Using Alexa and openHAB 2 to Control Your Home”