Echo Devices (Alexa) as Media Player - Testers Needed

Thanks So Much !! I will give it a try.

Great job here!

How would I add sensor data to the message?

I am guessing you would have to save the sensor data to variables and combine them into a message and pass that onto the alexa node using a funtion node.
this is from my example a few posts above
var name = flow.get(‘name’)
var device = flow.get(‘device’)
var message1 = msg.payload1
var message2 = msg.payload2
var l_loc = flow.get(‘kll’)
var c_loc = flow.get(‘kcl’)
var final_msg = ${name} + ${message1} + ${c_loc} + ${message2} + ${l_loc}
var payload = {“domain”:“notify”,“service”:“alexa_media”,“data”:{“message”:${final_msg},“data”: {“type”:“tts”},“target”:[${device}]}}
msg.payload = payload
return msg;

Please be aware I am no expert when it comes to nodered and I only managed to put that together with lots of trial and error. I imagine there are lots of better ways to do it.

2 Likes

Thanks to itzmrdavis2u for helping me create the following flow to have Alexa speak a sensor changed alert on Alexa.

[{"id":"ceea0455.816a98","type":"change","z":"4c65e40e.fba3bc","name":"Garage Hum","rules":[{"t":"move","p":"payload","pt":"msg","to":"garagehum","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":270,"y":1114,"wires":[["4b60b21f.24fdcc"]]},{"id":"4b60b21f.24fdcc","type":"function","z":"4c65e40e.fba3bc","name":"Create Alexa Alert","func":"var name = \"Alert, \"\nvar device = \"media_player.kitchen\"\nvar message1 = \"Garage humidity is high,,, \"\nvar message2 = \"The garage temperature is,,, \"\nvar l_loc = flow.get('garagehum')\nvar c_loc = flow.get('garagetemp')\nvar final_msg = `${name}` + `${message1}` + `${l_loc}` + `${message2}` + `${c_loc}`\nvar payload = {\"domain\":\"notify\",\"service\":\"alexa_media\",\"data\":{\"message\":`${final_msg}`,\"data\":{\"type\":\"tts\"},\"target\":[`${device}`]}}\nmsg.payload = payload\nreturn msg;\n","outputs":1,"noerr":0,"x":530,"y":1040,"wires":[["f11000e9.44d8e"]]},{"id":"f11000e9.44d8e","type":"api-call-service","z":"4c65e40e.fba3bc","name":"","server":"901e0813.a14178","service_domain":"notify","service":"alexa_media","data":"{\"message\":\"Alet, Alex is moving!\",\"data\":{\"type\":\"tts\"},\"target\":[\"media_player.kitchen\"]}","mergecontext":"","output_location":"","output_location_type":"none","x":610,"y":1160,"wires":[[]]},{"id":"c92ddc2f.2b0cf","type":"server-state-changed","z":"4c65e40e.fba3bc","name":"Garage Humidity ","server":"901e0813.a14178","entityidfilter":"sensor.garage_humidity_2","entityidfiltertype":"exact","outputinitially":true,"state_type":"str","haltifstate":">71","halt_if_type":"num","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"x":80,"y":1120,"wires":[["ceea0455.816a98"],[]]},{"id":"ee71d8bb.f01d28","type":"server-state-changed","z":"4c65e40e.fba3bc","name":"Garage Temperature","server":"901e0813.a14178","entityidfilter":"sensor.garage_temperature","entityidfiltertype":"exact","outputinitially":true,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"x":90,"y":1180,"wires":[["ad5b575d.830f58"]]},{"id":"ad5b575d.830f58","type":"change","z":"4c65e40e.fba3bc","name":"Garage Temp","rules":[{"t":"move","p":"payload","pt":"msg","to":"garagetemp","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":300,"y":1180,"wires":[["4b60b21f.24fdcc"]]},{"id":"901e0813.a14178","type":"server","z":"","name":"Home Assistant rc","legacy":false,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open"}]
1 Like

LOVE THIS PROJECT-

Quick question - i cleaned up my list of Alexa devices in the Alexa online dashboard - How do i get this system to pull the newly updated list and drop the old devices off?

Have you tried restarting Home Assistant? I’m sure that worked for me. Alternatively, if you don’t change your Alexa devices that often, you could use the include_devices option to only include the ones you want (you would need to restart after doing this):

alexa_media:
  accounts:
    - email: !secret alexa_email
      password: !secret alexa_password
      url: amazon.com
      include_devices:
        - "My First Echo"
        - "My Second Echo"
        - "My Third Echo"

Or you can use the exclude_devices option to specifically exclude the ones you don’t want:

alexa_media:
  accounts:
    - email: !secret alexa_email
      password: !secret alexa_password
      url: amazon.com
      exclude_devices:
        - "This Device"
        - "My Alexa Apps"

This is an amazing project!

The only thing is, I can’t get Alexa to play any TTS or Announce announcements at all. Spent all night and finally gave up at 3am this morning. Back on it now :-).
Does anyone know how to debug the response of the Alexa API? According to the debug log, the command is sent correctly to the API, but I don’t see/hear anything on my Echo.

Here’s what I’m trying (via the Service notify.alexa_media):

{ "message":"test", "title":"Testing from HA", "data":{"type":"announce", "method":"all"}, "target":["media_player.******_s_echo_spot"] }

Here’s what I’m seeing in the DEBUG log:

2019-04-19 09:07:19 DEBUG (SyncWorker_11) [custom_components.alexa_media.notify] Converting: <Entity **********'s Echo Spot: standby> to (serialnumbers): G************XG
2019-04-19 09:07:19 DEBUG (SyncWorker_11) [custom_components.alexa_media.notify] Testing item: <Entity **********'s Echo Spot: standby> against (<Entity This Device: standby>, This Device, c****************************5ac, media_player.this_device)
2019-04-19 09:07:19 DEBUG (SyncWorker_11) [custom_components.alexa_media.notify] Announce targets: ['G************1XG'] entities: [<Entity **********'s Echo Spot: standby>]
2019-04-19 09:07:19 DEBUG (SyncWorker_11) [custom_components.alexa_media.notify] a***@********.com: Announce by <Entity ***********'s Echo Spot: standby> to targets: ['G************1XG']: test
2019-04-19 09:07:19 DEBUG (SyncWorker_11) [alexapy.alexaapi] Running sequence: AlexaAnnouncement data: {"behaviorId": "PREVIEW", "sequenceJson": "{\"@type\": \"com.amazon.alexa.behaviors.model.Sequence\", \"startNode\": {\"@type\": \"com.amazon.alexa.behaviors.model.OpaquePayloadOperationNode\", \"type\": \"AlexaAnnouncement\", \"operationPayload\": {\"deviceType\": \"A***********BK\", \"deviceSerialNumber\": \"G**********1XG\", \"locale\": \"en-US\", \"customerId\": \"A***********O\", \"expireAfter\": \"PT5S\", \"content\": [{\"locale\": \"en-US\", \"display\": {\"title\": \"Testing from HA\", \"body\": \"test\"}, \"speak\": {\"type\": \"text\", \"value\": \"test\"}}], \"target\": {\"customerId\": \"A***********O\", \"devices\": [{\"deviceSerialNumber\": \"G***********1XG\", \"deviceTypeId\": \"A************K\"}]}}}}", "status": "ENABLED"}
2019-04-19 09:07:20 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.1813897040] Sending {'id': 18, 'type': 'result', 'success': True, 'result': None}

So by the looks of it, the API call was successful, but no reaction on the Echo Spot whatsoever.

If anyone could point me into the right direction for troubleshooting, this would be highly appreciated.

Thanks

Hey all – I have this installed and “working?” how can i control the source of the media being played to that Amazon device? currently when i click on a Alexa device it just gives me the local speaker option

Look here:

https://github.com/keatontaylor/alexa_media_player/wiki#notable-additional-features

Does it work in the Alexa App? That’s the next place to test since we’re emulating that. Assuming it does:

  • What url region are you using?
  • Do any other functions work with the Echo spot (e.g., media player or tts services)?

As you’ve surmised, it is sending the message to the Echo Spot so we may have limited ability to debug this further without sniffing the packets in the network and comparing it against the official app.

It should automatically add anything new. To delete old entries you’ll need to use the HA entity editor and reboot. The suggestion to exclude or include whatever you want to keep will also help, because the default behavior is to add anything discovered.

Which documentation did you look at? This thread is probably not a good place to look. However, the main README explains there is further documentation in the Wiki which has an installation section. The Wiki is in fact editable by anyone to improve it. Any help in fixing documentation would be appreciated.

1 Like

A very kool and very useful add-on you’ve got here. I’ve incorporated it extensively in my own setup and am very satisfied with it’s function. Thank you!
However (don’t ya just love however’s…)
I have set up an Amazon Alexa multi-room music group defined as “everywhere”. HA picks it up and your add-on does indeed create a media_player.everywhere for me along with one for each of my echos. I can manipulate each media_player attribute as advertized just fine but… here’s the however:
media_player.everywhere ignores me
Everywhere group defined in Amazon verbally works as advertised, but not as an attribute in HA.
Please tell me we found a bug and not that I just did something stupid.

Thanks @alandtse,

  • It’s working perfectly fine in the Alexa App. I can use the ‘Announce’ feature and my echos are responding fine.
  • I’m using amazon.co.uk as URL region
  • The only functions which are working are Pause and Play of currently running Media Streams as well as Volume control. None of the TTS features or Play Media Features (e.g. playing TuneIn) works.

The network capture was my next approach, just trying to figure out how to best do that on the Raspberry Pi. I’m a Windows guy and perfectly fine with Wireshark, but well, Google is your friend :slight_smile:

Do you think it can have anything to do with the en-us language tag which is sent with the API commands? I have already tried to change the language of one of my echos to American English but that also didn’t bring any luck. I’m almost tempted to reset one of the devices and register it against my amazon.de account just for kicks and giggles.

Edit: I have ripped one of my echos out of my amazon.co.uk account and added it to my amazon.de account. Set it up in HA and… exactly the same behaviour. Volume Control and Start/Stop of currently running streams works, any TTS or other media commands don’t work.

I also went down the packet capture route to analyse the API responses, but realised that it was a bit of wasted time setting up a mirroring port on my router, as obviously all of the traffic is encrypted. Any possibility to extract the session key via your integration, so I can load it into wireshark?

Any additional pointers would be highly appreciated.

thanks and happy Easter

You might consider searching this topic for the word “everywhere” as I believe it’s been discussed numerous times.

Well that search advice was almost helpful. There was almost something mentioned about almost having a fix or workaround…
I think I’ll just let my request stand for a bit thankyou.

Known bug. You’re not crazy. Check the link for workarounds.

Thanks for the details.

It might; I’ve always wondered about the region setting but it seems hardcoded in a lot of endpoints. One thing to try is to create announce/tts routines in the Alexa App and investigate it using this endpoint (switch to your url). More details here.

If you determine you have a different locale that works, then we’ll have to fix the alexapy API to provide the proper locale. Please file an issue with details.

@Dixey

see, I told you some here could help you.

:wink:

Ah, you are not alone! I tried to do this yesterday and spent a good few hours trying to work it out,

Think im in the same boat as you, also using amazon.co.uk, Alexa App works etc.

Great to hear I’m not the only one spending his easter weekend trying to figure this out :slight_smile: Good news (although no explicable) is, that since this morning it’s working perfectly fine. Both on my amazon.co.uk account as well as on my amazon.de account. I highly suspect that there was a glitch on Amazon side. I didn’t change anything in my code. This morning all of a sudden I got woken up by Alexa telling me, that the washing machine finished. Kinda made my day even if it’s in a weird way.

Well, there’s good news and bad news. The good one is, that since this morning, it’s working perfectly fine for both my amazon.de as well as my amazon.co.uk account. The bad news is, I cannot explain why this is, as my code didn’t change and also the log entries are still exactly the same. It seems, that @Ian_Hartwell has got the same issues with his amazon.co.uk account. I highly suspect, that there was a glitch on Amazon side. Sorry for wasting your time here.

Ive just tried again and its working!

Though I did it differently, before i was following documentation which said:

Use the notify.alexa_media service and gave example target as “target”:[“group.alexa”, “Guest Room”, “media_player.kitchen”, “serialNumber”]

I therefore made:

Service: notify.alexa_media
Data: {
"message":"Testing",
"data":{"type":"tts"},
"target":["media_player.alexa_media_living_room"]
}

To get it working i actually used:

Service: notify.alexa_media_living_room
Data: {
"message":"Testing",
"data":{"type":"tts"},
"target":["notify.alexa_media_living_room"]
}