I like the idea of tracking play state. I have several pi core players using HiFi Berry Pro XLR. These are connected to powered monitors around my home. The Pi is powered over Ethernet, so always powered on.
I'd like to use the play state of the Pi to trigger a remote controlled outlet to turn on the speakers. I already have the Amazon outlets that works with Alexa. So, an IFTTT action should be able to do this.
Sadly, I am not a developer. I'll need some help.
Results 11 to 20 of 30
-
2019-03-27, 08:00 #11
- Join Date
- Feb 2006
- Posts
- 138
Play state to IFTTT (or similar)
Michael Graves
House: RPi3 + HifiBerry Pro XLR, M-Audio BX5As
Home Office: RPi3 + HifiBerry Pro XLR, M-Audio BX5A D2, Berhringer B2092A subwoofer
Workshop: RPi3 + HifiBerry Pro XLR, Alesis M520 Active
Back Yard: HiFiBerryOS on Pi3, Dayton Amp, Definitive Tech AW6500s
Front Yard: SB3, SMSL Q5 Amp, Definitive Tech AW5500s
LMS via PiCorePlayer on Pi4
email: mgraves <at> mstvp.com
blog: http://www.mgraves.org
-
2019-03-27, 09:33 #12
- Join Date
- Sep 2005
- Posts
- 2,854
Make some script like amp_power.sh with something that powers the wifi-plug.
eg: (made for a Tasmota driven device without using mqtt "for this example" -in real life its using mqtt instead of curl)
Code:#!/bin/bash port=9090 server=lms.server.ip.address muzzigbox=ma:ca:dd:re:ss from the used player amp=IP.of.your.wifiswitch now=$(date +%H:%M) up=$(ps aux |grep squeezelite |grep -v grep|awk '{print $9}') if [ ! "$now" == "$up" ] then sleep 2 status=$(printf "$muzzigbox mode ?\nexit\n" | nc $server $port | cut -d ' ' - if [ $status = play ] then curl http://$amp/cm?cmnd=Power%20ON else curl http://$amp/cm?cmnd=Power%20OFF fi else echo detect startup printf "$muzzigbox power 0 \nexit\n"|nc $server $port curl http://$amp/cm?cmnd=Power%20OFF fi
Take a look at this Thread
The first script poweres the amp on / off if you press the powerbutton on the lms gui/ power the squeezelite player in any way.
The 2.nd script that should run each xx minutes as a cronjob "unpowers the squeezeliteplayer if its not playing anymore" and that power cycle starts the poweroff for your Amp.
-
2019-03-27, 09:37 #13
- Join Date
- Feb 2006
- Posts
- 138
Michael Graves
House: RPi3 + HifiBerry Pro XLR, M-Audio BX5As
Home Office: RPi3 + HifiBerry Pro XLR, M-Audio BX5A D2, Berhringer B2092A subwoofer
Workshop: RPi3 + HifiBerry Pro XLR, Alesis M520 Active
Back Yard: HiFiBerryOS on Pi3, Dayton Amp, Definitive Tech AW6500s
Front Yard: SB3, SMSL Q5 Amp, Definitive Tech AW5500s
LMS via PiCorePlayer on Pi4
email: mgraves <at> mstvp.com
blog: http://www.mgraves.org
-
2020-08-07, 09:44 #14
- Join Date
- Jul 2020
- Posts
- 29
Do you happen to know why "pcp mode" does not distinguish "stop" and "power off" state? It returns "stop" in either state.
Code:tc@Konyha:~$ pcp play tc@Konyha:~$ pcp mode play tc@Konyha:~$ pcp pause tc@Konyha:~$ pcp mode pause tc@Konyha:~$ pcp stop tc@Konyha:~$ pcp mode stop tc@Konyha:~$ pcp play tc@Konyha:~$ pcp mode play tc@Konyha:~$ pcp power off tc@Konyha:~$ pcp mode stop tc@Konyha:~$
Last edited by sakos; 2020-08-07 at 09:47. Reason: add output
-
2020-08-07, 14:15 #15
hi sakos,
Generally speaking the "pcp commands" are only a simple interface into LMS commands. They can only respond as LMS responds.
Having said that, reading the documentation we should get an "undefined" value. Maybe we have coded a default value of stop.
Code:<playerid> mode ? The "mode" command allows to query the player state and returns one of "play", "stop" or "pause". If the player is off, "mode ?" returned value is undefined. Example: Request: "04:20:00:12:23:45 mode ?<LF>" Response: "04:20:00:12:23:45 mode stop<LF>"
regards
Greg
-
2020-09-03, 14:50 #16
- Join Date
- Dec 2017
- Posts
- 57
Ok, my first (b)ash script, actually my first work on linux
For newbees like me (working with Windows normaly):
- use MobaXTerm to ssh to your piCorePlayer, create a new file in /home/tc/ps2gpio.sh
- double click ps2gpio.sh in the MobaXTerm explorer view to edit the file
- copy and paste the script below, save and accept request with "all"
- In terminal Window - provided you will use GPIO4 set to 3V when squeezelite ist playing:
chmod +xX ps2gpio.sh
sudo ./ps2gpio.sh -g 4
If you think thats fine, you can put it to Autostart:
- Web browser to your picoreplayer
- Tweaks - User commands:
sudo /home/tc/ps2gpio.sh -g 4 -d
Sorry for the noisy explenations. Here is the script:
------------------------------------------------------------------------------------------
Code:#!/bin/sh BASE_GPIO_PATH=/sys/class/gpio function Usage () { echo "" echo "PlayState to GPIO (ps2gpio) sets a GPIO when squeezelite is playing." echo "--------------------------------------------------------------------" echo "Usage: sudo $0 -g GPIO [-s n] [-d] [-h] [-v]" echo "" echo "-g : GPIO-number" echo "-s : Set value for \"play\" state: 0,1. Default=1 sets GPIO to 3V when playing" echo "-d : Daemonize: Start running in backgrund and exit" echo "-v : Verbose output when daemonized" echo "-h : Shows this help" echo "" echo "Examples:" echo "---------" echo " sudo $0 -g 27 : Sets GPIO27 to 3V when playing, stop running with Ctrl-c" echo " sudo $0 -g 4 -s 0 -d : Sets GPIO4 to 0V when playing, running in background" echo " sudo $0 -g 4 -s 1 -d -v : Sets GPIO4 to 3V when playing, running in background with status output" echo "" exit 1 } # function Usage function err () { echo "$1" >&2; Usage } # function err # Parameter # Defaults Daemonize=false PlayVal=1 Verbose=false if [ ! $1 ]; then Usage; fi while getopts g:s:dhv opt do case $opt in g ) # Check for valid GPIO if [ "$OPTARG" -ge 2 ] && [ "$OPTARG" -le 27 ]; then myGPIO=$OPTARG else err "\"$OPTARG\" is not a valid GPIO, please use 2 .. 27" fi # Check for valid GPIO ;; s ) # Check parameter for setting GPIO to 0 or 1 when playing if [ $OPTARG ]; then # Set GPIO to 0 or 1 when playing if [ "$OPTARG" -eq 0 ] || [ "$OPTARG" -eq 1 ]; then PlayVal=$OPTARG else err "\"$OPTARG\" is not a valid GPIO state, please use 0 or 1" fi else # no parameter PlayVal=1 # default fi # Check parameter for setting GPIO to 0 or 1 when playing ;; d ) Daemonize=true ;; v ) Verbose=true;; h ) Usage;; esac done if [ ! $myGPIO ]; then err "Mandatory parameter -g \"GPIO\" is missing"; fi echo "$0 -g $myGPIO -s $PlayVal -d $Daemonize -v $Verbose" # Init if [ ! -e $BASE_GPIO_PATH/gpio$myGPIO ]; then # Init GPIO echo "Export GPIO $myGPIO to userspace" echo "$myGPIO" > $BASE_GPIO_PATH/export fi # Init GPIO echo Set GPIO $myGPIO as an output echo "out" > $BASE_GPIO_PATH/gpio$myGPIO/direction # wait for squeeze to come online wt=0 until pids=$(pidof squeezelite squeezelite-dsd) do sleep 1; wt=$(($wt+1)) echo "Waited $wt seconds for for squeezelite ..." if [ "$wt" -ge 60 ]; then err "Waited too long for squeezelite"; fi done # read actual GPIO value - gives 0 ? # oldGPIOval=`cat /sys/class/gpio/gpio$myGPIO/value` # echo "oldGPIOval is $oldGPIOval" function Loop () { while true do STATE=`(pcp mode)` if [ ! "$STATE" = "$OldState" ]; then # STATE change echo pcp State is $STATE if [ "$STATE" = "play" ]; then GPIOval=$PlayVal; else GPIOval=$((!$PlayVal)); fi # Set GPIO value if [ ! "$GPIOval" = "$oldGPIOval" ]; then echo Set GPIO $myGPIO to $GPIOval echo "$GPIOval" > $BASE_GPIO_PATH/gpio$myGPIO/value oldGPIOval=$GPIOval fi # GPIO val change OldState=$STATE fi # STATE change sleep 0.5 done # while true } # function Loop if $Daemonize; then # daemonize if $Verbose; then echo "Daemonizing with output." Loop & else echo "Daemonizing." Loop > /dev/null 2>&1 & fi else # run in foreground: Loop fi exit 0
Not very well tested (On a fresh pcp 6.1 ok). Should work nevertheless.
have fun
Aki
-
2020-09-03, 15:03 #17
- Join Date
- Dec 2017
- Posts
- 57
P.S. Dont forget to backup :-)
-
2020-09-03, 17:54 #18
I wish my first shell script looked that good!
-
2020-09-04, 03:15 #19
- Join Date
- Dec 2017
- Posts
- 57
Thanks Greg :-) Was a long way of learning from early Fortan (Punch cards) to Powershell nowadays.
I am motivated to start with C on piCorePlayer. Is there any helping starting point on piCore for newbees?
Aki
-
2020-09-04, 05:26 #20
http://www.tinycorelinux.net/
There is also a book. http://www.tinycorelinux.net/book.htmlpiCorePlayer a small player for the Raspberry Pi in RAM.
Homepage: https://www.picoreplayer.org
Please donate if you like the piCorePlayer