element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Pi IoT
  • Challenges & Projects
  • Design Challenges
  • Pi IoT
  • More
  • Cancel
Pi IoT
Blog Pi Control Hub: Music with Mopidy and Home Assistant
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: carmelito
  • Date Created: 22 Aug 2016 3:34 AM Date Created
  • Views 3217 views
  • Likes 3 likes
  • Comments 0 comments
  • home automation
  • picontrolhub
  • piiot
  • piiot challenge
  • music
Related
Recommended

Pi Control Hub: Music with Mopidy and Home Assistant

carmelito
carmelito
22 Aug 2016

My friends where over this friday, and as I was demoing to them the  parts/spokes of the project and showing them Home Assistant UI features, one of them said "Won't it be awesome! if there could be music playing out of the Hub" image, which meant I got to work on Saturday morning trying to install Mopidy, which i have used before with the Pi.. Now,  since Home Assistant uses python 3 and Mopidy use an older version of python , I had to look for a work around. This meant that we will have to install Home Assistant in a virtual environment, which means the python packages you install for Home Assistant won’t interact with the rest of your system and vice-versa, when compared to straight forward installation in the previous blog post - Pi Control Hub: Setting up Home Assistant+Controlling  Philips hue

 

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

In addition to complete the build we will use Adafruits Stereo 3.7W Class D Audio Amplifier - MAX98306 and hook them up to a couple of speakers 2W 8 Ohms speakers as show in the picture below, but you could also connect to your speaker system at home using an audio jack..

 

Here are the steps to follow to complete the setup

#1 Setup the Virtual Environment  and setup up Home Assistant

  Follow details steps at https://home-assistant.io/getting-started/installation-virtualenv/

  And also setup home assistant to start at every boot , follow commands at https://home-assistant.io/getting-started/autostart-systemd/  , here remember to replace pi user with hass , which    you   created as part of setting up the virtual enviroment and install of Home Assistant.

 

#2 Update your configuration.yaml file

  follow the previous blog post to setup configration.yaml file with Sensors and the Philips Hue bulbs, but since we have installed Home Assistant in virtual environment, we will have to follow the    commands below to edit the file in the nano editor

    sudo su -s /bin/bash hass

    cd ~/.homeassistant

    nano configuration.yaml

    exit

  And then to test the changes stop and start Home Assistant using

    sudo systemctl stop home-assistant@hass

    sudo systemctl start home-assistant@hass

image

#3  Now lets install Mopidy

      run the following command

        sudo apt-get install mopidy

     Once installed to check out all the extensions that you install with mopidy run

       apt-cache search mopidy

for more info check out the documentation at  - Installation — Mopidy 2.0.1 documentation

#4 Installing extension, in my case I am using soundcloud

        sudo apt-get install mopidy-soundcloud

     image

     if you have a spotify premium account , you can also install it using - sudo apt-get install mopidy-spotify

 

#5 Ensure that volume is outputed from the audio jack and not the HDMI

        sudo amixer cset numid=3 1

 

#6  Now modify the mopidy.conf to enable the HTTP and MPD

        sudo nano /etc/mopidy/mopidy.conf

      un-comment the http and mpd section and change the hostname section from 127.0.0.1 to 0.0.0.0 , this will allow you top open  mopidy on your browser

        image

      Also un-comment out the souncloud section , if you have installed soundclound and add the API key which you will have to create an app for in the soundcloud developer console.

 

#7   Installing web extension to use with Mopidy

      check out the link and choose the web extension - Web extensions — Mopidy 2.0.1 documentation

      My favorite ones are  Mopidy-Mobile and Mopidy-Simple-Webclient, ideal if you are using a tablet/mobile

            sudo pip install Mopidy-Mobile

            sudo pip install Mopidy-Simple-Webclient

      We are going to use Mopidy-Mobile with Home Assistant as a web panel, in you can create playlist and browse your Pi and Soundclound as shown in the video above.

      And you can use Mopidy-Simple-Webclient ,to give your house guest a link , which will allow them to play your curated playlist , instead of them playing random stuff image..

 

#8  To run mopidy on boot run

       sudo systemctl enable mopidy

    and then reboot your Pi, and to check the status of you install run .And then open url in your browser http://IpAddressOfPi:6680/, you should see the web clients installed.

       sudo service mopidy status

         image

  If you have to stop and start the service , in case you FTP/load mp3 files to your Pi

     sudo systemctl stop mopidy

     sudo mopidyctl local scan

     sudo systemctl stop mopidy

In addition, click the mobile link in the browser and create playlist, which you can then use with the simple-webclient

 

#9 Creating a web panel in Home Assistant to display the Mopidy  mobile web client

      Modify the  configuration.yaml file to add

panel_iframe:
  music:
    title: 'Music'
    icon: 'mdi:music-box-outline'
    url: 'http://192.168.0.32:6680/mobile/index.html#/playback'

         modify the ip address of your Pi, here is how the web panel should look

image

this means you can now create and manage your music inside Home Assistant image ..

 

#10 Setting up Music Player daemon(MPD)

    Now if you want to save a couple of clicks image, instead of going to newly created music tab , you can setup MPD, which will show up in the status tab , and will allow you play your songs from    the   track list and control their volume. Add the following to the configuration.yaml file

#mopidy installed on the Pi
media_player:
  platform: mpd
  server: 127.0.0.1
  port: 6600
  location: Music PiHub

 

image

 

#11 Soldering and connecting audio jack to Audio Amplifier and Lipo battery

 

As part of the final setup, the idea is to have the speaker and Pi run on Lipo's, which means we will need a Lipo charger and  an On/Off switch.

 

{gallery} Circuit to connect the Pi to Speakers

image

Circuit

image

Stereo 3.7W Class D Audio Amplifier - MAX98306 (https://www.adafruit.com/products/987)

image

Adafruit Mini Lipo w/Mini-B USB Jack(https://www.adafruit.com/products/1905) or you can use the micro charges as well

image

Running Mopidy from Home Assistant

image

Tab setup as panel_iframe in the Home-Assistant configuration.yaml file

image

Music Player Daemon (MPD) setup

 

Cut off one end of of female to female jumper and then solder to GND pin on Adafruit Mini Lipo w/Mini-B USB Jack. Then connect the BAT pin to one end of the switch using using bread boarding wire and the other end to female jumper wire.

Now cut the end of your audio cable and connect 2 female jumper wires to the white line and one wire to Left side and the other to the right side.

And then connect negative wire from the Mini Lipo w/Mini-B USB Jack to GND and the positive wire to VDD, as shown in the picture above.

Once you are done with the connections, screw down the speaker in the blue terminal blocks

Now connect the lipo battery and turn on the speakers and connect the audio jack to the phone to test it out..

Also test that your lipo is charging and wait for the lipo to completely charge.

  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube