Amazon Echo Skill for OpenHAB available!

@d0t Post rule on github. Keep up the good work! :slight_smile:

I use it all the time. Thank you so much! It works great except for ā€œask $SKILL_NAME toā€ part. I know there is no way of changing it, unless using some kind of hue emulator or something, but then you lose a lot of options.
By the way, I had Wolfram working just fine, and then it stopped all of the sudden. Says it did not get response in time. Any ideas what could have happened?

Should I update my Alexa-HA? I installed it 3 months ago or so.

Always good to hear :sunglasses:

Hmmm, I havenā€™t used it in quite some time so canā€™t comment on the Wolfram integration. But you could investigate further by adding some debugging to the code to print the response. That might give you some more insight (such as HTTP response codes, error messages, etc).

There havenā€™t been any major changes in the past few months, so I would wait for the next major release. Working on updating Alexa-HA for OpenHAB 2.x, and will do my best to backport any improvements for the 1.x users too.

Trying to get this skill setup, and things were going well until I tried to get pm2 working properly. The service starts properly with pm2 start server.js, but wonā€™t survive a reboot.

I suspect it has something to do with the fact that /etc/init.d/pm2-init.sh does not seem to exist. When I try to edit this per the notes in the above post, I get a blank new file.

Any Ideas what could of caused this? All the previous steps went well, the only suspect thing is when installing pm2, the first line is see in the status is: npm WARN optional dep failed, continuing fsevents@1.0.17

Any tips???

On the Alexa tester page, should you be able to issue, say, and intent request, configure it, press send request button and get some sort of response? I can reach the page, issue the request, and nothing happens. No response and no error. Any tips in debugging this?

Hi @Jeff_Smeker,

Hope you have fixed the PM2 issue. I seem to recall having the fsevents warning too so doubt that is your problem. Sounds like itā€™s a user or posix permissions issue. Which user are you running pm2 under? Try root to testā€¦

Regarding the tester page, itā€™s been a while but I couldnā€™t get it working at the time. Others have reported using it without issue since, but I would focus on using real commands on your devices. Can you confirm your Alexa endpoint is on port 443 with a valid or uploaded SSL cert? Amazon requires this and has been the most common cause for others with commands not reaching the alexa HA endpointā€¦

All the best,
.

Thanks for the response. Iā€™m going to revisit the pm2 issues later and will look at user permissions.

Re ssl cert: I had been getting ssl errors on the amazon dev site, but after copying the .cer contents to amazin, the ssl error went away. Iā€™m assuming this part is now ok.

Re port 443: Iā€™m able to reach the tester page using 443 from the external domain, so I think this is setup correctly. But Iā€™m a little confused - in the QuickStart example of server.js config states port 30000, then configured forwarding 443 to 30000. There is also a note about using a custom configuration. Iā€™m setup exactly like this example, but am a little confused what this is all doing. Any clarification you can provide?

I also had problems with pm2.

Resorted to start it by adding it in my after.local
/etc/init.d/after.local:

      sudo -u alexa /home/alexa/startalexaha.sh

and startalexaha.sh

#!/bin/bash -
cd /home/alexa/node_modules/alexa-app-server/api/
pm2 start /home/alexa/node_modules/alexa-app-server/api/server.js

@d0t

Looks like my cert may not be correct afterall. Just not sure how to do this. Iā€™m using the Semi-direct approach, and have Alexa HA server on a seperate server (on an outside network, hosted on AWS actually) . My ports are all opened properly on my home network where OH is located.

I noted in the Alexa app a few SSL errors. They didnā€™t appear right away, after issuing the command. Specifically:

The SSL handshake to endpoint Resource [https://[IP TO MY ALEXA HA SERVER]/api/alexa-ha?password=[MY PASSWORD]], Type [HTTP] failed, Region [NA] Failed. Please check that your java keystore is correctly configured.

When I visit the above endoint URL, I do get a connection. Although it is stating not secure. Iā€™m thinking this is not correct??

Iā€™ve went thru the process of the self signed cert in the QUICKSTART many times. Then I open ~/node_modules/alexa-app-server/api/sslcert/cert.cer. Copy and paste the contents into the Amazon SSL cert section. Is this the correct method? I didnā€™t see these exact steps mentioned anywhere.

Really itching to get this setup. Please help! Iā€™d be willing to help with clarifying the documentation if needed too.

@Jeff_Smeker
I can really recommend getting a proper certificate.
You can get one for free from: https://www.letsencrypt.org
Itā€™s quite simple to set up.

Going to my endpoint url (same as configured in Amazon Developer Portal, Alexa-Skill)
https://www.mydomain.com/api/Alexa-HA?password=somepassword

I get the Alexa Tester page as a valid https page.

Hope this helps.

Regards S

1 Like

@Seaside
Thanks for that, Iā€™m currently giving it a go, but it seems Iā€™d have to use Apache and not use the semi-direct approach. Iā€™m ok with that, but that docs donā€™t document getting that method going. Iā€™m trying now though!

Please share you hurdles along the way and I/we are glad to assist working through them all!

Best regards
.

Boy, I think Iā€™m getting close. Why would I get ā€œalexa-app-server is runningā€ instead of the tester page though? Any quick ideas?

Iā€™m taking good notes on all this, so Iā€™ll be able to post my process.

Nevermind, needed whole URL /api/alexa-ha/ā€¦ :slight_smile:

Okay, looks like Iā€™m connected well. Now getting errors that alexa ha cannot switch my items on or off. Not sure if these is connection to the OH server issue, or an items/groups issue. Any tips on debugging?

My response to the command from the tester site:
REQUEST: Switch Intent slots are: ON/Office Floor Lamp/office
RESPONSE: I cannot currently switch your office Office Floor Lamp

Setup as follows:

Office Floor Lamp is a actual item in my working OH setup
And how are locations mapped in the item files?

Update: really stumped on this one. It seems no matter what I put into config.js regarding the connection to my OH server, I get the same result. Even if I put in known incorrect info. Iā€™m thinking my connection to my OH server is failing then.

If I build a connection string exactly as shown in the config, Iā€™m able to connect via a browser. Using EXTERNAL auth, no SSL cert in OH. Is that my issue?

Where are the logs showing whatā€™s happening here?

Edit again:
Looks like debug logging became enabled after a reboot of the server. Hereā€™s some error output:
alexa@ip-172-30-0-245:~/node_modules/alexa-app-server/api$ node server.js
Serving static content from: public_html
Loading server-side modules from: server
Loaded /home/alexa/node_modules/alexa-app-server/api/server/login.js
Loading apps from: apps
Loaded app [Alexa-HA] at endpoint: /api/Alexa-HA
httpsEnabled is true. Reading HTTPS config
Listening on HTTPS port 30000
Listening on HTTP port 30001
108.89.243.46 - 2015-05-13T12:34:56Z - AWS ASK IntentRequest received: amzn1.ec ho-api.request.6919844a-733e-4e89-893a-fdcb77e2ef0d / amzn1.echo-api.session.abe ee1a7-aee0-41e6-8192-e6faaed9f5ef
REQUEST: Switch Intent slots are: ON/light/office
OpenHAB getState Results: OFF
/home/alexa/node_modules/alexa-app-server/api/apps/alexa-ha/lib/openhab.js:34
console.log('setState call: ā€™ + url + ā€˜/ā€™ + state);
^

ReferenceError: state is not defined
at Request._callback (/home/alexa/node_modules/alexa-app-server/api/apps/ale xa-ha/lib/openhab.js:34:57)
at Request.self.callback (/home/alexa/node_modules/request/request.js:186:22 )
at emitTwo (events.js:87:13)
at Request.emit (events.js:172:7)
at Request. (/home/alexa/node_modules/request/request.js:1081:10)
at emitOne (events.js:77:13)
at Request.emit (events.js:169:7)
at IncomingMessage. (/home/alexa/node_modules/request/request.js: 1001:12)
at IncomingMessage.g (events.js:260:16)
at emitNone (events.js:72:20)
at IncomingMessage.emit (events.js:166:7)
at endReadableNT (_stream_readable.js:923:12)
at nextTickCallbackWith2Args (node.js:458:9)
at process._tickCallback (node.js:372:17)

Last edit: I had jacked around with the openhab.js to try to get debug logging working, and I broke it. Put it back, rebooted server, and things seem to be working!

Well, this wasnā€™t easy. At least not for me rather inexperienced in linux, and never messed with SSL before. And the Amazon side is pretty complex. Anyway, hereā€™s what I did:

Running: Ubuntu 16.04 on a Amazon EC2 instance
ā€™This will install apache2 and configure both a HTTP and HTTPS site
ā€™Donā€™t worry about the reverse proxy stuff, as it wonā€™t be used in the final settings. I thoughts this was going to be required, but not.
'Complete the self-signed cert stuff as well, even though that wonā€™t be used in the final product either
ā€™This allows full testing of the HTTP and HTTPS sites
ā€™Chrome will bark about non-private connection using the self-signed cert, this is normal

'Once the above is working, install a cert using the instructions from the link below
ā€™Use the automated setup, worked without any trouble and I was immediately able to browse the HTTPS version with a green light from chrome
ā€™Some notes: Server name needed to be a domain name pointing to the server. This server name should also be noted in the proxy-ssl-host.conf from above

'Install Alexa-HA from below.
'User server.js exactly per the example with the exception of below:
privateKey:ā€˜privkey.pemā€™,
certificate:ā€˜fullchain.pemā€™,
'Do not redirect port 443 as noted (yet)
'Make sure your server is passing ports 80, 443, 30000, and 30001 for testing
ā€™Do not do the self signed cert stuff
ā€™I also held off on the PM2 stuff for the time being, and manually started and stopped the server as needed
Copy the above certs files from /etc/letsencrypt/live/MYSERVERNAME/ to (alexa user) ~/node_modules/alexa-app-server/api/sslcert

'Starting Alexa-HA should be successful without any SSL errors
ā€™Make sure you can visit the Alexa tester page using port 30000 per the above instructions
redirect port 443 as noted above
Now visiting port 443 should auto redirect to 30000 (silently) and you see the tester page

'Some notes regarding the config.js file
config.applicationId and config.userId will be displayed in the output of the Alexa Tester page, start to manually create a request, and youā€™ll see this data fill in. Enter the data from the tester page into config.js and the tester page will command Alexa HA.
Change the above applicationId to the one shown on the Amazon dev site, then try to issue a command from the Echo. In the error output youā€™ll see the userId. Enter this info into config.js, restart Alexa HA, and everything will function from the Echo
nano ~/node_modules/alexa-app-server/api/apps/alexa-ha/config.js

The last big hurdle I have is that for some reason PM2 / node.js is giving me out of memory errors, and crashing. Just started debugging this. If anybody has any ideas, love to hear em!

Thanks!

Edt: PM2 install was my issue above. Hereā€™s my install process that stopped the memory errors, and restarted automatically on boot:
as root
usermod -aG sudo alexa 'allow alexa sudo permissions
sudo npm install -g pm2 'install pm2
sudo su alexa
cd ~/node_modules/alexa-app-server/api/
pm2 start server.js
pm2 startup systemd 'sets to auto start on boot in Ubuntu
output from this command will include instructions to run a command specific to your system. in my case:
sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u alexa --hp /home/alexa
More info here:

Thatā€™s it, worked like a champ!

Currently spending my Friday night configuring my item files to get a little more functionality. Code and some cold ones!

Just wanted to say thanks to all of you for all the work put into this projectā€¦ and OpenHab in general. Such a great platform. Where can I donate some money to help out the project? Or if I can help with any testing, or hosting, or anything except for hard-core coding, Iā€™d be willing.

Thanks again! Cheers!

I think help with documentation is always warmly welcomed!

Yikes, just went through setting up this, only to be stopped at the last hurdle. Apparently LITERAL slot types are not supported using English.UK language, and will be stopped all together next month for the US too:
See Here
Although I do notice there is a Smart Home App type now, could using this help?