Echo Devices (Alexa) as Media Player - Testers Needed

Sure. This is my ‘alarm triggered’ script.

alarm_triggered:
  sequence:
  - data:
      data: 
        icon: https://goo.gl/xeetdy
        vibration: 0,65,706,86,657,95,668,100"
      message: "House alarm away!!!"
      title: "Home Assistant"
    service: notify.phones
  - data:
      entity_id: media_player.downstairs
      volume_level: "1"
    service: media_player.volume_set
  - data_template:
      entity_id: media_player.downstairs
      message: -> 'Attention, the alarm has been triggered. The owner has been notified.'
    service: media_player.alexa_tts
  - data_template:
      entity_id: media_player.upstairs
      message: -> 'Attention, the alarm has been triggered. The owner has been notified.'
    service: media_player.alexa_tts
  - data:
      entity_id: group.all_covers
    service: cover.open_cover
  - data:
      entity_id: switch.counter_top
    service: switch.turn_on
  - data:
      entity_id: switch.bedroom_light
    service: switch.turn_on
  - data:
      entity_id: switch.dining_table
    service: switch.turn_on
  - data:
      entity_id: switch.lr_ceiling_power
    service: switch.turn_on
  - data:
      entity_id: switch.outside_light
    service: switch.turn_on
  - delay: 00:00:08
  - data_template:
      entity_id: media_player.downstairs
      message: -> 'Attention, the alarm has been triggered. The owner has been notified.'
    service: media_player.alexa_tts
  - data_template:
      entity_id: media_player.upstairs
      message: -> 'Attention, the alarm has been triggered. The owner has been notified.'
    service: media_player.alexa_tts

And my ‘welcome home’ script:

remco_home:
  alias: Remco home
  sequence:
  - data:
      entity_id: group.alarm
    service: switch.turn_off
  - data:
      entity_id: switch.drapes_open
    service: switch.turn_on
  - wait_template: '{{ is_state(''sensor.broadlink_s1c_sliding_door'', ''open'') }}'
    timeout: 00:30:00
  - delay: 00:00:12
  - data_template:
      entity_id: media_player.downstairs
      message: -> 'Hello Remco. Welcome home. Cherry is {% if is_state("device_tracker.zy223rkvxx",
        "home") -%} also at home. {%- else -%} not at home. {%- endif %} The temperature
        inside is {{ states("sensor.broadlink_sensor_temperature") }} degrees. And
        outside it is {{ states("sensor.weather_temperature") }} degrees.'
    service: media_player.alexa_tts

And when I unplug my cellphone from the charger in the morning:

remco_awake:
  alias: Remco woke up
  sequence:
  - data:
      entity_id: group.alarm
    service: switch.turn_off
  - data:
      entity_id: switch.drapes_open
    service: switch.turn_on
  - data_template:
      entity_id: media_player.upstairs
      message: -> 'Hello Remco. Goodmorning. The temperature outside is {{ states("sensor.weather_temperature")
        }} degrees. There will be {% if states("sensor.weather_precipitation") ==   '0.0'  -%}
        no rain today. {%- else -%} {{states("sensor.weather_precipitation")}} milimeter
        of rain today, bring an umbrella. {%- endif %} Your first calendar item is;
        {{ states("sensor.next_appoint_remco_message") }}, at {{ states("sensor.next_appoint_remco_tijd")
        }}. Your Travel time to work is approximatly {{ states("sensor.waze_travel_time")
        }} minutes if you take {{ states.sensor.waze_travel_time.attributes.route
        }}. Have a nice day'
    service: media_player.alexa_tts
  - wait_template: '{{ is_state(''sensor.broadlink_s1c_living_room_door'', ''open'')
      }}'
    timeout: 00:30:00
  - delay: 00:00:05
  - data_template:
      entity_id: media_player.downstairs
      message: -> 'Hello Remco. Your Travel time to work is approximatly {{ states("sensor.waze_travel_time")
        }} minutes if you take {{ states.sensor.waze_travel_time.attributes.route
        }}. Have a nice day.'
    service: media_player.alexa_tts
2 Likes

And my doorbell script;

doorbell:
  alias: Doorbell
  sequence:
  - service: media_player.alexa_tts
    data_template:
      entity_id: media_player.downstairs
      message: -> ' Ding-Dong. Someone is at the door.'
  - service: media_player.alexa_tts
    data_template:
      entity_id: media_player.upstairs
      message: -> ' Ding-Dong. Someone is at the door.'
1 Like

Nice work!
I have imported the flow but getting messages about Home assistant connection failed with error: Connection to home assistant could not be established with config: DUMMY_URL

I have connected all of the server nodes, but not sure where to change the DUMMY URL and what it should be?

I have been able to get TUNEIN radio to work!
Has anyone been able to get iHeartRadio to work?

alexa_play_radio_wtvn:

alias: Radio Alexa play Radio WTVN Kitchen
sequence:

  • service: media_player.play_media
    data:
    entity_id: media_player.kitchen
    media_content_id: WTVN
    media_content_type: “iHeartRadio”

Tried this and not working.

1 Like

Found this thread and setting up was super easy, thanks to all the various contributors, so big thanks and have TTS working for various trigger activities now.

