I will try this! Seems to be exactly what I wanted! Thanks alot.
I tried it, but i get
sh squeezebox_alert_save_playlist.sh % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 60 0 0 100 60 0 41124 --:--:-- --:--:-- --:--:-- 60000 curl: (52) Empty reply from server squeezebox_alert_save_playlist.sh: [[: not found prev_power=0 % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 59 0 0 100 59 0 41143 --:--:-- --:--:-- --:--:-- 59000 curl: (52) Empty reply from server squeezebox_alert_save_playlist.sh: [[: not found prev_playmode=0 curl: (52) Empty reply from server % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 69 0 0 100 69 0 44892 --:--:-- --:--:-- --:--:-- 69000 curl: (52) Empty reply from server prev_volume= % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 72 0 0 100 72 0 49180 --:--:-- --:--:-- --:--:-- 72000 curl: (52) Empty reply from server prev_repeat=
What can i do?
Edit: A a small file called â.txtâ is saved containing only â0 0 0â
Should have read the code!
Now i get:
sh squeezebox_alert_save_playlist.sh âkitchenâ â00:04:20:29:6a:0fâ 60
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 176 100 99 100 77 62303 48458 --:â:-- --:â:-- --:â:-- 99000
squeezebox_alert_save_playlist.sh: [[: not found
prev_power=0
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 178 100 102 100 76 61519 45838 --:â:-- --:â:-- --:â:-- 99k
squeezebox_alert_save_playlist.sh: [[: not found
prev_playmode=0
{âmethodâ:âslim.requestâ,âparamsâ:[â00:04:20:29:6a:0fâ,[âplaylistâ,âsaveâ,âkitchenâ,âsilent:1â]],âidâ:1,âresultâ:{â__playlist_idâ:59142}} % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 198 100 112 100 86 69221 53152 --:â:-- --:â:-- --:â:-- 109k
prev_volume=â60â
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 203 100 114 100 89 77079 60175 --:â:-- --:â:-- --:â:-- 111k
prev_repeat=â0â
{âresultâ:{},âmethodâ:âslim.requestâ,âidâ:1,âparamsâ:[â00:04:20:29:6a:0fâ,[âmixerâ,âvolumeâ,â60â]]}set alert_volume
{âparamsâ:[â00:04:20:29:6a:0fâ,[âplaylistâ,ârepeatâ,â0â]],âidâ:1,âmethodâ:âslim.requestâ,âresultâ:{}}set repeat_setting to 0
Edit: Tried it with a Spotify playlist and with a ânormalâ one.
Edit: Volume set does work. kitchen.txt contains only
0
0
0
â0â
â0â
Edit: I think something is wrong with the âif-âŚâ. Perhaps it has to do with my system: its FreeBSD not LinuxâŚ
I donât get this bash variable thing. Canât get a working if with a curl variable!
I updated the post above with an example of using the script. I also updated the script so the settings file (player_name.txt) will be saved in the same directory as the script files. It works for me on both regular and spotify (remote stream) playlists.
Yeah, you might be having issues due to bash shell differences⌠this should really be re-written using python. Anyone???
Ok, good to hear! How are you using it in home assistant? Are you using a âscript:â with a âsequence:â like in my example above? Just wondering.
At the moment iâm still testing. Want to use (and already tried) it as a part of an automation. But Iâm not sure about this.
Your script is working, but my Squeezeboxes (radio & touch) are completely out of sync after the resume-script. I think its more a squeezebox-problem than a problem of HASS, so i will try to find a solution in the Squeezebox-Forum.
I did some quick tests with synchronization and it seems to work fine for me. In my tests the script was only ever dealing with one player (kitchen). I did a test where the kitchen player was the sync master and one where it was the sync follower. In both tests the alert was played on both players and both players resumed playing music in sync with each other. Check your squeezebox player settings and make sure âMaintain synchronization while playingâ option is selected. I am not synchronizing player volume or power⌠not sure if it matters. In my test I used a SB Classic and a SB Boom. Note, I generally keep synchronization off and didnât test the script much with synchronization turned on.
@smazman
I´ve notice one bug with the script.
When the playlist is restored it starts playing even if the player was off before.
I´m using your original script not the two with the save/restore ones.
I canât reproduce the behavior you mentioned, but I made some updates related to power handling in the original script (first post). I also updated the script in post 15 to take an optional parameter to not restore the playlist (so it should allow similar behavior to the script in the first post). Let me know how it goes.
Thank you I´ll try this.
I was a bit unclear before, I´m using the script in post 15.
Did you do any changes to this one except the flag?
Do I understand it right that there are atm 3 different versions?
First post, used by you
15th post, used by me
and the split version used by mrmuppet
Oh ok sorry, I thought you were using the script in the first post. Iâm not sure exactly what I updated in the script at post 15 at this point⌠I updated it a few times now. Grab the current one and let me know if you still see the issue. If so, try running it from the command line and post the output.
I am actually now using both the script at post 15 and the split script⌠depending on if I want to play a local mp3 or if I want to use TTS.
Just came across this thread and although Iâm not a HA user I do use Domoticz and I just published a perl script that does something very similar to what the bash scripts here do. Check out the wiki entry over at Domoticz:
https://www.domoticz.com/wiki/Logitech_Media_Server#Audio_Alerts_via_Squeezebox_Players
Anyone else having issues with this and resuming playlist from Spotty?
After TTS message it seems it can´t restore the list
on post 20 can you separate out the scripts for others that might be confused save and restore are kind of mashed together in the post.
But the script is awesome finally got it working for me. Are you also using HTTP not HTTPS as your base URL?
I couldnât figure out how to edit post 20, so Iâll just include the code here againâŚ
Example configuration.yaml entries (not complete)
automation:
- alias: "Play lamp on audio alert"
trigger:
- platform: state
entity_id: switch.lamp
to: 'on'
action:
- service: homeassistant.turn_on
entity_id: script.play_light_on_alert_in_kitchen
shell_command:
playlist_save_kitchen: bash /volume1/homeassistant/squeezebox_alert_save_playlist.sh "kitchen" "00:04:20:01:02:03" 65
playlist_restore_kitchen: bash /volume1/homeassistant/squeezebox_alert_restore_playlist.sh "kitchen" "00:04:20:01:02:03"
script:
play_light_on_alert_in_kitchen:
alias: "Play light alert"
sequence:
- service: shell_command.playlist_save_kitchen
- service: tts.google_say
entity_id: media_player.kitchen
data:
message: 'The lamp is on.'
- service: shell_command.playlist_restore_kitchen
squeezebox_alert_save_playlist.sh
#!/bin/bash
#squeezebox_alert_save_playlist.sh
#NOTE: Edit "user", "pass", ip and port below
JSONRPC="http://user:[email protected]:9000/jsonrpc.js"
#Example command arguments
#playlist_name="bedroom"
#mac="00:04:20:01:02:03"
#alert_volume=60
playlist_name=$1
mac=$2
alert_volume=$3
#get power state
power=$(curl -X GET -H "Content-Type: application/json" \
-d '{"id":1,"method":"slim.request","params":["'"$mac"'",["power","?"]]}' \
$JSONRPC | jq '.result._power')
prev_power=0
if [[ $power =~ .*1.* ]] ; then
prev_power=1
fi
echo "prev_power=$prev_power"
#get play mode
mode=$(curl -X GET -H "Content-Type: application/json" \
-d '{"id":1,"method":"slim.request","params":["'"$mac"'",["mode","?"]]}' \
$JSONRPC | jq '.result._mode')
prev_playmode=0
if [[ $mode =~ .*play.* ]] ; then
prev_playmode=1
fi
echo "prev_playmode=$prev_playmode"
noplay=1
prev_time=0
if [ $prev_playmode -eq 1 ] ; then
noplay=0
# pause currently playing song
curl -X GET -H "Content-Type: application/json" \
-d '{"id":1,"method":"slim.request","params":["'"$mac"'",["pause"]]}' $JSONRPC
echo "pause currently playing song"
# get paused time
prev_time=$(curl -X GET -H "Content-Type: application/json" \
-d '{"id":1,"method":"slim.request","params":["'"$mac"'",["time","?"]]}' \
$JSONRPC | jq '.result._time')
echo "prev_time=$prev_time"
fi
# save current playlist
curl -X GET -H "Content-Type: application/json" \
-d '{"id":1,"method":"slim.request","params":["'"$mac"'",["playlist","save","'"$playlist_name"'","silent:1"]]}' $JSONRPC
echo "save current playlist"
# GET SETTINGS TO RESTORE AFTER PLAYING ALERT SONG
#get current volume
prev_volume=$(curl -X GET -H "Content-Type: application/json" \
-d '{"id":1,"method":"slim.request","params":["'"$mac"'",["mixer","volume","?"]]}' \
$JSONRPC | jq '.result._volume')
echo "prev_volume=$prev_volume"
#get current repeat setting
prev_repeat=$(curl -X GET -H "Content-Type: application/json" \
-d '{"id":1,"method":"slim.request","params":["'"$mac"'",["playlist","repeat","?"]]}' \
$JSONRPC | jq '.result._repeat')
echo "prev_repeat=$prev_repeat"
#write settings to file
DIRECTORY=$(cd `dirname $0` && pwd)
echo "Save settings to file: $DIRECTORY/$playlist_name.txt"
> "$DIRECTORY/$playlist_name.txt"
printf '%s\n%s\n%s\n%s\n%s\n' $prev_power $prev_playmode $prev_time $prev_volume $prev_repeat > "$DIRECTORY//$playlist_name.txt"
# SET SETTINGS FOR ALERT SONG
#set alert_volume to command argument value
curl -X GET -H "Content-Type: application/json" \
-d '{"id":1,"method":"slim.request","params":["'"$mac"'",["mixer","volume",'$alert_volume']]}' $JSONRPC
echo "set alert_volume"
#set repeat setting to 0
curl -X GET -H "Content-Type: application/json" \
-d '{"id":1,"method":"slim.request","params":["'"$mac"'",["playlist","repeat",0]]}' $JSONRPC
echo "set repeat_setting to 0"
squeezebox_alert_restore_playlist.sh
#!/bin/bash
#squeezebox_alert_restore_playlist.sh
#NOTE: Edit "user", "pass", ip and port below
JSONRPC="http://user:[email protected]:9000/jsonrpc.js"
#Example command arguments
#playlist_name="bedroom"
#mac="00:04:20:01:02:03"
playlist_name=$1
mac=$2
# WAIT FOR ALERT SONG TO STOP PLAYING
echo "wait for alert song to stop playing"
cur_mode="play"
while [[ $cur_mode =~ .*play.* ]]; do
sleep 1
cur_mode=$(curl -X GET -H "Content-Type: application/json" \
-d '{"id":1,"method":"slim.request","params":["'"$mac"'",["mode","?"]]}' \
$JSONRPC | jq '.result._mode')
done
echo "alert song stopped playing"
# read settings from file
DIRECTORY=$(cd `dirname $0` && pwd)
echo "Restore settings from file: $DIRECTORY/$playlist_name.txt"
IFS=$'\n' read -d '' -r -a lines < "$DIRECTORY/$playlist_name.txt"
prev_power="${lines[0]}"
prev_playmode="${lines[1]}"
prev_time="${lines[2]}"
prev_volume="${lines[3]}"
prev_repeat="${lines[4]}"
echo "prev_power=$prev_power"
echo "prev_playmode=$prev_playmode"
echo "prev_time=$prev_time"
echo "prev_volume=$prev_volume"
echo "prev_repeat=$prev_repeat"
noplay=1
if [ $prev_playmode -eq 1 ] ; then
noplay=0
fi
# RESTORE PREVIOUS SETTINGS
#restore prev_volume setting
curl -X GET -H "Content-Type: application/json" \
-d '{"id":1,"method":"slim.request","params":["'"$mac"'",["mixer","volume",'"$prev_volume"']]}' $JSONRPC
echo "restore prev_volume setting"
#restore prev_repeat setting
curl -X GET -H "Content-Type: application/json" \
-d '{"id":1,"method":"slim.request","params":["'"$mac"'",["playlist","repeat",'"$prev_repeat"']]}' $JSONRPC
echo "restore prev_repeat setting"
# resume previous playlist
curl -X GET -H "Content-Type: application/json" \
-d '{"id":1,"method":"slim.request","params":["'"$mac"'",["playlist","resume","'"$playlist_name"'","noplay:'$noplay'"]]}' $JSONRPC
echo "resume previous playlist"
# RESUME PREVIOUSLY PLAYING MUSIC
if [ $prev_playmode -eq 1 ] ; then
#skip ahead in song to prev_time
curl -X GET -H "Content-Type: application/json" \
-d '{"id":1,"method":"slim.request","params":["'"$mac"'",["time",'"$prev_time"']]}' $JSONRPC
echo "skip ahead in song to prev_time"
fi
#restore prev_power setting
if [ $prev_power -eq 0 ] ; then
echo "prev_power setting was off, power off"
curl -X GET -H "Content-Type: application/json" \
-d '{"id":1,"method":"slim.request","params":["'"$mac"'",["power",0]]}' $JSONRPC
fi
I can see that in the script above you have google tts working with Squeezebox.
Do you use SSL (Let´s crypt)?
EDIT: I was trying the save/restore version of the script.
But all I get in my Kitchen.txt is:
1
0
0
â40â
â0â
@mrMuppet can you give an example of your setup? I can´t get the resume to work anymore, instead I get funny results (tries to resume non-existing playlist for example)
@freelev: I am not using SSL (HTTPS) on my Logitech Media Server (LMS), but I am with Home Assistant. Your Kitchen.txt file looks correct. That file just holds the power, playmode, time, volume and repeat settings for your player so those settings can be read back in and restored after the alert is played on your squeezebox. The actual squeezebox playlist is saved in a folder determined by your LMS settings. If you go to the LMS web interface you should see a playlist called âKitchenâ.
Hi
Thank you, I´ll check my playlist folder when I`m back home. Maybe it is something with permissions to that folder.
I don´t use SSL on my LMS either, still TTS does not work for me.
Are you using Let´s Encrypt?
If so, can you please post how your base_url and TTS config looks like?
I have currently two issues
- playlist not restoring as it should
- TTS not working (need to use pre-created files)
no 2 I can live with, no 1 would be nice to solve