NOTE: Because of the age of this thread, we can’t edit the first post anymore and it is outdated. For current installation instructions and latest information, please see the Wiki.
I’m excited to share with you all a component that I have been working on for the last week that allows controlling amazon echo devices (and clones) directly in home assistant!
What This Is:
This topic and this post is a place I hope to use to collaborate with enthusiastic Home Assistant users that want to see this component become the best it possibly can be. What I hope for is that we can each test and debug features within our skill set to make sure that once submitted for code review to be integrated into an official home assistant component that it will be a seamless experience for all users that wish to enable it.
For anyone who wishes to install the custom component and hassio add-on (or docker container) be aware that this component is absolutely still a work in progress and may have currently unforeseen issues. With that said
What It Does:
Allows for control of Amazon Echo products as home assistant media devices with the following features:
- Play/Pause/Stop
- Next/Previous (Track)
- Volume
- Retrieval for displaying in home assistant of:
- Song Title
- Artists Name
- Album Name
- Album Image
Screenshot:
Background
A home assistant component that, like any other, defines a device and its attributes for home assistant to digest and ultimately show you on the HA GUI. The second part is a node.js API that creates a session with the https://alexa.amazon.com web interface and sends commands using the retrieved session tokens.
I cannot take all the credit for the component and while I haven’t spoken to either of the following people directly I want to say:
A huge thanks goes to Alexander Noack @ https://github.com/thorsten-gehrig/alexa-remote-control his work of inspecting the Alexa web interface and reverse engineering amazon’s APIs for use in a shell script is what makes this comment possible.
I also want to thank Noel @ https://github.com/noelportugal/alexa-reminders for laying the groundwork for getting nightmare in node.js working for the https://alexa.amazon.com website. This allows getting the session cookies easily.
# Design Choices
node.js has been chosen as the backend API because it allows for easy retrieval of the session cookies used for calling the APIs discovered by Alexander. I attempted for a while to discover a similar way of doing this inside python to make everything HA native, but unfortunately couldn’t. This is either because amazon locks down python scripts working this way or some javascript is needed for the login process that node.js can easily handle. What this means is that we end up with both a component and a hassio add-on to make things work.
Installation of Custom Component
Installing the custom component
First thing is to download the alexa.py custom_componet from @ https://github.com/keatontaylor/custom_components/blob/master/media_player/alexa.py. This file will be placed in your config directory under a folder named custom_components/media_player. If these folders do not exist you can add them.
Once there you’ll need to update your config to include the following:
media_player:
- platform: alexa
email: “your amazon email”
password: “your amazon password”
url: “amazon.com”
Once set, reboot and you should see all your Alexa devices in home assistant
Known Bugs and Issues
- Whole Home Audio Devices have no working volume reporting (controls still work via service commands)
- Unknown support for Alexa clones (but works on a Roav VIVA)
-
Media Players that haven’t played music in a while go into an unknown state (this is because Amazon doesn’t keep the playlist active).Request a song from the play_media service -
As above, currently no way to tell Alexa what playlist/song/artist you want to hear directly from HA (this is coming soon)DONE -
May not work with other media providers like Pandora, Tune-In, Spotify(FIXED)
Notable Additional Features
Text-to-Speech - Can be invoked from the HA UI services menu. media_player.alexa_tts and requires a payload like this:
{"entity_id": "media_player.bedroom_echo_dot", "message": "Test message"}
Online status of devices - Additional attribute to tell you if the Alexa device is online (extremely useful if you want to send a TTS after one has come back online (such as one in a vehicle)
Going forward
To those who made it all the way to the bottom of this extremely long post thank you so much! I hope that it was sufficiently informative for you to get it setup to start testing in your home assistant install. I really do humbly appreciate anyone who provides feedback and comments of any kind (including constructive criticism) so please feel free to leave a reply for anything and everything.