{"id":4996,"date":"2020-12-16T15:35:31","date_gmt":"2020-12-16T15:35:31","guid":{"rendered":"https:\/\/robertjwallace.com\/?p=4996"},"modified":"2023-07-18T23:22:50","modified_gmt":"2023-07-18T23:22:50","slug":"creating-home-assistant-interface-to-alexa-playlists","status":"publish","type":"post","link":"https:\/\/robertjwallace.com\/es\/creating-home-assistant-interface-to-alexa-playlists\/","title":{"rendered":"Creaci\u00f3n de una interfaz de asistente de hogar para listas de reproducci\u00f3n de Alexa"},"content":{"rendered":"<h2 class=\"wp-block-heading\">Goal: <\/h2>\n\n\n\n<p>Use Home Assistant to use Amazon Echo to play Amazon Music playlists<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Resources used:<\/h2>\n\n\n\n<p>Home Assistant Community Store \u2013 <a href=\"https:\/\/github.com\/custom-components\/alexa_media_player\" target=\"_blank\" rel=\"noreferrer noopener\">Alexa Media Player<\/a><\/p>\n\n\n\n<!--more-->\n\n\n\n<p>Mini Media Player card &#8211; <a href=\"https:\/\/github.com\/kalkih\/mini-media-player\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/github.com\/kalkih\/mini-media-player<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Steps:<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>Install Alexa Media Player &#8211; <a href=\"https:\/\/github.com\/custom-components\/alexa_media_player\/wiki\">https:\/\/github.com\/custom-components\/alexa_media_player\/wiki<\/a><br><br>This was a bit of a pain in the ass, getting the two factor authorization set up but I finally got it working.  You need to follow the instructions carefully.<br><\/li><li>Install the Mini Media Player &#8211; <a href=\"https:\/\/awesomeopensource.com\/project\/kalkih\/mini-media-player#shortcut-item-object\">https:\/\/awesomeopensource.com\/project\/kalkih\/mini-media-player#shortcut-item-object<\/a><br><\/li><li>I used the example card from the documentation in step 2 with gave me a text input field to send a message for the echo to play.  While this was interesting, it is not very useful by itself.  But I have noticed how often the Echo device will trigger on normal conversation when it hears it&#8217;s own keyword &#8220;alexa&#8221; spoken on the TV for example.  So I typed into the text input field &#8220;Alexa play my country playlist on echo living room&#8221;, and hit the send button.  A moment later, the echo played the message, recognized it as an echo command, and played the playlist.  <br><br>Now I have multiple echo devices, and the &#8220;living room&#8221; echo played the command, and a second echo device &#8220;heard&#8221; it and executed the command.  But I suspect that this might not work with a single echo.<br><\/li><li>So now I had to by-pass the text input field.  I didn&#8217;t want to have to type a command each time I wanted to play music.  With a lot of internet searching I finally pieced all of the parts together.  What I wanted on the mini media player card was a list of buttons, each one for a play list:<\/li><\/ul>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"521\" height=\"289\" data-src=\"https:\/\/robertjwallace.com\/wp-content\/uploads\/2020\/12\/playlist.jpg\" alt=\"\" class=\"wp-image-4997 lazyload\" data-srcset=\"https:\/\/robertjwallace.com\/wp-content\/uploads\/2020\/12\/playlist.jpg 521w, https:\/\/robertjwallace.com\/wp-content\/uploads\/2020\/12\/playlist-300x166.jpg 300w\" data-sizes=\"(max-width: 521px) 100vw, 521px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 521px; --smush-placeholder-aspect-ratio: 521\/289;\" \/><\/figure><\/div>\n\n\n\n<p><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>After many false starts I figured out I needed to create a series of scripts, one for each playlist, and then call the scripts from the shortcuts object of the mini media player.<\/li><\/ul>\n\n\n\n<p>Here is the code (manually entered) that creates the mini media player card shown above.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>type: 'custom:mini-media-player'\nentity: media_player.echo_living_room\nicon: 'mdi:amazon'\nartwork: cover\nshortcuts:\n  columns: 1\n  buttons:\n    - icon: 'mdi:cat'\n      name: Country playlist\n      type: script\n      id: message_alexa_country\n    - icon: 'mdi:cat'\n      name: French playlist\n      type: script\n      id: message_alexa_french\ntts:\n  platform: alexa\n  enity_id: media_player.echo_living_room\n<\/code><\/pre>\n\n\n\n<p>Note that I kept the tts: entry which shows the text input box.  That isn&#8217;t needed but I figured why not keep it for fun.  The key parts are the buttons with and type: script. This code is entered in to the input box you get when creating a manual card.  Briefly, when you are editing the interface and hit the &#8220;add card&#8221; button, scroll down to the bottom of the list of pre-defined cards and click the &#8220;Manual&#8221; link.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"472\" height=\"141\" data-src=\"https:\/\/robertjwallace.com\/wp-content\/uploads\/2020\/12\/manual.jpg\" alt=\"\" class=\"wp-image-4999 lazyload\" data-srcset=\"https:\/\/robertjwallace.com\/wp-content\/uploads\/2020\/12\/manual.jpg 472w, https:\/\/robertjwallace.com\/wp-content\/uploads\/2020\/12\/manual-300x90.jpg 300w\" data-sizes=\"(max-width: 472px) 100vw, 472px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 472px; --smush-placeholder-aspect-ratio: 472\/141;\" \/><figcaption>link to manually create a Lovelace card<\/figcaption><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"331\" height=\"194\" data-src=\"https:\/\/robertjwallace.com\/wp-content\/uploads\/2020\/12\/manualcard.jpg\" alt=\"\" class=\"wp-image-5000 lazyload\" data-srcset=\"https:\/\/robertjwallace.com\/wp-content\/uploads\/2020\/12\/manualcard.jpg 331w, https:\/\/robertjwallace.com\/wp-content\/uploads\/2020\/12\/manualcard-300x176.jpg 300w\" data-sizes=\"(max-width: 331px) 100vw, 331px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 331px; --smush-placeholder-aspect-ratio: 331\/194;\" \/><figcaption>Text box for defining the card code<\/figcaption><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Scripts<\/h2>\n\n\n\n<p>The next part was coding the scripts.  This code is in the scripts.yaml file.  I use the visual studio code editor for Home Assistant: <a href=\"https:\/\/community.home-assistant.io\/t\/home-assistant-community-add-on-visual-studio-code\/107863\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/community.home-assistant.io\/t\/home-assistant-community-add-on-visual-studio-code\/107863<\/a><\/p>\n\n\n\n<p>The script code looks like:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>message_alexa_country:\n  sequence:\n    - service: notify.alexa_media_echo_living_room\n      data:\n        target:\n          - alexa_media_echo_living_room\n        data:\n          type: tts\n        message: &gt;\n          {{- \"Alexa play country playlist on echo living room\" -}}\nmessage_alexa_french:\n  sequence:\n    - service: notify.alexa_media_echo_living_room\n      data:\n        target:\n          - alexa_media_echo_living_room\n        data:\n          type: tts\n        message: &gt;\n          {{- \"Alexa play french playlist on echo living room\" -}}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Issues and next steps<\/h2>\n\n\n\n<p>This probably requires that you have two echo devices.  I happen to have five in my house so when one speaks the text to speech command, another one hears it and executes the command.  I need to test to see if this works with only one echo device.<\/p>\n\n\n\n<p>The echo device miss-hears the commands.  This seems to be a problem with the echo.<\/p>\n\n\n\n<p>If music is already streaming the echo asks if you want to stop the streaming.<\/p>\n\n\n\n<p>I would like to call the scripts with parameters so I don&#8217;t have to create a new script for each new playlist.<\/p>","protected":false},"excerpt":{"rendered":"<p>Goal: Use Home Assistant to use Amazon Echo to play Amazon Music playlists Resources used: Home Assistant Community Store \u2013 Alexa Media Player<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","_eb_attr":"","footnotes":""},"categories":[143,166],"tags":[],"class_list":["post-4996","post","type-post","status-publish","format-standard","hentry","category-computer-stuff","category-home-assistant"],"featured_image_src":null,"featured_image_src_square":null,"author_info":{"display_name":"Bob","author_link":"https:\/\/robertjwallace.com\/es\/author\/admin\/"},"_links":{"self":[{"href":"https:\/\/robertjwallace.com\/es\/wp-json\/wp\/v2\/posts\/4996","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/robertjwallace.com\/es\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/robertjwallace.com\/es\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/robertjwallace.com\/es\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/robertjwallace.com\/es\/wp-json\/wp\/v2\/comments?post=4996"}],"version-history":[{"count":5,"href":"https:\/\/robertjwallace.com\/es\/wp-json\/wp\/v2\/posts\/4996\/revisions"}],"predecessor-version":[{"id":5024,"href":"https:\/\/robertjwallace.com\/es\/wp-json\/wp\/v2\/posts\/4996\/revisions\/5024"}],"wp:attachment":[{"href":"https:\/\/robertjwallace.com\/es\/wp-json\/wp\/v2\/media?parent=4996"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/robertjwallace.com\/es\/wp-json\/wp\/v2\/categories?post=4996"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/robertjwallace.com\/es\/wp-json\/wp\/v2\/tags?post=4996"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}