Mopidy, MusicBox WebClient, autostart

Hi there,

I’m having issues with Mopidy. I’m trying to setup my pirate audio board so it immediately plays a song on boot. However, because I installed Musicbox as a WebClient for Mopidy ( using this command : sudo python3 -m pip install Mopidy-MusicBox-Webclient) I don’t have a file that I can edit.

To make my question even clearer : how can I setup some sort of autostart on Mopidy?

Thanks in advance !

It’s difficult to answer, because many things depends on your particular system setup.

Basically what I would do is, at after booting :

  • start mopidy
  • use a command line client to add a song and play it

To autorun programs at boot, there are basically two solutions:

  • run as the program a systemd service
  • autologin a user and have that user autostart the program

Another thing to take into consideration is that mopidy likely takes some seconds to start, so you would have to add some delay between mopidy startup and the client commands.

1 Like

My exact setup is :
Hardwarewise :
-raspberry pi zero v1.3
-wifi dongle
-Pirate audio board
-sandisk ultra 16gb 10A1

-raspbian buster with desktop
-slightly modified script for pirate audio : instead of installing Iris install musicbox
(Link to the actual file :

Do you have any tutorial that would explain how to do what you think would be best?

Thanks and sorry for the late reply,
Take care!

Ok so it appears you are running mopidy with a systemd service (you can see that with all the systemctlcommands in the install script.
I thing the easiest way to go would be to create a custom service that would sleep for a while, then add a song and trigger playback. For this you need :

  1. install mopidy-mpd, and mpc
  2. Configure mpc to connect it with mopidy (i guess)
  3. Write and save a script like
#! /bin/bash
sleep 10
mpc add "some song"
mpc play
  1. Make the script executable: chmod +x /path/to/
  2. Write a systemd service file like
  1. Save the service file in /etc/systemd/system/autoplay.service
  2. You can test if the service works using systemctl start autoplay, which should trigger the song after 10 seconds (addapt to your needs)
  3. To enable the script and run it at each startup, run systemctl enable autoplay in a terminal.

I might have forgotten a step or made some mistakes, but that should be the general idea.

1 Like

Thanks a lot dude, it worked !
just had to add this to the service sript to be able to enable it :
Description=Automatically play a song on boot


while the [Unit] part is not required, the [Install] section is required to enable the service.

Thanks a lot for your time !!
Take care !

Nice, glad you made it work !

1 Like

So I finally (almost) completed my project ! you can check it out here :

That is cool. I wanted to do something just like this but failed at the crucial step of actually doing it… so kudos to you! I like the idea of holding the button for longer to initiate a safe shutdown - that is neat. Have you considered suggesting they add this support to the project?

Your instruction in the readme:

sudo apt-get install mpd-mopidy mpc -y

is wrong as there’s no such package as mpd-mopidy. It should read:

sudo apt-get install mopidy-mpd mpc -y

(it’s already correct in your script).

You’ve got some typos in each of the occurrences of Pimoroni in the readme. And also note that the Raspberry Pi Foundation are very protective of their logo, you might have noticed you don’t see it used outside of their official stuff. If they see it they will, not unreasonably, ask you to remove it.

If you find your work to be used in my project and want a shout out, feel free to contact me.

Can Mopidy itself have a shout out? :slight_smile:

EDIT: Are you working on a case or anything? Your README would be even better with some pictures!

Got it, I’ll give mopidy a shout out in the thanking section. Thanks for the corrections, I’ll make sure I edit this today !
Let’s hope that raspberry doesn’t see it then :crossed_fingers::wink:

I’m not working on a case currently, it is not my priority and I’m not even sure I’ll work on one someday… I’ll try to add some pictures if I find some relevant ones :blush: