Echo Devices (Alexa) as Media Player - Testers Needed

shut_up:
  alias: "Shut Up"
  sequence:
    - service: media_player.alexa_tts
      data_template:
        entity_id: "media_player.livingroom"
        message: "Shut The Fuuck! UP, Again, Shut, the fuuck-ing Fuuck!, up ... I do not want to hear, your big, fat arse, fuuck! arse! MOUTH!, anymore! ... I, am the captain now wendy,  you little! b itch!"
3 Likes

I ended up creating an automation that does a string.replace() on any swear words sent to the echo and I created a dictionary of all “my own” replacement words

1 Like

Do you mind posting the code for that? Sounds interesting.

I’m sorry I’m being dense but I’m still not getting what I need to do to get the volume to change. :confused:

If I want to change the volume before I send a TTS message what do I need to do?

Well I am using Node Red, with an input_text enitity on the front end. When text is entered, Node Red resets the input_text and then creates a payload to send to a service call node. Here is the javascript that does the replacement of swear words. Hopefully you or others find it useful

if (msg.payload === "") return null;

msg.payload = 
{ 
    "data": {
        "entity_id": "media_player.justins_echo_dot", "message": msg.payload.toLowerCase().replace(/twat/g, "twaht")
        .replace(/cunt/g, "cunnt").replace(/ass/g, "asz").replace(/whore/g, "hore").replace(/slut/g, "slutt")
        .replace(/fuck/g, "fucck").replace(/shit/g, "shitt").replace(/bitch/g, "bitchh")
    }
};


// Return the message so it can be sent on
return msg;

To change the volume when it’s in idle, make a play_media call and play the song using:

"data": {
        "entity_id":"media_player.YOUR_ECHO_DOT",
        "media_content_id":"silence 5 seconds",
        "media_content_type": "AMAZON_MUSIC"
}

Then change the volume while that five second song is playing

So after actually trying this, I had to make multiple volume_set calls after sending the play_media command or it wouldn’t work. So after I send play_media, I send the volume_set after 2, 4, 6, and 8 seconds, and this seems to always be working for me. If you use Node Red, I can share my flow.

Yes, pls share the flow as I was looking for the same

Ok, here is my flow, along with a picture of the card I have on my front end for my Alexa control, to give you an idea of my setup (I have my Alexa plugged into my whole-house audio speakers).

[{"id":"61058760.2f3df","type":"comment","z":"e22fb2e7.988f48","name":"Home Audio","info":"","x":75,"y":195,"wires":[]},{"id":"f69ab328.a70908","type":"server-state-changed","z":"e22fb2e7.988f48","name":"TTS text entered","server":"d1d2392c.0d8c9","entityidfilter":"input_text.home_audio_tts","entityidfiltertype":"exact","haltifstate":"","x":85,"y":288,"wires":[["e3f92890.b3e568","5114c6a1.01ed1"]]},{"id":"e3f92890.b3e568","type":"api-call-service","z":"e22fb2e7.988f48","name":"Clear text","server":"d1d2392c.0d8c9","service_domain":"input_text","service":"set_value","data":"{\"entity_id\": \"input_text.home_audio_tts\", \"value\":\"\"}","mergecontext":"","x":285,"y":288,"wires":[[]]},{"id":"7e940906.ab758","type":"api-call-service","z":"e22fb2e7.988f48","name":"Announce","server":"d1d2392c.0d8c9","service_domain":"media_player","service":"alexa_tts","data":"{}","mergecontext":"","x":614,"y":289,"wires":[[]]},{"id":"5114c6a1.01ed1","type":"function","z":"e22fb2e7.988f48","name":"Create Payload","func":"if (msg.payload === \"\") return null;\n\nmsg.payload = \n{ \n    \"data\": {\n        \"entity_id\": \"media_player.echo_dot\", \"message\": msg.payload.toLowerCase().replace(/twat/g, \"twaht\")\n        .replace(/cunt/g, \"cunnt\").replace(/ass/g, \"asz\").replace(/whore/g, \"hore\").replace(/slut/g, \"slutt\")\n        .replace(/fuck/g, \"fucck\").replace(/shit/g, \"shitt\").replace(/bitch/g, \"bitchh\")\n    }\n};\n\nreturn msg;","outputs":1,"noerr":0,"x":443,"y":289,"wires":[["7e940906.ab758"]]},{"id":"515bd94e.743cb8","type":"server-state-changed","z":"e22fb2e7.988f48","name":"Song/Playlist entered","server":"d1d2392c.0d8c9","entityidfilter":"input_text.song_playlist","entityidfiltertype":"exact","haltifstate":"","x":105,"y":226,"wires":[["50fb6234.9a594c","3b8b322b.f6aa7e"]]},{"id":"50fb6234.9a594c","type":"api-call-service","z":"e22fb2e7.988f48","name":"Clear text","server":"d1d2392c.0d8c9","service_domain":"input_text","service":"set_value","data":"{   \"entity_id\": \"input_text.song_playlist\",\"value\":\"\" }","mergecontext":"","x":287,"y":226,"wires":[[]]},{"id":"555abe90.16fa58","type":"api-call-service","z":"e22fb2e7.988f48","name":"Play","server":"d1d2392c.0d8c9","service_domain":"media_player","service":"play_media","data":"{}","mergecontext":"","x":593,"y":226,"wires":[[]]},{"id":"3b8b322b.f6aa7e","type":"function","z":"e22fb2e7.988f48","name":"Create Payload","func":"if (msg.payload === \"\") return null;\n\nmsg.payload = \n{ \n    \"data\": {\n        \"entity_id\":\"media_player.echo_dot\",\n        \"media_content_id\":msg.payload,\n        \"media_content_type\": \"AMAZON_MUSIC\"\n    }\n};\n\nreturn msg;","outputs":1,"noerr":0,"x":443,"y":227,"wires":[["555abe90.16fa58"]]},{"id":"1d5d9252.d04676","type":"server-state-changed","z":"e22fb2e7.988f48","name":"Volume changed","server":"d1d2392c.0d8c9","entityidfilter":"input_number.home_audio_volume","entityidfiltertype":"exact","haltifstate":"","x":85,"y":319,"wires":[["640e2549.28bba4"]]},{"id":"c419e3aa.817f3","type":"api-call-service","z":"e22fb2e7.988f48","name":"Set Volume","server":"d1d2392c.0d8c9","service_domain":"media_player","service":"volume_set","data":"{}","mergecontext":"","x":1354,"y":324,"wires":[[]]},{"id":"d05e020b.c6f578","type":"function","z":"e22fb2e7.988f48","name":"Store Payload","func":"msg.payload = \n{ \n    \"data\": {   \n        \"entity_id\": \"media_player.echo_dot\", \"volume_level\":flow.get(\"volume\")\n    }\n};\n\nreturn msg;","outputs":1,"noerr":0,"x":1191,"y":324,"wires":[["c419e3aa.817f3"]]},{"id":"d7fe9342.000de8","type":"server-state-changed","z":"e22fb2e7.988f48","name":"Genre selected","server":"d1d2392c.0d8c9","entityidfilter":"input_select.genre","entityidfiltertype":"exact","haltifstate":"Choose...","x":85,"y":257,"wires":[["3ce4ba6.2b71ac6","a9cbd42e.4661b8"]]},{"id":"3ce4ba6.2b71ac6","type":"api-call-service","z":"e22fb2e7.988f48","name":"Reset","server":"d1d2392c.0d8c9","service_domain":"input_select","service":"select_option","data":"{   \"entity_id\": \"input_select.genre\",\"option\":\"Choose...\" }","mergecontext":"","x":276,"y":257,"wires":[[]]},{"id":"8c342d69.70513","type":"api-call-service","z":"e22fb2e7.988f48","name":"Play","server":"d1d2392c.0d8c9","service_domain":"media_player","service":"play_media","data":"{}","mergecontext":"","x":594,"y":257,"wires":[[]]},{"id":"a9cbd42e.4661b8","type":"function","z":"e22fb2e7.988f48","name":"Create Payload","func":"msg.payload = \n{ \n    \"data\": {\n        \"entity_id\":\"media_player.echo_dot\",\n        \"media_content_id\":\"My \" + msg.payload + \" playlist shuffled\",\n        \"media_content_type\": \"AMAZON_MUSIC\"\n    }\n};\n\nreturn msg;","outputs":1,"noerr":0,"x":442,"y":257,"wires":[["8c342d69.70513"]]},{"id":"640e2549.28bba4","type":"change","z":"e22fb2e7.988f48","name":"Save volume","rules":[{"t":"set","p":"volume","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":248,"y":320,"wires":[["d16e51e7.d262f8"]]},{"id":"d16e51e7.d262f8","type":"api-current-state","z":"e22fb2e7.988f48","name":"Get idle state","server":"d1d2392c.0d8c9","halt_if":"","override_topic":false,"override_payload":false,"entity_id":"media_player.echo_dot","x":416,"y":320,"wires":[["25b097b1.40dd6"]]},{"id":"25b097b1.40dd6","type":"switch","z":"e22fb2e7.988f48","name":"idle?","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"idle","vt":"str"},{"t":"neq","v":"idle","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":565,"y":320,"wires":[["5a985cec.804ee4"],["d05e020b.c6f578"]]},{"id":"5a985cec.804ee4","type":"api-call-service","z":"e22fb2e7.988f48","name":"Play song if idle","server":"d1d2392c.0d8c9","service_domain":"media_player","service":"play_media","data":"{\"entity_id\":\"media_player.echo_dot\", \"media_content_id\":\"silence 5 seconds\",         \"media_content_type\": \"AMAZON_MUSIC\" }","mergecontext":"","x":783,"y":307,"wires":[["4b757c24.af221c","7a958262.f9635c","144f2332.a5756d","ca7abdf4.241fa8"]]},{"id":"4b757c24.af221c","type":"delay","z":"e22fb2e7.988f48","name":"","pauseType":"delay","timeout":"8","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":960,"y":308,"wires":[["d05e020b.c6f578"]]},{"id":"7a958262.f9635c","type":"delay","z":"e22fb2e7.988f48","name":"","pauseType":"delay","timeout":"6","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":960,"y":276,"wires":[["d05e020b.c6f578"]]},{"id":"144f2332.a5756d","type":"delay","z":"e22fb2e7.988f48","name":"","pauseType":"delay","timeout":"4","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":959,"y":244,"wires":[["d05e020b.c6f578"]]},{"id":"ca7abdf4.241fa8","type":"delay","z":"e22fb2e7.988f48","name":"","pauseType":"delay","timeout":"2","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":959,"y":212,"wires":[["d05e020b.c6f578"]]},{"id":"d263b855.a64e","type":"comment","z":"e22fb2e7.988f48","name":"Have to make multiple calls at random times or it wont work","info":"","x":929,"y":178,"wires":[]},{"id":"d1d2392c.0d8c9","type":"server","z":"","name":"DUMMY_NAME","url":"DUMMY_URL","pass":"DUMMY_PW"}]

HomeAudioCard

1 Like

Hi,

Great peice of work by the way.

Does anyone know how to remove unwanted alexa connected devices such as these?

image

Lol ty

If you remove the Media players from your views it should hide it, I use Lovelace I absolutely love it!

What fixed it?

Here’s how I have been limiting this component to only update for ‘online’ devices.

Find line 212

for device in devices: 

Add the following code below it so it looks like the following:

        for device in devices:

            if device['online'] is False:
                continue

You could also try the following to only return ‘ECHO’ devices:

        for device in devices:

            if device['deviceFamily'] != 'ECHO':
                continue
3 Likes

Is there any way to play your own music on the Echo?

I see that there is no way to upload your own music to the Amazon music library since April 30th.

Is there (or can there be…) a local option?

Yah looks like everything has to be streamed now unless you’re using Bluetooth

I’ve discovered an issue, but I believe it’s just how the echos work and not sure if there is anything that can be done about it. So I have two echo’s near each other. They work as they are supposed to, so sometimes when I say “Alexa, go XXX” they both light up, one decides is closer and does its thing.

I created a simple TTS script that fires when I turn on an input boolean. I created a routine with alexa so I can say Alexa where is person X. If the echo that I wanted to speak the TTS happened to “turn on” it will not speak the TTS. I’ve even added delays, but have been unable to get it to speak. If I whisper quielty into a different alexa, it will speak the message.

Anyone else had this issue and figured out how to get it to work?

EDIT: Maybe not what I thought. For some reason my Echo Show seems to be flaking out. Sometimes it will play a TTS and other times not.

Using deviceFamily worked perfectly to limit only to my Echo’s. Thanks.

Works good, but also excluded my Spot and Show.

I feel like there is a bug with echo shows and TTS

- alias: Where is Tracy
  trigger:
  - platform: state
    entity_id: input_boolean.wheres_tracy
    to: 'on'
  condition:
  - condition: numeric_state
    entity_id: sensor.ha_runtime_in_minutes
    above: 1
  action:
  - service: input_boolean.turn_off
    entity_id:
      - input_boolean.wheres_tracy
  - service: script.audio_notify
    data_template:
      tts_msg: "Tracy is at {{ states('device_tracker.tracy_all') }} and is approximately {{ states('sensor.tracys_time_to_home') }} minutes from home."
      mplayer: "kitchen"

If I run this automation/script manually it works perfectly. If I use any alexa to trigger this automation by turning on the input boolean (via an alexa routine) the show fails to speak the text. In the alexa app it shows a “simon says …” for the show, but it is never heard" I have 1st and 2nd gen echos and dots as well as an echo show that all work fine.

Thanks for the pointers.

If I use the services it works like a charm. (json structure)
But I can’t get it encoded in a automation it doesn’t work.

alias: Radio Alexa play kitchen
sequence:
  - service: media_player.play_media
    data:
      entity_id: media_player.kitchen_echo_dot
      media_contend_id: VRT MNM
      media_contend_type: "TUNEIN"

can you please help with this? Maybe I’m overlooking something but I tried almost every format for this automation (With quotes, without, partial quotes, etc)
Thank you for your help.