# Start playback with a relais/GPIO/motion detector?

**URL:** https://discourse.mopidy.com/t/start-playback-with-a-relais-gpio-motion-detector/244
**Category:** Pi MusicBox (archive)
**Created:** [October 10, 2014, 12:36pm UTC](https://discourse.mopidy.com/t/start-playback-with-a-relais-gpio-motion-detector/244 "2014-10-10T12:36:39Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![manwald](https://avatars.discourse-cdn.com/v4/letter/m/7ab992/32.png) [@manwald](https://discourse.mopidy.com/u/manwald)
#### Post date: [October 10, 2014, 12:36pm UTC](https://discourse.mopidy.com/t/start-playback-with-a-relais-gpio-motion-detector/244/1 "2014-10-10T12:36:39Z")

</div>

Hi all,

I’m so glad I found this really awesome project! 👍

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: [http://www.amazon.de/HC-SR501-Infrared-Arduino-Raspberry-HCSR501/dp/B00KDZNJGO](http://www.amazon.de/HC-SR501-Infrared-Arduino-Raspberry-HCSR501/dp/B00KDZNJGO)

I would really appreciate your help 🙂

Best regards  
Mischa

---

<div class="post-metadata">

### Author: ![adamcik](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.mopidy.com/adamcik/32/5_2.png) [@adamcik](https://discourse.mopidy.com/u/adamcik)
#### Post date: [October 11, 2014, 7:58pm UTC](https://discourse.mopidy.com/t/start-playback-with-a-relais-gpio-motion-detector/244/2 "2014-10-11T19:58:43Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![manwald](https://avatars.discourse-cdn.com/v4/letter/m/7ab992/32.png) [@manwald](https://discourse.mopidy.com/u/manwald)
#### Post date: [October 16, 2014, 9:44pm UTC](https://discourse.mopidy.com/t/start-playback-with-a-relais-gpio-motion-detector/244/3 "2014-10-16T21:44:12Z")

</div>

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](http://abyz.co.uk/rpi/pigpio/pigpiod.html) 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!

---

<div class="post-metadata">

### Author: ![9and3r](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.mopidy.com/9and3r/32/1513_2.png) [@9and3r](https://discourse.mopidy.com/u/9and3r)
#### Post date: [October 16, 2014, 10:18pm UTC](https://discourse.mopidy.com/t/start-playback-with-a-relais-gpio-motion-detector/244/4 "2014-10-16T22:18:22Z")

</div>

Hi.  
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!

---

<div class="post-metadata">

### Author: ![manwald](https://avatars.discourse-cdn.com/v4/letter/m/7ab992/32.png) [@manwald](https://discourse.mopidy.com/u/manwald)
#### Post date: [October 16, 2014, 10:38pm UTC](https://discourse.mopidy.com/t/start-playback-with-a-relais-gpio-motion-detector/244/5 "2014-10-16T22:38:28Z")

</div>

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 🙂

I will test it out and report back!

---

<div class="post-metadata">

### Author: ![kingosticks](https://avatars.discourse-cdn.com/v4/letter/k/858c86/32.png) [@kingosticks](https://discourse.mopidy.com/u/kingosticks)
#### Post date: [October 16, 2014, 11:18pm UTC](https://discourse.mopidy.com/t/start-playback-with-a-relais-gpio-motion-detector/244/6 "2014-10-16T23:18:59Z")

</div>

Have you had a look at the pigpio python documentation [http://abyz.co.uk/rpi/pigpio/python.html#callback](http://abyz.co.uk/rpi/pigpio/python.html#callback) ? You can do what you want using that and python-mpd [http://pythonhosted.org/python-mpd2/topics/commands.html#controlling-playback](http://pythonhosted.org/python-mpd2/topics/commands.html#controlling-playback)

---

<div class="post-metadata">

### Author: ![jodal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.mopidy.com/jodal/32/2564_2.png) [@jodal](https://discourse.mopidy.com/u/jodal)
#### Post date: [February 19, 2026, 11:47am UTC](https://discourse.mopidy.com/t/start-playback-with-a-relais-gpio-motion-detector/244/7 "2026-02-19T11:47:55Z")

</div>


