Select Page
This entry has been published on 2017-03-02 and may be out of date.

Last Updated on 2017-03-02.

[:en]Amazon’s Echo Dot is a great way to control your smart home via voice.

If you are already using a visualization tool like OpenHAB for your smart home, it’s quite easy to get it running.

Because every smart home installation is configured very individually, I will only explain some basics here.

OpenHAB 2

If you are running OpenHAB v1, please upgrade it to v2. Most OH1’s add-ons, bindings etc. can be used with OH2 and the migration process is quite feasible.

Upgrade recommendations:

  • Use a fresh installation for OH2 (new Ubuntu VM, Raspberry Pi etc.)
  • Decide at the beginning which of the 3 configuration types (text-based, Paper UI, Karaf) you would like to use in the future. It could be error-prone to change in the future, because every type saves the configs to other places. I would prefer Paper UI, but the migration doc linked above recommends text-based config.

When you have OH2 ready to run, install the addon “Hue Emulation”:

  • Text-based config: In services/addons.cfg, uncomment the “misc =” line and add “hueemulation”
  • Paper UI: Open Add-ons -> Misc -> Install Hue Emulation

Then open your items file. For testing purposes, simply add “[ “Lighting” ]”  or “[ “Switchable” ]” to an already switch.

Example:

Switch myswitch "Test" <myicon> (mygroup) [ "Switchable" ] { channel=... }

Save the items file, then run the Alexa app, connect it and let it search for devices. You can also do this via voice command, e.g. “Alexa, search for connected devices”, or in German “Alexa, suche nach verbundenen Geräten”. Make sure you have enabled the Pairing mode, e.g. via Paper UI addon config.

Alexa should find a device called “Test”. Try it e.g. by saying “Alexa, switch Test on.”.

Send HTTP commands

Sometimes it can be useful to make Echo Dot call simple HTTP GET commands, especially with a KNX / smart home server, which reside in your local network and you want those commands to be called directly in your LAN, not via cloud/Skill feature etc.

To achieve this, enable the OpenHAB HTTP binding. You might also need the TCP binding.

In your items file, add a simple switch item like:

Switch AlexaRollershutters "Shutters" [ "Switchable" ]

You do not have to add it in your sitemap, so it can stay invisible.

Append to your rules file:

rule "Alexa: Rollershutters"
        when
                Item AlexaRollershutters received command
        then
                //sendHttpGetRequest("http://myserver/myCommandToControlShutters") //if you don't have an existing OH switch for your shutters, you could use this way
                switch(receivedCommand) {
                 case ON : MyRollershutters.sendCommand(DOWN)
                 case OFF : MyRollershutters.sendCommand(UP)
                 }

        end

Add the “Shutters” device to Alexa like described above. You should now be able to control your rollershutters.

For debugging purposes, you can temporarily add the switch AlexaRollershutters to your sitemap to test it manually.

Example with Squeezebox / Logitech Media Server:

sendHttpGetRequest("http://10.1.0.21:9000/status.html?p0=play&player=da%3Ada%3Ada%3Ada%3Ada%3A10")

In this case, the MAC address (ID of the player) is “da:da:da:da:da:10”. The command tells the certain player to start playing.

 

Send SSH commands

This can be one way to execute remote commands on Linux machines, e.g. tell your Raspberry Pi, OpenELEC / LibreELEC / Kodi Mediacenter to power up (see also here).

You can either configure SSH to accept password-less logins (certificates), or the slightly more convenient way would be to install apt-package “sshpass”.

First, connect Putty to your OpenHAB 2 server (in my case Ubuntu 16).

Double-check if the command or script you want to run remotely can be executed by the local openhab user, i.e. check if it has the correct permissions. To test the behavior, run a test command like

ssh root@yourRemoteIp reboot

SSH will ask if it should save the connection hash (important: choose Yes), and then run the reboot command after you have entered the password.

If this works, try the same using sshpass:

sshpass -p yourpassword ssh root@yourRemoteIp reboot

The reboot command should work immediately on the remote machine.

So to integrate this process into OpenHAB and therefore combine it with Alexa, create a simple Switch like in the HTTP example above and create a rule, e.g.:

rule "Alexa: TV on/off"
        when
                Item AlexaTv received command
        then
                executeCommandLine("sshpass -p libreelec ssh [email protected] /storage/.kodi/userdata/onOffHelper.sh &")
        end

Be careful if you have to use quotation marks within your SSH command. You can use e.g. “@@”. For more details, have a look at the OH configuration documents.[:]