Capture and Restore Music Player

Why am I finding this so incredibly difficult? I’ve got a very simple DO piston just for testing this, and I can’t quite get it to work the way I expect it to.

Basically, I’d like my Music Player to capture the state it’s in, speak some text, then restore the player to the state it was in before the piston ever began. But what ends up happening is nothing. My Music Player doesn’t even stop, it just plays what it was playing as if the piston I created didn’t even exist.

Here’s my piston:

► Capture state of attributes [level, mute, status, switch, ⌂ trackUri, ⌂ model, ⌂ trackData, ⌂ trackDescription, ⌂ trackNumber, ⌂ transportUri] to local store
► Speak text “test” at volume 50 and restore

► Restore state of attributes [level, mute, status, switch, ⌂ model, ⌂ trackData, ⌂ trackDescription, ⌂ trackNumber, ⌂ trackUri, ⌂ transportUri] from local store

If I remove that last Restore action, my music player will stop and speak the text I wrote in, and that’s it. But if the restore command is there, when the piston runs nothing happens.

I’ve tried various different permutations of this piston, such as creating separate “Capture” and “Restore” pistons that execute in a test piston. I’ve tried having these commands run as a single action in a single piston, I’ve tried keeping all the actions separate, still nothing.

ANY help is appreciated! :frowning:

Edit: I’ve also tried using “Speak Text and Resume” in place of Restore, results are the same.

I don’t have a sonos but played with vlcthing for a few. Does CoRE show Sonos as having a "Speak text and resume" task available?

1 Like

It does, and I’ve tried using that but the results are the same. I should actually mention that I’ve been using “Speak Text and Resume” for the most part, having recently switched over to using restore since resume bore no fruit.

Is there a WAIT task after your SPEAK task? If not, you need to add one to allow the message to finish before your RESTORE task executes.

1 Like

I havent considered that; I’ll give that a try when I get home, then update this thread! :slight_smile:

Looking at your piston again, you can put all the tasks under one “Using SONOS” action block:

     Capture state 
     Speak text
     Wait whatever secs
     Restore state
1 Like

Been toying with it since I’ve been at work, here’s how it looks now:

► Capture state of attributes [level, mute, status, switch, ⌂ model, ⌂ trackData, ⌂ trackDescription] to local store
► Wait 1 seconds
► Speak text “test” at volume 50 and resume
► Wait 5 seconds
► Restore state of attributes [level, mute, status, switch, ⌂ model, ⌂ trackData, ⌂ trackDescription] from local store

Added the wait 1 second before speaking juuuuust in case, then condensed the action to a single block as suggested by elf.

I had been trying various versions of this, separating actions mostly, because a post in the peer assistance thread. They suggested that, for some reason, the Restore task needed to be in it’s own action block.

Sure hope that’s wrong.

1 Like

Hope that works too, LOL

This is similar to my “cuckoo clock” piston, where it had to Wait 18 seconds for the first soundbite to finish before it could play the next one:


Might have to ‘borrow’ this and drive the wife cuckoo!


Yeah, the wifey has already mentioned that the volume needs to be turned down :grinning:

Hours 1 thru 12 plays tower bells, hours 13 thru 24 plays the cuckoo clock …

1 Like

I don’t have a SONOS either, but if it’s true that you need the restore task in a separate action block, then just put the Wait task before the Restore task (in the same action block).

1 Like

Sorry for the long wait, new dad here,forgot I wouldnt have free time on the weekends anymore… lol

Anyways, tried all the suggestions here, no dice. I think I’m just going to give up on having this work the way I want and settle for only speaking text when the music device is not in use.

Kind of a crappy compromise, but at least the speaker wont stop abruptly when my wife is listening to music.


Well, congrats!! :+1:


Thank you!

That goes for both of us. :frowning:

Perhaps there’s simply an issue with the way SONOS handles statuses, or maybe an issue with CoRE as it stands. I’m just gonna hope the HTML5 version of CoRE magically resolves this.

@I2eflux - this is working wonders for me. I implemented your suggestion in post 7 however You missed the key attribute to store - trackURI (to be honest I am setting everything to the store but from previous testing trackURI is key - you can check this out by going into the IDE, Devices, the specific device and looking at the properties -trackURI seems to be the key thing that tells the Sonos what to play).

1 Like

This is one of my welcome home pistons:

So far it’s working perfectly. If the kitchen Sonos is on before I get home it pauses the Sonos, plays the welcome and then restores the Sonos track/radio station playing before the pause.

1 Like

Oh damp!

Gonna play with my pistons now to see if that does the trick!

Edit: Sure hope it works for inputs, too. I’ve got my PLAYBAR set to listen for input from the TV, makes me wonder how it handles “pausing” a live audio source.

Edit 2: k, hoping this works…

1 Like

So, this “worked”. It’ll resume the last track after TTS takes place, but doesn’t work when the audio source is anything live.

For instance, if Pandora is playing, the TTS will kick in and say whatever, then it’ll resume playing whatever was on Pandora; Awesome!

But, if the audio source is from the TV, TTS will kick in, then play the TTS again, incorrectly assuming the last thing it was doing was the TTS itself.

2 steps forward, 1 step back, but at least some progress!

Why are you not using the ‘Speak Text and Resume’ rather than saving the status to the local store, speaking your text and then restoring from local store?

I use this feature and seems to work reliably although I have had the odd occasion where a TTS is repeated, like in your case.

1 Like

[quote=“Hal9000, post:20, topic:73555”]
Why are you not using the ‘Speak Text and Resume’ rather than saving the status to the local store, speaking your text and then restoring from local store?[/quote]

Not sure I follow, because I am using ‘Speak text and Resume’, and I am saving and restoring.