{"id":20,"date":"2022-07-04T15:13:59","date_gmt":"2022-07-04T20:13:59","guid":{"rendered":"https:\/\/blog.lfps64.com\/?p=20"},"modified":"2022-07-06T08:08:05","modified_gmt":"2022-07-06T13:08:05","slug":"configuring-media-player-daemon-on-the-xiaomi-gateway-3","status":"publish","type":"post","link":"https:\/\/blog.lfps64.com\/?p=20","title":{"rendered":"Configuring Media Player Daemon on the Xiaomi Gateway 3"},"content":{"rendered":"<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"1024\" src=\"https:\/\/blog.lfps64.com\/wp-content\/uploads\/2022\/07\/IMG_20220704_144604-1024x1024.jpg\" alt=\"\" class=\"wp-image-22\" srcset=\"https:\/\/blog.lfps64.com\/wp-content\/uploads\/2022\/07\/IMG_20220704_144604-1024x1024.jpg 1024w, https:\/\/blog.lfps64.com\/wp-content\/uploads\/2022\/07\/IMG_20220704_144604-300x300.jpg 300w, https:\/\/blog.lfps64.com\/wp-content\/uploads\/2022\/07\/IMG_20220704_144604-150x150.jpg 150w, https:\/\/blog.lfps64.com\/wp-content\/uploads\/2022\/07\/IMG_20220704_144604-768x768.jpg 768w, https:\/\/blog.lfps64.com\/wp-content\/uploads\/2022\/07\/IMG_20220704_144604-1536x1536.jpg 1536w, https:\/\/blog.lfps64.com\/wp-content\/uploads\/2022\/07\/IMG_20220704_144604.jpg 2048w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><figcaption>DGNWG05LM \/ ZHWG11LM<\/figcaption><\/figure><\/div>\n\n\n<p>Before beginning, It&#8217;s worth noting I&#8217;ve already flashed OpenWRT on my Xiaomi Gateway 3 <strong>(DGNWG05LM \/ ZHWG11LM)<\/strong><\/p>\n\n\n\n<p>I&#8217;m assuming you&#8217;ve flashed already OpenLumi on your gateway, if you haven&#8217;t, please follow the guides below to do it:<\/p>\n\n\n\n<p>This is how you root it: <br><a href=\"https:\/\/openlumi.github.io\/gain_root.html\n\">https:\/\/openlumi.github.io\/gain_root.html<br><\/a>And this is how you flash OpenWRT on it:<br><a href=\"https:\/\/openlumi.github.io\/\">https:\/\/openlumi.github.io\/<\/a><\/p>\n\n\n\n<p>Once your device is rooted, flashed with OpenWRT and you have ssh access to it, you&#8217;ll find your Xiaomi Gateway has become pretty useless unless you have an actual plan for it. (As it was my case)<\/p>\n\n\n\n<p>In my case, I wanted to be able to push media files and TTS messages to the gateway using Home Assistant and Node-Red. I&#8217;ll try to explain the Node-Red part in a separate post, but for the time being, I&#8217;ll focus on the MPD Server setup.<\/p>\n\n\n\n<p>A great part of what I&#8217;m doing<a rel=\"noreferrer noopener\" href=\"https:\/\/openlumi.github.io\/wiki\/ru\/faq\/general\/how-do-i-set-up-music-player-daemon.html\" data-type=\"URL\" data-id=\"https:\/\/openlumi.github.io\/wiki\/ru\/faq\/general\/how-do-i-set-up-music-player-daemon.html\" target=\"_blank\"> is based on a guide I&#8217;ve found in Russian<\/a>, but I&#8217;ve found it hard to understand so I thought it would be a good idea to write this one in another language.<\/p>\n\n\n\n<p>After you&#8217;ve managed to gain root access, you need to begin by installing some packages on your gateway, to do this we will run on the terminal :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>opkg update &amp;&amp; opkg install node git-http mpg123 mpc mpd-full\n<\/code><\/pre>\n\n\n\n<p>Once you do, we need to create the files and directories for MPD to work, so go ahead and type in your gateway&#8217;s terminal:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd \/\nmkdir mpd\ncd mpd \nmkdir music\nmkdir playlists\ntouch database\ntouch log\ntouch \/etc\/mpd.state<\/code><\/pre>\n\n\n\n<p>Once you&#8217;ve done this, we will create the configuration file for MPD, to do this we will make the mpd.conf file on the \/etc\/<\/p>\n\n\n\n<p>I&#8217;ve used &#8220;vi&#8221; for this, if you don&#8217;t know how to use vi to edit files, please check this out: <a href=\"https:\/\/www.redhat.com\/sysadmin\/introduction-vi-editor\">https:\/\/www.redhat.com\/sysadmin\/introduction-vi-editor<\/a><\/p>\n\n\n\n<p>This is how I did it:<\/p>\n\n\n\n<p>I first created a backup of the original file and deleted the original one:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cp \/etc\/mpd.conf \/etc\/mpd.conf.bkp\nrm \/etc\/mpd.conf\n<\/code><\/pre>\n\n\n\n<p>Then, I created my new mpd.conf file with the command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vi \/etc\/mpd.conf<\/code><\/pre>\n\n\n\n<p>Once you&#8217;re ready to edit, you can go ahead and paste the following config info:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\nstate_file \"\/mpd\/state\" # Read the note at the bottom \"How do I set the MPD to keep the volume level?\"\nmusic_directory \"\/mpd\/music\" # Specify the path to the music folder, in my case the mpd folder is in the root\nplaylist_directory \"\/mpd\/playlists\" # Specify the path to the playlists folder, in my case the mpd folder is in the root\ndb_file \"\/mpd\/database\" # Specify the path to the database database, in my case the mpd folder is at the root\n#log_file \"\/mpd\/log\" # Uncomment the line if you want to write to the log\n#log_level \"default\" # Uncomment the line if you want to write to the log\nbind_to_address \"any\"\nport \"6600\"\nuser \"root\"\ngroup \"root\"\nauto_update \"yes\"\nauto_update_depth \"3\"\nfilesystem_charset \"UTF-8\"\nid3v1_encoding \"UTF-8\"\naudio_output {\n  type \"alsa\"\n  name \"My ALSA Device\"\n  device \"hw:0,0\"\n  mixer_type \"software\"\n  mixer_control \"Master\"\n  mixer_device \"default\"\n}<\/code><\/pre>\n\n\n\n<p>After saving it (Remember, to save on vi you need to type ESC and type :wq!, you can check the configuration by typing:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cat \/etc\/mpd.conf<\/code><\/pre>\n\n\n\n<p>And you should have something similar to this:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"979\" height=\"354\" src=\"https:\/\/blog.lfps64.com\/wp-content\/uploads\/2022\/07\/imagen-3.png\" alt=\"\" class=\"wp-image-80\" srcset=\"https:\/\/blog.lfps64.com\/wp-content\/uploads\/2022\/07\/imagen-3.png 979w, https:\/\/blog.lfps64.com\/wp-content\/uploads\/2022\/07\/imagen-3-300x108.png 300w, https:\/\/blog.lfps64.com\/wp-content\/uploads\/2022\/07\/imagen-3-768x278.png 768w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/figure>\n\n\n\n<p>Then to apply the changes run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/etc\/init.d\/mpd stop\n\/etc\/init.d\/mpd start\n<\/code><\/pre>\n\n\n\n<p>After this step, I&#8217;ve uploaded an mp3 file to the \/mpd\/music\/ folder to test the functionality, for obvious reasons I can&#8217;t share that file, but we&#8217;ll call it doorbell.mp3, there are plenty of sites that offer these kinds of files for free.<\/p>\n\n\n\n<p>Now to test if the MPD server is working you can download Auremo from this website:<\/p>\n\n\n\n<p><a href=\"https:\/\/code.google.com\/archive\/p\/auremo\/downloads\">https:\/\/code.google.com\/archive\/p\/auremo\/downloads<\/a><\/p>\n\n\n\n<p>After installing Auremo, make sure you set it up using the IP of your MPD server (Your Gateway&#8217;s IP) to test its functionality, if you can see your mp3 file and you&#8217;re able to play it from your computer, you should be able to make it work on Home Assistant as well.<\/p>\n\n\n\n<p>After that, you should be ready to use your MPD daemon on your home assistant as long as you configure the gateway on your configuration.yaml file, my configuration is similar to this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>media_player:\n  - platform: mpd\n    name: Xiaomi Lumi Gateway (Use whatever name makes you happy)\n    host: 192.168.0.100 (Make sure you use the IP assigned to your gateway and you have a static ip)\n    port: 6600\n    scan_interval: 30<\/code><\/pre>\n\n\n\n<p>After this, restart Home Assistant.<\/p>\n\n\n\n<p>You should now be able to push TTS commands on your Home Assistant by going to:<\/p>\n\n\n\n<p>Settings &gt;&gt; Home Assistant Cloud &gt;&gt; Text to Speech and clicking on &#8220;Try&#8221;<\/p>\n\n\n\n<p>From there, select your newly added Xiaomi Lumi Gateway device and try to make it say a few things. \ud83d\ude42<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"849\" height=\"491\" src=\"https:\/\/blog.lfps64.com\/wp-content\/uploads\/2022\/07\/TTS-Test.png\" alt=\"\" class=\"wp-image-24\" srcset=\"https:\/\/blog.lfps64.com\/wp-content\/uploads\/2022\/07\/TTS-Test.png 849w, https:\/\/blog.lfps64.com\/wp-content\/uploads\/2022\/07\/TTS-Test-300x173.png 300w, https:\/\/blog.lfps64.com\/wp-content\/uploads\/2022\/07\/TTS-Test-768x444.png 768w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/figure>\n\n\n\n<p>Right now, just like this, it&#8217;s ready for me to push commands, in my case I&#8217;ll use it with Node-Red to push alerts and voice commands.<\/p>\n\n\n\n<p>I&#8217;ll be showing how I did this in a later post.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Before beginning, It&#8217;s worth noting I&#8217;ve already flashed OpenWRT on my Xiaomi Gateway 3 (DGNWG05LM \/ ZHWG11LM) I&#8217;m assuming you&#8217;ve flashed already OpenLumi on your gateway, if you haven&#8217;t, please follow the guides below to do it: This is how you root it: https:\/\/openlumi.github.io\/gain_root.htmlAnd this is how you flash OpenWRT on it:https:\/\/openlumi.github.io\/ Once your device &hellip; <a href=\"https:\/\/blog.lfps64.com\/?p=20\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Configuring Media Player Daemon on the Xiaomi Gateway 3&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[7,8,5,6,4],"_links":{"self":[{"href":"https:\/\/blog.lfps64.com\/index.php?rest_route=\/wp\/v2\/posts\/20"}],"collection":[{"href":"https:\/\/blog.lfps64.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.lfps64.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.lfps64.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.lfps64.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=20"}],"version-history":[{"count":15,"href":"https:\/\/blog.lfps64.com\/index.php?rest_route=\/wp\/v2\/posts\/20\/revisions"}],"predecessor-version":[{"id":81,"href":"https:\/\/blog.lfps64.com\/index.php?rest_route=\/wp\/v2\/posts\/20\/revisions\/81"}],"wp:attachment":[{"href":"https:\/\/blog.lfps64.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=20"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.lfps64.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=20"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.lfps64.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=20"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}