{"id":4276,"date":"2024-10-07T10:25:01","date_gmt":"2024-10-07T15:25:01","guid":{"rendered":"https:\/\/lab.rapternet.us\/?p=4276"},"modified":"2024-09-21T22:34:03","modified_gmt":"2024-09-22T03:34:03","slug":"displaying-currently-playing-music-info","status":"publish","type":"post","link":"https:\/\/lab.rapternet.us\/?p=4276","title":{"rendered":"Displaying Currently Playing Music Info"},"content":{"rendered":"\n<p>I have played with the MAX7219 display a few times in the past but never had a solid project in mind for it. With my whole home audio project though, I realized I can use it for a cool little display showing what&#8217;s currently playing on the system. I&#8217;ll want a slightly larger display to use for a final project, but for now I can play with the automations and back end setup for such a display.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>I&#8217;ve <a href=\"https:\/\/lab.rapternet.us\/?p=3584\">used the MAX7219 previously <\/a>for some demonstration units and have some future projects planned for it, this one is probably one that will also make use of it for a final product too rather than just for some demos here.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Parts <\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.amazon.com\/HiLetgo-MAX7219-Arduino-Microcontroller-Display\/dp\/B07FFV537V?pd_rd_w=TACnL&amp;content-id=amzn1.sym.c75be473-fd9d-40a1-b940-0fbe5f6985d0&amp;pf_rd_p=c75be473-fd9d-40a1-b940-0fbe5f6985d0&amp;pf_rd_r=R7K9P2KSFHZBYRCRYEXT&amp;pd_rd_wg=B51Z4&amp;pd_rd_r=06c9fc4c-db6b-4067-941d-70f550f90f27&amp;pd_rd_i=B07FFV537V&amp;psc=1&amp;ref_=pd_bap_m_grid_dv_rp_0_1_ec_ppx_yo2_mob_b_ts_rp_2_t\" target=\"_blank\" rel=\"noreferrer noopener\">Max7219 display<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.amazon.com\/ESP8266-Internet-Development-Wireless-Micropython\/dp\/B07RNX3W9J?pd_rd_w=n5s2n&amp;content-id=amzn1.sym.b854a5c2-4475-41f8-a6d4-df92b2868104&amp;pf_rd_p=b854a5c2-4475-41f8-a6d4-df92b2868104&amp;pf_rd_r=CJ11Z5WMAQHD1VJPSME4&amp;pd_rd_wg=WMXre&amp;pd_rd_r=f3ba372f-b400-4c47-972b-13fc3e13e9ef&amp;pd_rd_i=B07RNX3W9J&amp;psc=1&amp;ref_=pd_basp_m_rpt_ba_s_4_sc\">Esp8266<\/a> or ESP32<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Getting Attribute Data<\/h2>\n\n\n\n<p>We need to first know what attributes we want to grab from the media player and display on our screen. To get the list of available attributes, we can to go to the developer tools -&gt; states. From here, we find the media player we want to gather data from and take a look at what&#8217;s available for information. For this, I&#8217;ll be looking at my music assistant group player.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"490\" src=\"https:\/\/lab.rapternet.us\/wp-content\/uploads\/2024\/09\/image-24-1024x490.png\" alt=\"\" class=\"wp-image-4279\" srcset=\"https:\/\/lab.rapternet.us\/wp-content\/uploads\/2024\/09\/image-24-1024x490.png 1024w, https:\/\/lab.rapternet.us\/wp-content\/uploads\/2024\/09\/image-24-300x143.png 300w, https:\/\/lab.rapternet.us\/wp-content\/uploads\/2024\/09\/image-24-768x367.png 768w, https:\/\/lab.rapternet.us\/wp-content\/uploads\/2024\/09\/image-24-1536x735.png 1536w, https:\/\/lab.rapternet.us\/wp-content\/uploads\/2024\/09\/image-24.png 1936w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><figcaption class=\"wp-element-caption\">Developer Tools &#8211; States<\/figcaption><\/figure>\n\n\n\n<p>The key components I wanted to display are the band and song title, which are media_title and media_artist according to the state list. These will be used in my automation to set the text on the screen.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Automation<\/h2>\n\n\n\n<p>For the automation, I&#8217;m using two triggers with trigger IDs. The first is when the speaker group is turned on or off. This will be used to clear the display either when the music is stopped playing or prior to starting it. The second trigger is when the media title being played changes. This is the song title changing that we want to display.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"955\" src=\"https:\/\/lab.rapternet.us\/wp-content\/uploads\/2024\/09\/image-25-1024x955.png\" alt=\"\" class=\"wp-image-4280\" srcset=\"https:\/\/lab.rapternet.us\/wp-content\/uploads\/2024\/09\/image-25-1024x955.png 1024w, https:\/\/lab.rapternet.us\/wp-content\/uploads\/2024\/09\/image-25-300x280.png 300w, https:\/\/lab.rapternet.us\/wp-content\/uploads\/2024\/09\/image-25-768x717.png 768w, https:\/\/lab.rapternet.us\/wp-content\/uploads\/2024\/09\/image-25.png 1494w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><figcaption class=\"wp-element-caption\">Trigger<\/figcaption><\/figure>\n\n\n\n<p>I decided on the string format for the output as shown below. The original display that I&#8217;m showing this on is a small digital display that needs to scroll the text to show it all. The pipe character is to add a delimiter between the song and artist while it scrolls. Similarly it could have been a number of spaces as well, or if I were showing this on a longer display or one that text can&#8217;t scroll on, it could have skipped that delimiter all together.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"> | Band: Song<\/pre>\n\n\n\n<p>Putting that format into the text field in home assistant, we get the crazy template below.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"366\" src=\"https:\/\/lab.rapternet.us\/wp-content\/uploads\/2024\/09\/image-22-1024x366.png\" alt=\"\" class=\"wp-image-4277\" srcset=\"https:\/\/lab.rapternet.us\/wp-content\/uploads\/2024\/09\/image-22-1024x366.png 1024w, https:\/\/lab.rapternet.us\/wp-content\/uploads\/2024\/09\/image-22-300x107.png 300w, https:\/\/lab.rapternet.us\/wp-content\/uploads\/2024\/09\/image-22-768x274.png 768w, https:\/\/lab.rapternet.us\/wp-content\/uploads\/2024\/09\/image-22.png 1531w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><figcaption class=\"wp-element-caption\">Action<\/figcaption><\/figure>\n\n\n\n<p>The yaml text for the automation in whole is below.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">action: input_text.set_value<br \/>target:<br \/>  entity_id: input_text.esphome_display_text<br \/>data:<br \/>  value: \" | {{ state_attr('media_player.all_airplay','media_artist') }}: {{ state_attr('media_player.all_airplay','media_title') }}\"<br \/><\/pre>\n\n\n\n<p>With this setup, we get the following output when playing a Green Day song.<\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"300\" height=\"237\" data-id=\"4288\" src=\"https:\/\/lab.rapternet.us\/wp-content\/uploads\/2024\/09\/image_editor_output_image-29843563-17264898014307720159074000514772-300x237.jpg\" alt=\"\" class=\"wp-image-4288\" srcset=\"https:\/\/lab.rapternet.us\/wp-content\/uploads\/2024\/09\/image_editor_output_image-29843563-17264898014307720159074000514772-300x237.jpg 300w, https:\/\/lab.rapternet.us\/wp-content\/uploads\/2024\/09\/image_editor_output_image-29843563-17264898014307720159074000514772.jpg 461w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"344\" height=\"273\" data-id=\"4290\" src=\"https:\/\/lab.rapternet.us\/wp-content\/uploads\/2024\/09\/image_editor_output_image-1903228644-1726489831516205050635438048971.jpg\" alt=\"\" class=\"wp-image-4290\" srcset=\"https:\/\/lab.rapternet.us\/wp-content\/uploads\/2024\/09\/image_editor_output_image-1903228644-1726489831516205050635438048971.jpg 344w, https:\/\/lab.rapternet.us\/wp-content\/uploads\/2024\/09\/image_editor_output_image-1903228644-1726489831516205050635438048971-300x238.jpg 300w\" sizes=\"auto, (max-width: 344px) 100vw, 344px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"409\" height=\"275\" data-id=\"4289\" src=\"https:\/\/lab.rapternet.us\/wp-content\/uploads\/2024\/09\/image_editor_output_image1639547107-17264898186321644595347681933501.jpg\" alt=\"\" class=\"wp-image-4289\" srcset=\"https:\/\/lab.rapternet.us\/wp-content\/uploads\/2024\/09\/image_editor_output_image1639547107-17264898186321644595347681933501.jpg 409w, https:\/\/lab.rapternet.us\/wp-content\/uploads\/2024\/09\/image_editor_output_image1639547107-17264898186321644595347681933501-300x202.jpg 300w\" sizes=\"auto, (max-width: 409px) 100vw, 409px\" \/><\/figure>\n<\/figure>\n\n\n\n<p>It works pretty well, and would work out really well with more MAX7219 panels together, maybe 8 instead of 4, or with two lines. Use one line of the display for the artist and one for the song name. In either case, I&#8217;ll be holding onto this to make use of later as I continue building out my whole home audio system.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have played with the MAX7219 display a few times in the past but never had a solid project in mind for it. With my whole home audio project though, I realized I can use it for a cool little display showing what&#8217;s currently playing on the system. I&#8217;ll want a slightly larger display to &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/lab.rapternet.us\/?p=4276\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Displaying Currently Playing Music Info&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":4291,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[105,74,39,49],"class_list":["post-4276","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-how-to","tag-audio","tag-esphome","tag-home-assistant","tag-smart-home"],"_links":{"self":[{"href":"https:\/\/lab.rapternet.us\/index.php?rest_route=\/wp\/v2\/posts\/4276","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lab.rapternet.us\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lab.rapternet.us\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lab.rapternet.us\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lab.rapternet.us\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4276"}],"version-history":[{"count":10,"href":"https:\/\/lab.rapternet.us\/index.php?rest_route=\/wp\/v2\/posts\/4276\/revisions"}],"predecessor-version":[{"id":4346,"href":"https:\/\/lab.rapternet.us\/index.php?rest_route=\/wp\/v2\/posts\/4276\/revisions\/4346"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lab.rapternet.us\/index.php?rest_route=\/wp\/v2\/media\/4291"}],"wp:attachment":[{"href":"https:\/\/lab.rapternet.us\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4276"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lab.rapternet.us\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4276"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lab.rapternet.us\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4276"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}