Home - alandtse/alexa_media_player GitHub Wiki
Welcome to the Alexa Media Player Wiki! Please help us update this if you see errors or things to add.
- What This Is
- What It Does
- Notable Additional Features
- Guides
This is a custom component to allow control of Amazon Alexa devices in Homeassistant using the unofficial Alexa API.
Please note this mimics the Alexa app so Amazon may cut off access at anytime.
Allows for control of Amazon Echo products as Home Assistant media devices with the following features:
- Run Custom command
- Play/Pause/Stop
- Next/Previous (Track)
- Volume
- Retrieval for displaying in home assistant of:
- Song Title
- Artists Name
- Album Name
- Album Image
- Shuffle
- Repeat
(versions >= 3.4.0) You can now issue a voice command directly to a device as if you're speaking to it.
action: media_player.play_media
metadata: {}
target:
entity_id: media_player.guest_room
data:
media:
media_content_type: custom
media_content_id: what time is itWe can basically do anything an Alexa Routine can do. You'll have to discover specifics, but here are some examples (and please help add them below!).
To play music using the media_player.play_media service, you have to define the media_content_type appropriately. Search the forum for other examples.
Service example
action: media_player.play_media
data:
media:
media_content_id: cats the musical
media_content_type: AMAZON_MUSIC
target:
entity_id: media_player.home_theaterPlaylist named "Duets"
action: media_player.play_media
data:
media:
media_content_id: My playlist Duets
media_content_type: AMAZON_MUSIC
target:
entity_id: media_player.guest_roomService example
action: media_player.play_media
data:
media_content_id: 7 rings
media_content_type: APPLE_MUSIC
target:
entity_id: media_player.guest_roomService example
action: media_player.play_media
data:
media_content_id: Falco
media_content_type: DEEZER
target:
entity_id: media_player.guest_roomService example
action: media_player.play_media
data:
media_content_id: kiss
media_content_type: I_HEART_RADIO
target:
entity_id: media_player.guest_room
Service example
media_content_type: PANDORA doesn't currently work. Use media_content-type: custom as indicated below.
In media_content_id, do not begin with play. play ... on Pandora fails with "couldn't find" but the same text without play works. You can optionally use start ... if you wish.
action: media_player.play_media
data:
media_content_id: depeche mode radio on pandora
media_content_type: custom
target:
entity_id: media_player.kitchen_echo_dotService example
action: media_player.play_media
data:
media_content_id: Madras Melodies
media_content_type: SAAVN
target:
entity_id: media_player.guest_roomService example
action: media_player.play_media
data:
media_content_id: Big 40 Countdown
media_content_type: SIRIUSXM
target:
entity_id: media_player.guest_roomService example
action: media_player.play_media
data:
media_content_type: SPOTIFY
media_content_id: Release Radar
target:
entity_id: media_player.guest_roomTuneIn radio stations can be played using media_player.play_media with media_content_type: TUNEIN. Specify the station name as media_content_id.
Service examples
action: media_player.play_media
data:
media_content_type: TUNEIN
media_content_id: BBC one
target:
entity_id: media_player.guest_roomaction: media_player.play_media
data:
media_content_type: TUNEIN
media_content_id: radio paradise main mix
target:
entity_id: media_player.guest_roomRegional restrictions and playback issues
Some stations available through the TuneIn website may not be available through Alexa due to regional licensing or other restrictions.
Please note that BBC services are not available via TuneIn in the United Kingdom.
If a station fails to play using TUNEIN, try using media_content_type: custom instead. This sends an Alexa-style command rather than requesting the station directly through TuneIn. Note: "on tunein" needs to be appended to the media_content_id.
Custom command workaround
action: media_player.play_media
data:
media_content_type: custom
media_content_id: BBC Radio One on TuneIn
target:
entity_id: media_player.guest_roomAlternatively, for another station:
action: media_player.play_media
data:
media_content_type: custom
media_content_id: radio paradise main mix on TuneIn
target:
entity_id: media_player.guest_roomIf these fail, try using the word play in the media_content_id:
media_content_id: play BBC Radio One on TuneIn
The custom method may work when direct TuneIn playback fails, but it does not bypass regional licensing restrictions.
If neither method works, try requesting the same station directly from your Echo using a voice command, such as:
"Alexa, play Radio Paradise on TuneIn."
If the voice command succeeds but playback through Home Assistant fails, please open an issue and include the station name, media_content_id, media_content_type, and relevant debug logs.
It is currently not possible to play to an Alexa group using routines. However, there is currently a hack that may or may not work where you can play to an Alexa group using any Alexa entity on that account. For example, to play "boyz ii men" to the "everywhere group", you can set the "media_content_id" like the following. NOTE: The "entity_id" is set to media_player.guest_room(this could be any alexa device) instead of media_player.everywhere
Service example
action: media_player.play_media
data:
media_content_id: boyz ii men in everywhere group
media_content_type: AMAZON_MUSIC
target:
entity_id: media_player.guest_roomYou can shuffle, if supported, by mentioning shuffle at the beginning of the media_content_id.
Please note that Amazon seems to have removed shuffle command as stated in the following issue We leave the reference here as no one knows if Amazon will ever enable it again... A possible workaround would be to play the media, enable the shuffle entity then use the media_player.media_next_track service adding some wait in the middle.
Service example
action: media_player.play_media
data:
media_content_id: shuffle greenday
media_content_type: AMAZON_MUSIC
target:
entity_id: media_player.echo_show(versions >= 3.2.0)
You can specify the amount of seconds the music will play before stopping. NOTE: This will only work if the target device is the playing device. If your target device will play on another device, the timer will not work.
Service example
action: media_player.play_media
data:
media_content_id: taylor swift
media_content_type: AMAZON_MUSIC
extra: {"timer": 30}
target:
entity_id: media_player.echo_showIf you get errors, please check Alexa history to see if there's special parsing happening. There have been multiple reports of inconsistent behavior.
Acronym issues
action: media_player.play_media
data:
media_content_id: e._s._p._n. radio
media_content_type: TUNEIN
target:
entity_id: media_player.guest_room
- “BBC one” This works.
- "NPR” This has always worked but no longer…Alexa says it “can not play by artist on Tune-in”
- "N P R” sorta works but picks the incorrect media channel.
- “n. p. r.” now works properly. I found out by verbally asking Alexa to play N P R and checking history.
Please also note that different services may parse text differently.
(versions >= 2.4.0)
Sounds are also available using the media_player.play_media service.
action: media_player.play_media
data:
media_content_id: amzn_sfx_doorbell_chime_01
media_content_type: sound
target:
entity_id: media_player.guest_roomScript sample:
# scripts.yaml
door_bell_alexa:
sequence:
- action: media_player.play_media
data:
media_content_type: sound
media_content_id: amzn_sfx_doorbell_chime_01
target:
entity_id: media_player.guest_roomThe full listing of ASK (Alexa Skills Kit) sounds is found here.
Some common ones are:
Click to expand
Bells and Buzzer
- bells: “bell_02”
- buzzer: “buzzers_pistols_01”
- church_bell: “amzn_sfx_church_bell_1x_02”
- doorbell1: “amzn_sfx_doorbell_01”
- doorbell2: “amzn_sfx_doorbell_chime_01”
- doorbell3: “amzn_sfx_doorbell_chime_02”
Holidays
- xmas_bells: “christmas_05”
- halloween_door: “horror_10”
Misc
- air_horn: “air_horn_03”
- boing1: “boing_01”
- boing2: “boing_03”
- camera: “camera_01”
- squeaky_door: “squeaky_12”
- ticking_clock: “clock_01”
- trumpet: “amzn_sfx_trumpet_bugle_04”
Animals
- cat_meow: “amzn_sfx_cat_meow_1x_01”
- dog_bark: “amzn_sfx_dog_med_bark_1x_02”
- lion_roar: “amzn_sfx_lion_roar_02”
- rooster: “amzn_sfx_rooster_crow_01”
- wolf_howl: “amzn_sfx_wolf_howl_02”
Scifi
- aircraft: “futuristic_10”
- engines: “amzn_sfx_scifi_engines_on_02”
- red_alert: “amzn_sfx_scifi_alarm_04”
- shields: “amzn_sfx_scifi_sheilds_up_01”
- sirens: “amzn_sfx_scifi_alarm_01”
- zap: “zap_01”
Crowds
- applause: “amzn_sfx_crowd_applause_01”
- cheer: “amzn_sfx_large_crowd_cheer_01”
(versions >= 2.10.0)
You can set the background of an Echo Show using the media_player.play_media service with media_content_type set to image. The url must be a valid https image to be accepted. To undo, follow these instructions.
action: media_player.play_media
data:
media_content_id: "https://home-assistant.io/images/cast/splash.png"
media_content_type: image
target:
entity_id: media_player.echo_show(versions >= 1.2.0)
Please see Notification Component for TTS, announcements, or mobile push.
Please note we do not support the Media Player UI for TTS!
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)
As of >= 3.6.0, a notify target will be created automatically notify.alexa_media_last_called.
Note: The entity ID of the media device should not end with a number.
Each device will report whether it is the last_called for a specific Alexa account with the attribute last_called, the timestamp last_called_timestamp, and command last_called_summary (summary in versions >= 3.5.0). This allows us to identify the device that was called according to the Alexa Activities API.
For basic TTS notifications you do not need to create your own sensor, but it can be useful for other purposes like room-aware lighting or sensor reports.
action: notify.alexa_media_last_called
data:
message: "YOUR MESSAGE"
data:
type: "tts"Add the following Template sensor configuration to configuration.yaml or templates.yaml to create the sensor.
template:
- sensor:
- name: Last Alexa
state: |-
{{ integration_entities('alexa_media') | select('match', 'media_player.')
| select('is_state_attr', 'last_called', True) | first }}
availability: |-
{{ integration_entities('alexa_media') | select('match', 'media_player.')
| select('is_state_attr', 'last_called', True) | first is defined }}Please note, due to changes made by Amazon, this sensor will be a little slow to update and might not be reliable for some uses.
Additionally, the following resources are highly relevant and provide useful background information:
- https://github.com/alandtse/alexa_media_player/issues/3175)
- https://github.com/alandtse/alexa_media_player/issues/2929
If you are using more than one Amazon account, see Legacy Last Called Sensor.
Script Examples
This can be useful if you want to set up different default volume levels for different echos. For example the Echo dot 2nd gen. is much quieter at volume 0.3 than an Echo dot 3rd gen. So you probably want to set a higher volume for the 2nd gen. Echo dot.
###scripts.yaml
alexa_set_volume:
sequence:
- action: media_player.volume_set
target:
entity_id: "{{ states('sensor.last_alexa') }}"
data:
volume_level: >
{% if is_state("sensor.last_alexa", "media_player.echo_dot_second_gen") %}
0.5
{% else %}
0.3
{% endif %}(versions >= 1.1.0)
Note: When two accounts are configured, all Alexa device names have to be unique across both accounts when calling the service alexa_media.update_last_called with no email account specified which tries to update the last_called device from both accounts. If not, the alexa_media.update_last_called service will fail to complete and the last_called device will not update correctly until the next scheduled poll. Alternatively, you can issue two separate alexa_media.update_last_called service calls, one for each account.
You can now force a last_called update with the alexa_media.update_last_called service . This is intended to be used in scripts/automations to get the latest data.
With no service data, it will refresh all accounts. If you want to selectively refresh an email account:
https://github.com/alandtse/alexa_media_player/wiki/Examples:-Sensors#legacy-last-called-sensor
{
"email": ["email1", "email2"]
}(versions >= 1.0.0)
Alexa accepts certain pre-defined 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.News.LocalNews
- Alexa.News.NationalNews
- Alexa.GoodNews.Play
- Alexa.GoodMorning.Play
- Alexa.GoodNight.Play
- Alexa.SingASong.Play
- Alexa.TellStory.Play
- Alexa.FunFact.Play
- Alexa.Joke.Play
- Alexa.Music.PlaySearchPhrase
- Alexa.Calendar.PlayTomorrow
- Alexa.Calendar.PlayToday
- Alexa.Calendar.PlayNext
- Alexa.Date.Play
- Alexa.Time.Play
- Alexa.CleanUp.Play
- Alexa.ImHome.Play
Follow these instructions to discover more sequences and please update this list!
(versions >= 1.0.0)
Running Alexa Routines is now supported. Routines are automations setup inside the Alexa App.
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:
action: media_player.play_media
data:
media_content_id: Goodnight
media_content_type: routine
target:
entity_id: media_player.alexaExample script to use a Routine called "Radio Paradise" that is set to play the radio station Radio Paradise from Tune on All Speakers
script:
radioparadise:
alias: Play Radio Paradise
icon: "mdi:play"
sequence:
- action: media_player.play_media
data:
media_content_id: Radio Paradise # Routine name in Alexa app, this is set to play on All Speakers
media_content_type: routine
target:
entity_id: media_player.den_echo_dot # need to select a default player
mode: singleLovelace card
type: entities
entities:
- action_name: Play
entity: script.radioparadise
- action_name: Stop
entity: script.stopmusic
show_header_toggle: false
title: Radio Paradise
(versions >= 2.7.0)
- alias: Trigging a skill.
initial_state: "on"
trigger:
platform: state
entity_id: input_boolean.start_my_car
to: "on"
condition: []
action:
- action: media_player.play_media
data:
media_content_id: <Skill ID>
media_content_type: skill
target:
entity_id: media_player.my_echo_dotYou can find skill ID's by inspecting the JSON when navigating to https://alexa.amazon.com and clicking on skills.
Note: At the moment we do not collect a list of Skill IDs. However, for common skills please feel free to add their IDs to this wiki.
- BBC: amzn1.ask.skill.d0f09984-4805-4275-a118-d7f63f45fa55
- NPR: amzn1.ask.skill.8e0fbda3-b70c-481d-878f-a2e5e17158c9
- Jeopardy: amzn1.echo-sdk-ams.app.6d474311-b5aa-4f47-a97b-1036bc3e1954
- Question of the Day: amzn1.ask.skill.0f26244c-7411-4c2c-8401-d808c57eedef
- My Media for Alexa: amzn1.ask.skill.e4c09d45-60d3-4684-a23f-aeb8c1e28586
This functionality is intended to be used with Alexa Actions, a guide a custom skill designed to allow for actionable notifications from Home Assistant to your Alexa devices.
(versions >= 1.3.0)
Arm and disarm Alexa guard mode using an Alarm Control Panel. To arm, use ARM_AWAY. ARM_HOME is the same as DISARM. Please ensure you've enabled through the Alexa app. You can find more instructions on integrating with Home Assistant here.
# Arms Alexa Guard.
- action: alarm_control_panel.alarm_arm_away
target:
entity_id: alarm_control_panel.alexa_guard # (or whatever yours is called)# Only Disarm if armed. Otherwise, Exit out.
- condition: state
entity_id: alarm_control_panel.alexa_guard
state: armed
- action: alarm_control_panel.alarm_disarm
target:
entity_id: alarm_control_panel.alexa_guard # (or whatever yours is called)I found that I needed to use my unique name plus use state: armed_away to detect if Guard was active. You can find your unique number by just reviewing your Entities in Developer Tools.
# Only Disarm if armed. Otherwise, Exit out.
- condition: state
entity_id: alarm_control_panel.alexa_guard_ # (or whatever yours is called)
state: armed_away
- action: alarm_control_panel.alarm_disarm
target:
entity_id: alarm_control_panel.alexa_guard_ # (or whatever yours is called)
data: {}We do not support any Guard notifications at the moment as the Alexa API does not provide an effective way to monitor.
(versions >= 1.4.0)
The component will create the following switches for each online media player.
- switch.<media_player>_repeat_switch
- switch.<media_player>_shuffle_switch
- switch.<media_player>_do_not_disturb_switch Do Not Disturb
Remark: If you are using any Includes during integration setup, you have to include the name of the switches for each switch the integration should create as well. Otherwise this switch is not created and excluded from setup.
Repeat and Shuffle are only available if the relevant music service supports them. Check against the Alexa App.
(Alarms/Timers/Reminders)
(versions >= 2.3.0)
Each online media player that supports Notifications will create the following sensors:
- sensor.<media_player>_next_alarm
- sensor.<media_player>_next_timer
- sensor.<media_player>_next_reminder
Remark: If you are using any Includes during integration setup, you have to include the name of the sensors for each sensor the integration should create as well. Otherwise this sensor is not created and excluded from setup.
This will give the date time value for the very next active notification that will trigger or None if nothing will trigger for that sensor. This date time value can be used by templates to trigger actions when the time passes.
Additional attributes are exposed:
- sorted_active - Sorted list of all active alarms for templating
- sorted_all - Sorted list of all alarms for templating
- recurrence - How often the alarm/reminder will recur
- reminder - For the Reminder sensor, this it the name of the reminder
You can turn on Amazon Kids (child mode) on an Echo by assigning it to one of the household's child profiles. child is the child's first name as shown in the Alexa app (not case sensitive) or the profile's directedId (amzn1.account...). If two children share a first name, the first match is used; pick the child with the Echo's select.<media_player>_amazon_kids_child instead.
Service example
action: alexa_media.amazon_kids_enable
data:
entity_id: media_player.kids_room
child: "Sam"You can turn off Amazon Kids on an Echo. This removes its assignment to a child.
Service example
action: alexa_media.amazon_kids_disable
data:
entity_id: media_player.kids_roomEach Echo that supports Amazon Kids also gets a binary_sensor.<media_player>_amazon_kids that shows the current state, a switch.<media_player>_amazon_kids that turns it on for the child last assigned (or the first child profile), and a select.<media_player>_amazon_kids_child to pick the child or None. These entities poll every 5 minutes, so a change made in the Alexa app can take up to 5 minutes to show.
You can create an alarm on an Echo. time is in the Echo's own time zone. days is a list of mon, tue, wed, thu, fri, sat and sun to repeat on; leave it out for a one-off alarm, which rings at the next occurrence of time.
Service example
action: alexa_media.create_alarm
data:
entity_id: media_player.guest_room
time: "06:30:00"
days:
- mon
- wedYou can delete an alarm. alarm_id is the alarm's id from the sorted_all attribute of the Echo's sensor.<media_player>_next_alarm.
Service example
action: alexa_media.delete_alarm
data:
entity_id: media_player.guest_room
alarm_id: "{{ state_attr('sensor.guest_room_next_alarm', 'sorted_all')[0].id }}"You can turn an alarm back on at its next ring time. It takes the same entity_id and alarm_id as alexa_media.delete_alarm. NOTE: Alarms with a repeat the integration cannot read, such as monthly, are refused.
Service example
action: alexa_media.enable_alarm
data:
entity_id: media_player.guest_room
alarm_id: "{{ state_attr('sensor.guest_room_next_alarm', 'sorted_all')[0].id }}"You can turn an alarm off without deleting it. It takes the same entity_id and alarm_id as alexa_media.delete_alarm.
Service example
action: alexa_media.disable_alarm
data:
entity_id: media_player.guest_room
alarm_id: "{{ state_attr('sensor.guest_room_next_alarm', 'sorted_all')[0].id }}"Alexa Media Player normally performs network discovery only when the integration is first loaded. To avoid unnecessary resource usage and lengthy polling cycles, discovery is disabled after each successful run.
This service re-enables network discovery for a one-time discovery pass during the next polling cycle, allowing newly added Alexa devices to be detected without reloading the integration or restarting Home Assistant.
The optional email parameter can target specific Alexa accounts. If omitted, all configured Alexa Media Player accounts are included.
Forces Alexa Media Player to log out of the selected Amazon Alexa account(s) and deletes their locally cached authentication session files (.pickle).
This service is primarily intended for debugging and troubleshooting authentication issues. Removing the cached session forces the affected accounts to establish a new authenticated session before they can resume normal operation.
The optional email` parameter can target specific Alexa accounts. If omitted, all configured Alexa Media Player accounts are affected.
Note: This service does not remove the integration or its configuration. It should only be used when troubleshooting login or authentication problems, as affected accounts may require reauthentication through Home Assistant.
Not yet implemented — planned feature.
Retrieves Alexa activity history records from Amazon for the selected account, providing detailed information about interactions with Alexa devices.
Depending on the information available from Amazon, records may include the recognized voice command, device that received it, Alexa's response, timestamps, and activity classifications.
This service is intended to support troubleshooting, diagnostics, and automations that require more detailed activity information than the existing last_called attribute provides.
The proposed implementation may support filtering by device, date range, or activity type, along with pagination for retrieving larger histories.
Note: The service interface, available parameters, and response format have not yet been finalized.
You can resend the last TTS message or announcement sent to an Echo with notify.alexa_media. An announcement keeps its title and method, and one sent to a speaker group can be repeated on any of its members. The last message is shown in the media player's last_message, last_message_type and last_message_timestamp attributes.
NOTE: Push notifications are not kept, and the last message is lost when Home Assistant restarts or the integration reloads.
Service example
action: alexa_media.repeat_last_message
data:
entity_id: media_player.guest_roomRestores an Alexa device's volume to its previous level before the most recent volume change made through Home Assistant.
Alexa Media Player remembers the volume level whenever it is changed through the integration, allowing this service to restore the previous setting.
This is particularly useful in automations that temporarily adjust the volume for announcements, notifications, or other activities and then return the device to its original volume.
The required entity_id parameter specifies the Alexa Media Player device whose volume should be restored.
Note: The previous volume is maintained by the integration, not retrieved from the device's volume history. Changes made outside Alexa Media Player may not be reflected in the saved value.
Forces Alexa Media Player to refresh the last_called information for the selected Amazon Alexa account(s).
The service queries Amazon's activity history to identify the most recently used Alexa device and updates the corresponding media player entities, including their last_called attributes.
This is particularly useful in scripts and automations that need to identify which Alexa device was most recently addressed, without waiting for the next scheduled update.
The optional email parameter can target specific Alexa accounts. If omitted, all configured Alexa Media Player accounts are refreshed.
Note: This service requests the latest available information from Amazon. Updates may be delayed if Amazon has not yet recorded the most recent interaction in its activity history.
- notify.alexa_media
- notify.alexa_media + entity_id
- notify.alexa_media_last_called
See Notification Component for details.
Removed 2024-07-19
Since the end of October 2023, this service no longer worked due to a change in the API by Amazon. Two workarounds are:
- Manually delete voice history in the app
- Enable deletion by voice
Some Amazon Echo devices include built-in smart home capabilities, such as Zigbee hubs, temperature sensors, and other device-specific features.
Alexa Media Player can discover and expose supported devices and features as entities in Home Assistant, including sensors, switches, and lights.
These additional entities allow you to monitor and control supported Alexa devices and connected smart home accessories directly from Home Assistant, making them available for dashboards, scripts, and automations.
Note: Available entities depend on the capabilities of your Echo devices, the devices connected to Alexa, and the features currently supported by Alexa Media Player. Not all devices or features exposed in the Alexa app are necessarily available through the integration.
- Install and configure Alexa Media Player as normal
- Go to the Integrations page in Home Assistant
- Press "Options" on the Alexa Media Player integration card
- Check the box for "Include additional sensors, switches and lights"
- Press "Submit"
This will add new entities for each discovered device. Echo Temperature sensors are automatically added regardless of the "Include devices connected via Echo" setting. These entities will not be associated with the Echo device and should have a name that matches their current name in the Alexa app.
- This only adds devices connected directly to your Echo device. It will NOT add smart devices connected to Alexa via Skills.
- If the emulated_hue integration is enabled, older Hue lights will be ignored and not added to HA.
- If you change the state of lights via Alexa routines or via the Alexa app, you will notice an unavoidable delay before the Home Assistant entity is updated as real time or even near real time updates are impossible. This is a limitation of the Alexa API which can only be polled periodically. The average update time is 5 minutes with a default scan interval of 60s which converts to a polling frequency of every 10 minutes. Choosing to poll more frequently will likely result in the all too familiar "Too many requests" error.
- Alexa supports a limited number of colors and color temperatures. AMP will use the closest possible color to the requested color.
There is a video tutorial how to install and configure this component available in german at youtube: https://youtu.be/giyo6Pv3GLo
Here is a YouTube Play list by 3ATIVE for: Setup (install) | Controlling devices (Node-Red) | advanced TTS and more: https://www.youtube.com/playlist?list=PLWRTMby105biP9gE08iGLab1FP6n7_mka