Home-Assistant Alexa Media Player options

pete_c

Guru
Used this wiki to install this; very much plug n play
 
Will attempt to turn this post in to a blog.
 
What it does:
 
1 - 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
2 - 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"} 
 
Installation

1 - download alexa.py and install it it /config/custom_components/media_player/alexa.py
wget hxxps://github.com/keatontaylor/custom_components.git
2 - edit your configuration yaml to include:

media_player:
- platform: alexa
email: your amazon email
password: your amazon password
url: amazon.com

or

media_player:
- platform: alexa
email: your amazon email
password: your amazon password
url: amazon.com
exclude_devices:
- "This Device"
- "Alan's Alexa Apps"
- Stairs
- Garage

or

media_player:
- platform: alexa
email: your amazon email
password: your amazon password
url: amazon.com
include_devices:
- "Master Bedroom"
- Stairs
exclude_devices:
- Stairs
- Garage
 
3 - restart HA
 
On reboot your Amazon Alexa Devices will come up as media devices in HA.
 
kitchenecho.jpg
bbbcnews.jpg
 
Here created Amazon Echo TTS for zone triggers using MQTT which work well using the built in automation editor after trying this by hand editing the automation.yaml.  Much easier to do this with the automation editor.

Here have an Amazon Dot connected to the Russound zoned audio system (that also is connected to HomeSeer MS SAPI) and utilize bluetooth microphone for this one.
 
Here is one for back door.
 
Name:
backdooropenecho1
 
Trigger type: mqtt
Topic: omnilink/zone2/basic_state
payload: OPEN
 
Actions:
 
Action type: call service
Service: media_player.alexa_tts
Service data:
{
  "entity_id": "media_player.ics_echo1",
  "message": "Back door is open"
}
 
 
 
Learning how to TTS HA variables...easy peasy stuff...
 
message: The temperature currently is {{ {states(‘sensor.temp_high_record_f’) }} .’
 
or use it to state current thermostat settings or current zone status if you want.
 
Really it is almost the same as Homeseer TTS using SAPI with variables (reference numbers).
 
Today is $date.  The time is $time.  The inside temperature is $$DVR: 2441: degrees. The humidity is $$DVR: 2444: percent.  The outside temperature is $$DVR:2443: degrees.   Current condition is $$DSR:1791:.
 
You may already know this, but for those that don't, the default type of everything in the templates is string. So if you want to do some arithmetic with a temperature value you first need to convert it to numeric (using float or int depending on your needs). Skip this step and it's quick trip down frustration lane!
 
Let's say we want to round the temperature value to two decimal places.
 

message: "The temperature currently is {{ states('sensor.temp_high_record_f') | float | round(2) }}."

 
PS
 
You have an extra 'moustache' (parenthesis) in your example. :)  It's the one just before states.
 
123 said:
You may already know this, but for those that don't, the default type of everything in the templates is string. So if you want to do some arithmetic with a temperature value you first need to convert it to numeric (using float or int depending on your needs). Skip this step and it's quick trip down frustration lane!
 
Let's say we want to round the temperature value to two decimal places.
 

message: "The temperature currently is {{ states('sensor.temp_high_record_f') | float | round(2) }}."

 
PS
 
You have an extra 'moustache' (parenthesis) in your example. :)  It's the one just before states.
 
Yeah that a Jinja thing.   I write ansible at work and  it's the same.   What really always gets me is booleans.   I  have spent many hours staring at my logic trying to figure out why it was failing only to realize I was compare something  to "true" instead of True   I am so paranoid now I cast all my booleans no matter what.   I just image any values as having invisible quotes around them...
 
UPDATE: Home-Assistant Alexa Media Player Options - 12th of February 2019  
 
Wiki look ==>   hxxps://github.com/keatontaylor/custom_components/wiki   Added to the OP now at Version 1.X  
 
Testing here and works great!  
 
Sequence commands (versions >= 1.0.0) Alexa accepts certain sequences and this is what provides TTS and play_media.
 
This is now exposed through the media_player.play_media service when the media_content_type is set to sequence
 
Example json:
 
{   "entity_id": "media_player.alexa",   "media_content_id": "Alexa.Joke.Play",   "media_content_type": "sequence" }
 
Supported sequences (may be region specific):    
Alexa.Weather.Play    
Alexa.Traffic.Play    
Alexa.FlashBriefing.Play    
Alexa.GoodMorning.Play    
Alexa.GoodNight.Play    
Alexa.SingASong.Play    
Alexa.TellStory.Play    
Alexa.FunFact.Play    
Alexa.Joke.Play    
Alexa.Music.Play Search Phrase    
Alexa.Calendar.PlayTomorrow    
Alexa.Calendar.PlayToday    
Alexa.Calendar.PlayNext    
Alexa.CleanUp.Play    
Alexa.ImHome.
 
Play Running Alexa automation routines is now supported.
 
Please create them using the Alexa app and ensure they are enabled.
 
This is now exposed through the media_player.play_media service when the media_content_type is set to routine
Example json:
{   "entity_id": "media_player.alexa",   "media_content_id": "Goodnight",   "media_content_type": "routine" }  
 
Instructions for installation:   In Docker (which I use)  
 
1 - Update pip / python  
 
pip install --upgrade pip  
 
2 - install dependencies 
 
pip3 install --force git+hxxps://gitlab.com/alandtse/alexapy.git 
 
3 - Download new alexia_media.py and install the files like this:
 
custom_components
   alexa_media.py
media_player
   alexa_media.py
 
4 - Configure HA
 
alexa_media:
accounts:
- email: your amazon email
password: your amazon password
url: amazon.com
- email: your second email
password: your amazon password
url: amazon.com
 
alexa.jpg
 
Back
Top