I’d like also to be able to a) stream radio and b) play local media files. Realising that b) is not yet possible, does anyone have examples of how to stream audio, initiated from HA? preferably through the media_player interface?

Can anyone here help me with solution how to set Alexa media player value while it is in standby state?

Problem details are described in separate thread

Thanks! This is excellent. Appreciate it.

Followed the guided procedure from the first post, working like a champ.

Hats off. Excellent work. Thanks…

I’m running on Hasso.io 79.3.

I’m still hoping for a solution to the volume control on idle issue.

Is that not going to happen or is it working now and I just missed it?

@inutilis @rclust @finity @Birdbrainuk
Try my version, here. I’ve never programmed in Python before so it’s not very efficient, but this should allow you to change the volume when the echo is in idle/standby, either by using the media_player.volume_set service call, or media_player.alexa_tts.

Note that when using the alexa_tss call, you’ll now need to specify the volume you want to set. Also note that when the echo is in standby, there will be an additional ~10 second delay before the TTS.

Example:

{
“entity_id”: “media_player.my_echo_dot”,
“message”:“testing 1 2 3 4”,
“volume”:“.5”
}

2 Likes

Request to add the following into the alexa.py config file.

Ability to only display standby devices.

There was an earlier post on adding this to line 212. However, this is now on line 214.

     for device in devices:

        if device['online'] is False:
            continue

Edited: Also, would be great to hide the Silent Track

Thanks for the help.

So just to be clear…

I need to replace the contents of the existing ‘alexa.py’ file with the contents from your repo.

Then from then on everything will work exactly the same except that on every TTS service call you will be required to specify the volume and there will be a 10 second delay while the echo device automatically plays a 10 second silent track and adjusts its volume to the selected volume?

And if you use the volume_set call then it will again automatically play a 10 second silent track while it adjusts the volume to the selected volume?

Basically, yes. It doesn’t play for ten seconds, but that’s just roughly how long it takes to queue up the song, play it, and then play the TTS message. This delay will only happen when the echo is in standby. One other thing… I have Prime Music Unlimited, so I’m honestly not sure if the song I chose is available for non-Unlimited members. Someone will just have to test it and see.

Thank you for this amazing component. Now I can send notifications to all my Echos in my home.

However in order to send notification to my Echo, I have to use this custom service; media_player.alexa_tts. Example action in automation…

  action:
    service: media_player.alexa_tts
    entity_id: media_player.office
    data:
      message: "Message goes here"

But I prefer to send notifications via the notify service so that I don’t have to change all my existing automation that uses the notify service.

My solution is to recreate the notify entities using Rest platform:

Example for one Echo device…

notify:
  - name: office
    platform: rest
    resource: 'https:/[YOUR HA URL]/api/services/media_player/alexa_tts'
    method: POST_JSON
    data:
      entity_id: 'media_player.office'
    headers: 
      x-ha-access: !secret http_password
      content-type: 'application/json'

Hope this helps if you are looking for similar solution.

1 Like

By the way, the Alexa TTS seems to ignore the degree (°) or percent (%) symbol in temperature. e.g. 31.1 °C.

It reads out as… “thirty one point one C” instead of “thirty one point one degree Celsius”.

My other custom news briefing and skills for alexa read out fine.

Is it due to encoding issue?

Has anyone been able to get alexa_tts working on a Multi-Room Audio group? I see the group in Home Assistant (media_player.downstairs) with all of the attributes, but the alexa_tts service call isn’t working.

Also thanks to @Justin_144 for the volume set code! I just updated to use your alexa.py file to set volume and it is working great.

I have also had this “Simon says” issue mentioned earlier in this thread.

I have neither talked to Alexa, nor sent any text to her trough HA. Still she is repeating that “Simon says” phrase over and over and over again.

I had to comment out the necessary lines in my config in order to make it stop.

Any ideas of how to solve this issue?

What piece of information would you like me to provide to try to solve this?

nevermind i misunderstood what alexa said

Unfortunately the blank song doesn’t play unless you have Amazon Music Unlimited.

I tried another one and it comes up in the player but it doesn’t play. It just sits there with the song on the screen and I can’t do anything with the media player at all.

This is the message I used in the media_player.play_media service:

{
“entity_id”:“media_player.computer_room_dot”,
“media_content_id”:“Silence 5 seconds”,
“media_content_type”: “AMAZON_MUSIC”
}

“Silence 5 Seconds” is the name of a song I found on amazon music for prime members (which I have).

If I tell Alexa to play the song “Silence 5 Seconds” by voice it immediately plays the correct song by the correct artist so Alexa knows the song I mean when I use voice control.

May be I’m not understanding how I designate a specific song in the service call but it worked (but told me it wasn’t included unless I had unlimited) when I tried it like this:

{
“entity_id”:“media_player.computer_room_dot”,
“media_content_id”:“Blank (Silent Track)”,
“media_content_type”: “AMAZON_MUSIC”
}

Well I think it is playing, but the thing you’re seeing with the media player is just what normally happens after a song ends. In my version of alexa.py, did you try changing the song to the “Silence 5 seconds” song (on line 507)? I briefly just tested it, and it seemed to work (the TTS calls with a “volume” value, that is). I’ll update my version in my repository to use the Silence 5 Seconds song.

If you can’t get it to work, try finding a silent track longer than 5 seconds (and let me know if you find one)