Giter Site home page Giter Site logo

shairport-power's Introduction

shairport-power

Background

I recently got and old pair of speakers, and wanted to set them up to stream wirelessly with AirPlay. One of the best ways to do this with 3rd-party software seems to be to run shairport-sync on a Raspberry Pi.

However, it turned out that my speakers had a bit of a "hum" when no audio was playing, so I needed a way to switch them off when not in use. Also saving a couple of watts of power.

The finished product

(Youtube Video)

Video of it switching off

Ingredients

Controlling the power

Circuit diagram

The starting point was this question which seemed to do something I wanted. Shairport-sync has a feature which runs a script when music starts or stops, and this was perfect for controlling the power.

I set up the python script to take an ON or OFF parameter and control the relay switch.

I used pins 4, 6, 8 and 10 on the Raspberry Pi (more convenient, as they're next to each other). Pin 4 supplies power at 5V. Pin 6 is ground, and pin 8 is the I/O for the switch. Pin 10 is connected to a second relay in case I decide to add something else to the system later on.

Raspi GPIO

I ran the wires through the conveniently sized holes in the case, to keep them safe in case they catch on anything.

Then I set up the relay connection in a little plastic box on the other end.

Top of the relay

And closed it up...

Closed Box

As you can see on the outside, I split the power cable to the speakers, and spliced the relay in the middle of the live wire.

Configuring the software

I chose the Python GPIO library because the pin state is retained after the script exits. This isn't the case with gpiozero (a popular, simpler alternative).

Finally I had to change some configuration parameters in shairport-sync to point to my scripts:

...
sessioncontrol =
{
  run_this_before_play_begins = "/home/pi/shairport-power/scripts/gpioControl.py ON";
  run_this_after_play_ends = "/home/pi/shairport-power/scripts/gpioControl.py OFF";
...

And restarted the shairport-sync service. On the first run this didn't work, with a syslog error:

RuntimeError: No access to /dev/mem.  Try running as root!

This requires a solution to fix permissions for the shairport-sync user. The following will grant the shairport-sync user permission to use gpio:

sudo adduser shairport-sync gpio

And then a system restart applies the change. Worked the next time around!

shairport-power's People

Contributors

skhg avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.