Start playback with a relais/GPIO/motion detector?

Hi all,

I’m so glad I found this really awesome project! :thumbsup:

What I wanted is a small WLAN-playback-solution for my guest-restroom.
There is already a 230V-motion detector installed which turns on some LEDs when one enters the room.

The motion detector switches a wall socket with two power outlets, where one is used for the power supply of the LEDs.

First I thought about letting the Pi being booted up everytime and simply cut the power by the motion detector when the room is empty, but I figured out that it lasts about one minute for the music to start. But I want the music to start instantly.

So I’m looking for another solution now - maybe you can help me?!

Is there a way for maybe let a 230V-relais being switched by the motion detector and using its signal on one of the GPIO-pins of the Pi? Additionally I then need a way to monitor this signal and turn the music on or off.

Another idea is to use an extra PIR, like this:

I would really appreciate your help :slight_smile:

Best regards

It does indeed sound like you just want to leave the PI on, and then either have a custom plugin in mopidy which handles GPIO, or more likely some external program that does GPIO and then talks to mopidy over MPD protocol, JSON RPC over HTTP requests or Websockets.

As for the electrical engineering part my experience is limited, but you might be able to rig something up with an optocoupler as I wouldn’t like mixing 230V and the GPIO pins which I assume are 5V.

Thank you very much. Now I found out something more to make my idea work.

I will use a simple 5V power supply on my motion detector with some ohmic resistances connected to GND and GPIO4.
Combined with a the pigpio-library I hopefully will be able to read out if GPIO4 has current or net.

Now I only need to know which command I have to use to start or stop the stream in dependency of the current?

As I’m really now to Linux and the Raspberry Pi I would really appreciate any help with programming the pigpio-routines and the necessary commands for Pi MusicBox.

Thanks a lot!

I think that Raspberry Pi GPIO inputs are 3.3v (I am not sure. But check it just in case).
For the software part you can develop an extension or simply use MPD commands.

A command line MPD you can use is ncmpcpp:
sudo apt-get install ncmpcpp
ncmpcpp play
ncmpcpp pause
ncmpcpp stop

Hope it helps!

1 Like

You’re right, GPIO inputs are 3.3V, the 5V power-supply with the ohmic resistances fits this need!

Thanks a lot for your idea - a simple ‘ncmpcpp play’ starts the selected stream and ‘ncmpcpp stop’ stops it? No other commands or actions are needed?

Do you also how I can program an interrupt-routine with pigpio to control the state of the GPIO and start or stop the stream?

This would be really great and simplifys everything :slight_smile:

I will test it out and report back!

Have you had a look at the pigpio python documentation ? You can do what you want using that and python-mpd