I was completely successful in configuring Alexa without the cloud on external port 8123 with events. I’ve seen everything else but events by others but I got events to work.
Hope this helps someone else who can’t use port 443. Totally worth the effort!
I essentially used the HA instructions but there are three very important changes:
1. You must make a simple edit to the matt2005 lambda code. Immediately after this part of the HA instructions
token = scope.get('token')
if token is None and _debug:
token = os.environ.get('LONG_LIVED_ACCESS_TOKEN') # only for debug purpose
to
token = os.environ.get('LONG_LIVED_ACCESS_TOKEN') # only for debug purpose
Very Important Note! The remaining line has been moved 4 spaces to the left
2. Where the HA instructions suggest not using the Long-lived Access Token (LLAT), YOU MUST USE an LLAT and DO NOT DELETE it when the instructions say you can.
3. You must use Login With Amazon (LWA). At the HA instructions Linking section use only the following, slightly edited subset of [this post](https://community.home-assistant.io/t/alexa-proactive-mode-unable-to-link-alexa/123530/28) to replace most of the Linking section.
Now continue the HA instructions starting at the screenshot near the end of the Linking section
Great! Did you set up SSL or it’s not required? I don’t want to set up SSL as my router doesn’t support NAT Loopback and I can’t connect with the domain
I did set up SSL but it is quite possible that you don’t have to. Specifically, Amazon requires SSL to talk to an Alexa skill but the lambda function is a marshalling function (man in the middle) and, therefore, IT is Alexa’s connection! Conceivably, you don’t need SSL (with a one-line change to use HTTP not HTTPS). Couple of caveats though. Maybe the lambda function enforces HTTPS (I doubt it). Maybe the HA integration requires SSL. Maybe Alexa needs SSL for “send Alexa events” which I believe go straight to Alexa from the integration (no lambda).
I didn’t enable NAT loopback so that is not a requirement. I access remotely using duckdns domain name. I access locally with the local IP. Works like a charm. You need a port forwarded and the lambda function needs to be able to get your IP (fixed IP would work probably)
I was careful to use the same login (email address) for AWS, Alexa login and Amazon developer.
For the login validation to get the login token, I used a trick. I made a LWA (Login with Amazon) account in Amazon Developer and used that to satisfy the need for Alexa to login to the app. Then, in the lambda function I totally ignored the token sent by Alexa and used the LLAT instead.
You do need a login for send events, but for that you use the login that is created by Amazon in your skill.
hi, i’m struggling with it… i understand what you said, but i don’t know how to create the LWA and how to make the Alexa skill log in that way…
Can you explain it in details?
Hello I am fairly new to home assistant and have zero knowledge about codes.
can you please explain how to make changes to lambda. " 1. Edit matt2005 lambda to comment out lines 50 and 51 and outdent 52 to force it to always use the LLAT."
and is llat long lived access token?
and if possible can i have some screenshots for same.
i know im asking a lot .thanks to anyone who can help.
Hi mate. Thanks for your post. I successfully followed steps 1 (setup Alexa as per HA instructions), modified the matt2005 Python script to force the use of a LLAT. I have also kept the LLAT in my amazon alexa settings environment variable (as per HA instructions too).
However, I am lost in step 4. I am confident with coding but never used Amazon Developer before, so where exactly do I link my HA using LWA method? Only way I know is using Alexa app normally and logging in, but that fails because I am not using port 443.
Is there a guide which shows me how to setup LWA (I googled this but don’t quite see how HA will work with it) and link my home assistant to my alexa on port 8123? I have successfully added endpoint, client_id, client secret I generated from Amazon login to my configuration file , but how do I go about linking?
Second, I need a bit of time to look at how I did it. I remember it was easy once I understood the pieces and their roles then came up with a good way to do it.
Sounds like you and I have similar computer skills. Many years of programming but no experience with AWD which, of course, is a key component of this solution.
When you get it working, perhaps you and I can both put a bit more meat on the first post of this thread to fill in a few assumptions.
Couple of days, please… Nudge me if it has been more than 1 week.
Note, pretty sure it doesn’t matter but I’m in Canada though I choose to tell Amazon that US is my location 'cause this stuff doesn’t work using Canada. It works in other regions (Ireland etc.) but I don’t know which URLs change for other regions. Search this forum and/or Google to find out.
So as I understand, you have progressed through the HA instructions , editing the matt2005 and keeping (not deleting) the LLAT and now you are at the Linking section and need more detail on differences from the HA instructions:
At the HA instructions Linking section use only the following, slightly edited subset of this post to replace most of the Linking section.
Now continue the HA instructions starting at the screenshot near the end of the Linking section
A small caution. there may be minor mistakes or missing items (though I did look carefully) and there may be more questions you have. Please help others by including me in your struggles so I can edit this post to give the next person a complete and simple HOWTO. I will be happy to you and others.
Useful references:
This documentation on the Alexa integration though it does not use LWA
This thread that diverges from the simple approach in this thread but offers some details about LWA etc.
I’ve found your thread while looking for options to move away from my current Alexa setup for handling speech interaction with HA. I’m sorry for the dumb question, but what does this solution actually do?
Great, appreciate your help. I’ve successfully managed it and it works!
So basically, I think what you replied is already half the job done. You can edit your first post (since I cannot and you are the main champion here ha-ha), just state something along these lines (you can be a bit more informative if you wish but it is actually very simple once we know what we mean by LWA; since I had no idea what LWA was before this):
Configure Alexa as per normal HA instructions normally
1a. Keep in mind, use the debugging mode of the instructions that keep the LLAT (Long-Lived Access Token) and keep it in Alexa’s developer Environment variable permanently
Follow instructions normally until Account Linking.
Then you can link the reply word-to-word you gave me, its clear enough.
and done!
Great work Keith!
I do have one more question, regarding the events now, into configuration.yml. Did you link the Client ID and Client Secret we got from Alexa’s Developer console (as normally HA instructions) or did you use the AWA login’s client ID and secret?
This is basically integrating Amazon Alexa into your Home Assistant devices.
But the change is this; normally when you need to integrate without Nabu Casa, you MUST use port 443 since the way Amazon Alexa’s API works. However, not everyone can forward 443 or they just do not want to forward a common scanned attack port (like me), so if you want to keep port 8123 or whatever, using LLAT and this method, you can use any port for linking Alexa.
Thank you for that info! I was hoping it might of been so voice commands given to Alexa bypass their cloud services and instead went elsewhere, possibly to a local voice command server… I’ll have to keep looking into that, but this info I’ll definitely keep in the back of my mind!