Amazon Echo Skill for OpenHAB available!

It will! It will support both a my.opehab hosted model as an “official” published skill, but also has a mode to run it your self using a username/password option (or however you want to do it I guess) . The code will be released as open source under the main github repo very soon!

2 Likes

I am using the semi direct approach : Semi-direct (i.e. Echo -> AWS ASK -> NodeJS/Express -> HA)

Followed all the steps. Created a self signed SSL certificate and uploaded/copied the certificate to Amazon ASK ssl section.

I
am able to access the Alexa tester Page using a web browser by visiting
this URL : https://customsite.ddns.net:30000/api/alexa-ha

Running
a test intent shows up relevant success message on the Node server
console. Which means the backend logic, port forwarding/router config
everything works just fine.

Now I try to run the skill
by using the Test section of Amazon ASK and using Echo device. In both
case the request is not going through. My endpoint on ASK config page is
pointed correctly to : https://customsite.ddns.net:30000/api/alexa-ha

http://alexa.amazon.com/spa/index.html#cards :

Error : A connection could not be established to Resource [https://customsite.ddns.net:30000/api/alexa-ha], Type [HTTP]

In Test section of my Amazon ASK skill dashboard:

Error: The remote endpoint could not be called, or the response it returned was invalid.

The
only thing I could think of is may be there is a problem with
the ssl certificate but I rechecked and the I followed all the right
steps to create the self signed certificate using this link
:https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/testing-an-alexa-skill#h2_sslcert

Can you please suggest what else could be the issue?

Hi,
It seems you are trying to use port 30000. Unfortunately Amazon requires the standard HTTPS port of 443 for the endpoint. If that is already in use, you may have to proxy the request through the existing webserver.

Also from recollection the Amazon ASK test page for the Skill did not work for me, even though everything works great on the Echo.

Hope this helps!
.

All - in case you aren’t already aware a few mobile apps have been released which mimic the Amazon Echo:

Android - Alexa Listens
IOS - Lexi

With Alexa Listens, I was able to get both Alexa HA and our forthcoming official OpenHAB Smart Home skill to work with it right out of the box! Eeexcellent :slight_smile:

Best regards,
.

1 Like

Thanks Mike, I got the issue resolved. I needed to remove port 30000 from
the ASK endpoint URL as ASK only works for 443 like you mentioned. The rest
of port forwarding was already in place.

Now I have achieved the overall functionality but the actual Skill part. I
am trying to turn on/off an LED connected to gpio pin on my Raspberry. I am
able to switch the LED on and Off from OpenHab (web browser url) so that
part is also working.

The thing that is missing is how does OpenHab and Alexa-HA maps to each
other at the Skill Level. Wish there was a “Hello Worl” kind of example
that explains how everything (Alexa-HA & OpenHab) is linked together. I am
new to OpenHab so this might be a very n00b question. I don’t see any place
where I can tell Alexa-HA what IP my OpenHab server has. I tweaked the
config.js so that basic utterances with static response like “Help” and
"Stop" works but as soon as the Skill asks for “Turn on the light”, I get
"Switching On your light from initial state undefined". I dig into the
script and see that getState() is trying to access a URL server +
"/rest/items" + itemName + “/state”

Where is this /rest/item state defined? I do have the correct item
configuration config.item = {‘light’ : ‘LED’} but no place to mention the
state values or how everything is talking to each other. Please help.

@Vikas_Singh,

The OpenHAB connection string is defined here. Note the variables above it are all included in the string. If you haven’t already, I would definitely use SSL and setup a username/password for authentication for security. If you are NOT using user auth, then you may need to amend this line to something like this to exclude the username & password:

config.HA_server = config.HA_protocol + '://' + config.HA_host + ':' + config.HA_port;

In the example config, note these are dealing with itemNames as defined in your OpenHab item file(s). If you continue to experience problems, I would uncomment the debugging lines here, and maybe even copy the console.log() messages into the getState() function above it. Then restart NodeJS, tail the logs and you should have more info then you would ever want regarding whats going on ‘under the hood’.

This is all defined in config.js. The ‘/state’ is an OpenHAB standard for accessing values from the OpenHAB REST endpoint. You don’t need to change this, but rather fix your connection strings and maybe copy & test the URLs from the debug logging with your local browser. If you can’t reach the OpenHAB REST API with the URL Alexa HA is using, then something in config.js is likely off!

I realize the setup for this is quite complex at the moment, and we have a lot of planned improvements to make this much easier to get started!

Thanks Mike. I moved one step further. Spent some time understanding how
the code is working (config.js, helper.js, index.js etc.).

Now when I ask my Echo device to “Switch on the light” I can see the
connection handshake and the intent running with debugging message.

Error now is 404 when a POST message is attempted (/rest/items/…). I
checked the log and this is the main reason : "authorizationError:
“UNABLE_TO_VERIFY_LEAF_SIGNATURE”

I google’s the error a bit and it seems since the ssl is self signed so
Node.js / Java is not very happy. One of the code level solution in
stackoverflow says :
set this process.env[‘NODE_TLS_REJECT_UNAUTHORIZED’] = ‘0’;

I am not sure if this is the exact problem and if yes then how to fix it?

Interesting, this should have been fixed with this Pull Request. Here are some other suggestions to try and resolve. we already have ‘rejectUnauthorized: false’ set in the AgentOptions… Are you using the 4.x version of NodeJS?

You may also want to try creating a new self-signed SSL cert for OpenHAB, or temporarily disable SSL for both OpenHAB server and Alexa HA to quickly test.

Another thought, while I don’t believe this will have an effect on SSL negotiation you might want to appropriately set the following options in your openhab.cfg, depending on your network configuration:

security:option=EXTERNAL
security:netmask=‘192.168.1.0/24’

Mike,

I tried updating the openhab.cfg with your settings but no luck. Spent
whole day but still stuck.

Alexa-HA is working fine independently as the intents are able to trigger
the relevant functions in the code.
OpenHab is working independently (as I am able to switch the led pins on of
using the url : http://localhost:8080/opemhab.app?sitemap=sitemapLED)

My router has port forwarded 30000 & 443 to internal port 30000. So this
seems fine too.

What I am not able to get is :

  1. Why is Alexa-HA not able to communicate with OpenHab and gives an TLS
    error for any GET/POST request (could be something related to selfsigned
    SSL)

  2. Even if I try to browse this url : http://localhost:8080/rest/items, I
    get a *HTTP ERROR 404 . Problem accessing /rest. Reason : ProxyServlet:
    /rest. *Shouldnt this give a list of items on the browser page as this is
    purely OpenHab and nothing to do with Alexa-HA or SSL?

  3. How does Alexa-HA know if my OpenHab is running on the same machine or a
    different IP. I couldnt figure out a config setting to set that.

This is the last piece of the puzzle that I am desperately in need to
figure out. Please suggest what all steps I could try.

Point 2 is resolved. https://localhost:8443/rest/items does give the list
of items in XML format. Initially my OpenHab service was a bit patchy and
was restarting very frequently hence the previous error.

However the “Unable_to_verify_leaf_signature” error remains when I am using
echo device to run custom intents i.e. Alexa-HA not able to talk to OpenHab
yet.

My NodeJS version = v4.2.6

I am using the default OpenHab ssl certificate and a self signed SSL
certificate for Alexa-HA Server (also uploaded to Amazon ASK). Currently
both OH & HA servers are on the same box (for testing purposes only)

Please let me know if you need any other info to help me fix this issue.

UGH! Sorry to hear that Vikas… We will get this sorted out.

30000 is not needed for communication, I would definitely block that port for security, but that wouldn’t effect your current problem… Regarding your line items above:

1 - SSL handshaking issue it seems, based your description/symptoms. :frowning:
2 - yes, and glad you got it sorted. Never ran into that issue before…
3 - config.js defines this, as mentioned above here. The variable defined as config.HA_host in config.js, and reused throughout the Alexa HA code. Please confirm and share the exact URLs Alexa HA is using (debug logging) and confirm if they work for you as well.

My immediate thoughts to fix this include:

  • Upgrade to NodeJS v4.4.x, the latest version. It might have more recent SSL CA’s or other changes considering the numerous SSL exploits discovered in recent past.
  • Are you using Oracle (Sun) Java or OpenJDK on your OpenHAB server? I have Oracle Java JDK v1.8 over here… Shouldn’t matter, but unsure of any differences in the server-side SSL handling…
  • If the above fails, try re-creating your OpenHAB self signed SSL cert using [these]
    (Create openHAB (Jetty) keystore from OpenSSL certificate/key pair · GitHub) instructions. But that is a last resort; really shouldn’t be necessary.
  • You are using OpenHAB Server 1.8.x, and not 2.x, right? Alexa HA only supports 1.8.x at the moment!

My guess is upgrading NodeJS and/or Java will fix this for you. For further reference, my OS is Ubuntu 14.04 LTS.

This has been resolved. The problem was in my understanding of how the
Alexa-HA control was being transferred / code flow amongst various JS
files. The config.js has hint comments saying server = HA server and port =
HA port. I was under the impression that HA mean Alexa-HA and not OpenHab.
Eventually figured out that config.js is connecting Alexa-HA server with
the OpenHab server rather than the external world/DDNS to Alexa-HA. So the
port shouldn’t be 30000 but 8443 on which the OpenHab Https is running.

So now every thing is working fine. I can talk to my echo device to switch
on the LED connected to one of the GPIO pins. Thanks for the help Mike :).

The demonizing auto-starting Alexa-HA server on boot is yet to happen. I
tried these steps :

sudo npm install pm2 -g
sudo env PATH=$PATH:/usr/local/bin pm2 startup -u alexa

  • You may need to change the home path to your alexa user by editing the
    start script:

sudo nano /etc/init.d/pm2-init.sh

  • Find the PM2_HOME export and set it to use our ‘alexa’ users
    directory, like so:

export PM2_HOME="/home/alexa/.pm2"

  • Start Alexa-HA with PM2:

sudo su alexa
cd ~/node_modules/alexa-app-server/api/
pm2 start server.js

but once I reboot my device (Alexa-HA server), the server doesn’t
start automatically. My /etc/init.d/pm2-init.sh is proper (I changed
PM2_HOME to alexa)
. Seems the default login user is not able to start the script for
another user(alexa) from init.d…or may be it’s some other issue.

What could I be missing here?

@Vikas_Singh - great news!

Regarding pm2, I would look at your syslog and/or the pm2 logs (i.e. tail -f /home/alexa/.pm2/logs/*.log) to look for any errors upon boot which may help to identify the problem. Also, double check all vital directory permissions are correct and owned by the alexa user. Finally, according to this, you may need to:

1) start all your processes, 2) create the startup script, and 3) run pm2 save

Step #3 is not in the Alexa HA documentation - please let me know if that does the trick! :sunglasses:

Hi Mike,

Since now my whole setup (Alexa-HA + OpenHab + Echo Device) works fine, its
time to dig deep and get some real stuff done.

I have a script (myScript.py) on my OpenHab server (config/scripts folder).
I want to run this script via a custom command given to the Echo device.

I have created the proper utterances/Slots etc on the ASK dashboard. The
command can now reach my custom Intent in the index.js file of Alexa-HA
server.

What would be the next step (logic inside my custom intent function) so
that I can trigger the python script on my OpenHab server?

I did some google and found something like : Create an Item + Rule that
accepts the name of the python script via command line and executes the
script :

set up a String item like

String CallScript

and a rule

rule Callwhen
Item CallScript received commandthen
callScript(receivedCommand.toString)end

and then at the console

osgi> openhab send CallScript myScript

This is a console command based example so not sure if this is relevant to
me or am I going in the wrong direction.

Please let me know what would be the right way to trigger my python script
and how to achieve that in the custom intent function of Alexa-HA index.js
file?

Hey @Vikas_Singh

Yes, use a rule to trigger a virtual switch, and the exec binding to call your custom scripts.

Thanks Mike. The virtual Switch exec binding mechanism works but my doubt
is, is it the right / idea way to implement such a functionality?

Suppose I have a python script (channel.py) that switches between TV
channels (IR transmitter attached to GPIO) based on the input parameter
(channel name) for eg. Switch to will give “Star Movies” to
the channel.py script which takes care of sending the IR signal stuff.

Since a switch has an on and off state where as selecting a channel out of
lets say 20 channels is more like a Radio button with one option selected
(HTML analogy) what would be the ideal way to achieve this?

index.js (Alexa-HA) calling OpenHab item (switch item with exec binding)

Can you help me by writing a dummy sample code / algo (OH item, Alexa HA
index.js) to achieve something like this? It would be great help to
understand the underlying technology.

or alternatively, how can I execute the below (OH command prompt) from
inside the app.intent function of Alexa-HA’s index.js file?

osgi> openhab send CallScript myScript

Here CallScript is a string item associated with a rule.

rule Callwhen
Item CallScript received commandthen
callScript(receivedCommand.toString)end

@Vikas_Singh - Ideally this should be implemented using a binding on the OpenHAB side, which AlexaHA interacts with, rather than calling external scripts at all. I personally have a MythTV backend and would like to develop AlexaHA voice control over the various KODI front ends throughout the house in the future. I’ve noticed comments/references to this sort of thing with other Amazon Echo smart home implementations. For reference see this for an example on how to create a channel switching intent, which should be pretty similar to what we would need on the AlexaHA side. You would then extend the config.js and add new utterances to extract the ‘slots’ you need. Coupled with the OpenHAB XBMC binding this would be much more useful as you could then check/set the ‘state’ of each TV/FrontEnd, and be able to create a web/mobile UI which stays in sync.

Without an OpenHAB binding, external scripts could get messy quick, and I would suggest sticking to putting all of the necessary logic into an OpenHAB rule for now and using the exec binding for issuing the commands, and some very simple stateless logic/intent(s) added to AlexaHA… That way you can still manually update states of other Virtual Items within the OH rule, so OH still has knowledge of each items state. Not perfect but it should fit the bill!

I would not go that route - as we should not assume others would be running AlexaHA on the same server. A core concept of AlexaHA is being able to provide this as a cloud based service (official published Skill) as well as offering self-hosting options.

If you dive into developing this, we would really appreciate it if you would contribute a PR back to our AlexaHA github repo! :slight_smile:

Best regards,
.

Hi All,

New to openHAB2 but VERY motivated to get this working as my Vera Edge just completely bricked. It had a fairly extensive HA setup with a lot of custom Luup code but the key was the BWS Systems HA-Bridge I had running on a Raspberry Pi. EVERYTHING was done with voice through the Echo and since the Edge died I have to figure out what switches turn on what lights!

In any event the learning curve has been steep but I’m starting to get it. This Alexa-HA setup however has been a real challenge for me. Specifically doing a LOT of reading about setting up my own skill and what code would go there. I have no doubt if I keep banging away at it eventually I will get it working but my question is should I even bother?

I see the Hue Emulation skill and seems to do everything the HA-Bridge did but this seems to have MUCH more control and abilities but I see there has been ZERO input on this in over 6 months. I see d0t Mike said ‘work will continue’ but the last post I see from him was July 7th.

Can anyone tell me if this project has changed hands, moved elsewhere, what the status of this is, or any better information on the install that the “INSTALL.md” and “INSTALL-QUICKSTART.md” I would greatly appreciate it!! Getting tired of stubbing my toes running into dark rooms yelling at Alexa to turn on lights before I remember!!

Thanks VERY much,
Dave