Basic question about controlling Mopidy

I’ve set up a Pimoroni Pirate Audio (amp) for playing rain sounds when the kids sleep, and using the controls to play/pause and adjust volume (display is disabled - it’s too bright at nighttime.

The issue is that whenever the Pi Zero reboots, I need to manually load the file that contains the rain sounds (e.g., via my phone). But for this, the Pi needs to be connected to wi-fi. That’s fine when we’re at home, but it means I can’t easily bring it elsewhere.

I’m trying to figure out how to load the file automatically in some way. My initial thought was to send some command and run a small script via cron. But I really have trouble finding what that command should be.

I’ve read about JSON-RPC, but I just can’t wrap my head around how it works.

Any help is greatly appreciated!

Could you set your phone as a wifi hotspot and operate the Pi through that for when you are away?

Or try using cron and mpc to play it 5 mins after reboot, to let the system come up.

@reboot sleep 300 mpc add “name and path of your track here”;mpc play

You may need to install mpc and mopidy-mpd I’m also not sure if Mopidy waits indefinitely for the network before it loads, therefore without a network it won’t actually load.

Thanks! Good points.

Regarding your second reply, how is using mpc and mopidy-mpd different from using JSON-RPC?

I don’t know, I’ve never used JSON-RPC, always stuck with MPC as I have very little programing knowledge and MPC just does what I’ve wanted it to do.
Have a look at this page for another idea on how to implement it

1 Like

Thanks a lot! Much appreciated. That should get me started.

There’s also this discussion, which is a bit more complicated, but more “stable”.

2 Likes

Thank you, that’s something else I’ve learned to do!! Was getting frustrated with it, but then increased the sleep time to 3 minutes and it worked perfectly.