[How to do instruction] Activate relay upon audio output with python - Printable Version +- Moode Forum (https://moodeaudio.org/forum) +-- Forum: moOde audio player (https://moodeaudio.org/forum/forumdisplay.php?fid=3) +--- Forum: FAQ and Guides (https://moodeaudio.org/forum/forumdisplay.php?fid=9) +--- Thread: [How to do instruction] Activate relay upon audio output with python (/showthread.php?tid=1382) |
Activate relay upon audio output with python - nahventure - 05-13-2019 Have an amp that doesn't feature auto power on/off? Have a Raspberry Pi with GPIO? Great. All you need now is a relay. *Note: This only works for amps which are "always on" by a switch. -------- Requirements: - Pi w/ a GPIO available. - Relay compatible with the Pi and your voltage (Typically 120v or 240v) - A way to connect your relay into the power feed of your amp, and the relay to the Pi. - Screen package - Python 2.7 or newer, which is included with moode. (I highly recommend python 2, otherwise you'll need to change the env at the beginning of the script) ------- I'm using GPIO 12 for my setup, and an always running loop within python that is running within a screen session. Now the how-to, You're going to need screen. Installing screen: apt install screen I used GPIO 12 for my setup, you can change in the config what GPIO pin you'd like to use, although it doesn't really matter if you have GPIO 12 open, then it's going to be pretty much a quick install without any modification to the script. You'll need to download my script into your home directory. (/home/pi) Otherwise you'll need to modify the crontab directory once we set that up. Here is the download to the script: https://drive.google.com/open?id=1JkVnprJZgumyPbFXip2qyQCwLQV3ndHh Now if you choose to, you can edit the script and make the changes needed to your setup, however I've made it work for most. That is all for now, I am currently figuring out how to get crontab or systemd to create a screen session at boot so that it auto starts. First off, we'll have to enable crontabs. sudo systemctl enable cron.service Now, we're going to edit the crontab. crontab -e (Select nano) add to the bottom the following: @reboot /usr/bin/screen -dmS python /home/pi/allinone.py (CTRL-X then y then hit enter to save and exit nano) Now it should automagically start with your pi Additional info: If you don't know the default ssh login, here you go: SSH login user: pi, pwd: moodeaudio I am running Python 2.7 under RE: Activate relay upon audio output with python - TheOldPresbyope - 05-13-2019 Not a comment on your instructions but on your recommendation to use Python 2. Python 2, currently Python 2.7, will be officially deprecated by the Python Software Foundation on 2020/01/01. From the Debian Python Policy statement: Quote:Debian currently supports two Python stacks, one for Python 3 and one for Python 2. The long term goal for Debian is to reduce this to one stack, dropping the Python 2 stack at some time. They haven't said how soon after 2020/01/01 this will occur. Some Python 2-isms run as-is in Python 3. Some don't. There are porting guides and utilities available to aid in the transition. Best to stay ahead of the curve. Regards, Kent PS - if you like this sort of thing, here's a countdown clock. RE: Activate relay upon audio output with python - nahventure - 05-14-2019 I'll go ahead and test it soon under python 3. RE: Activate relay upon audio output with python - lirus - 11-02-2019 (05-14-2019, 02:25 AM)nahventure Wrote: I'll go ahead and test it soon under python 3. Hi! Any luck porting it to python3? RE: Activate relay upon audio output with python - lirus - 11-05-2019 (11-03-2019, 12:17 PM)mike_d Wrote:(11-02-2019, 08:35 PM)lirus Wrote:(05-14-2019, 02:25 AM)nahventure Wrote: I'll go ahead and test it soon under python 3. Thanks mike_d! |