How to store and restore sonos settings before and after TTS

I am using tts a lot in my automations.
I generally use Google home.
But now I like to do it at sonos.
I can let sonos use TTS but I like that after a TTS message Sonos is going on as before.
I did find a solution at the internet, but it is not working for me.
I try to use the HA Api
What Am I doing wrong?
It is not restoring the sonos state
My test flow:
[{"id":"8503180733b2e438","type":"function","z":"fcf990c75cc7659a","name":"makeMSG","func":"msg.payload ={\n data: {\n message:'Dit is een test'\n }\n};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":610,"y":170,"wires":[["24155fc992410107"]]},{"id":"24155fc992410107","type":"api-call-service","z":"fcf990c75cc7659a","name":"TTS","server":"cd4bab9817bb3b13","version":5,"debugenabled":false,"domain":"tts","service":"edge_say","areaId":[],"deviceId":[],"entityId":["media_player.tv_hoek"],"data":"","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":764,"y":170,"wires":[["de89d9f4180adbf9"]]},{"id":"08f20a1ca6423008","type":"inject","z":"fcf990c75cc7659a","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":94,"y":170,"wires":[["1a600323a51c57e6"]]},{"id":"0ac42cfd97d12e24","type":"debug","z":"fcf990c75cc7659a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1226,"y":170,"wires":[]},{"id":"94c9d988a8a68315","type":"api-call-service","z":"fcf990c75cc7659a","name":"Volume","server":"cd4bab9817bb3b13","version":5,"debugenabled":false,"domain":"media_player","service":"volume_set","areaId":[],"deviceId":[],"entityId":["media_player.tv_hoek"],"data":"{\"volume_level\":\"0.3\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":451,"y":170,"wires":[["8503180733b2e438"]]},{"id":"2655865b2e1c3088","type":"ha-api","z":"fcf990c75cc7659a","name":"restore state","server":"cd4bab9817bb3b13","version":1,"debugenabled":false,"protocol":"http","method":"post","path":"/api/states/media_player.tv_hoek","data":"payload","dataType":"jsonata","responseType":"json","outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"results"}],"x":1052,"y":170,"wires":[["0ac42cfd97d12e24"]]},{"id":"1a600323a51c57e6","type":"ha-api","z":"fcf990c75cc7659a","name":"save state","server":"cd4bab9817bb3b13","version":1,"debugenabled":false,"protocol":"http","method":"get","path":"/api/states/media_player.tv_hoek","data":"payload","dataType":"jsonata","responseType":"json","outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"results"}],"x":287,"y":170,"wires":[["94c9d988a8a68315"]]},{"id":"de89d9f4180adbf9","type":"stoptimer","z":"fcf990c75cc7659a","duration":"5","units":"Second","payloadtype":"num","payloadval":"0","name":"5S","x":900,"y":170,"wires":[["2655865b2e1c3088"],[]]},{"id":"cd4bab9817bb3b13","type":"server","name":"Home Assistant 1","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false,"cacheJson":false,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":": ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"default","statusTimeFormat":"h:m","enableGlobalContextStore":true}]

I did found the option snapshot and restore. I will test that tonight.

EDIT: I tried to use the snapshot and restore service.
If I don’t use TTS between the snapshot and restore. The function is working.
If I use a TTS between the snapshot and restore servive I do receive a API error at the restore node.
I tried a delay after the snapshot and for TTS (5sec) also Api error.
It is playing Spotify

Any Idea?

Is there an other option beside snapshot and restore?
For example: I’m able to store the setting state into a variable, but how can I restore that variable to Sonos setting again?

YESSSS after a couple of days stumbling around I did find the solution:
I do store he snapshot msg.payload into a variable. After TTS I do write the var iable back into msg.payload and do restore.

@Canedje , I’m struggling with e same problem that you seem to find resolution for. Would you mind posting posting the code for your flow. Thanks

No problem:
[{"id":"9a06efe3bda6b90b","type":"debug","z":"e359fa80fca30826","name":"sonos","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":798,"y":221,"wires":[]},{"id":"30a1d85ac625480c","type":"api-call-service","z":"e359fa80fca30826","name":"sonos restore","server":"dbc269b7ec5d8849","version":5,"debugenabled":false,"domain":"sonos","service":"restore","areaId":[],"deviceId":[],"entityId":[],"data":"{\"entity_id\":\"media_player.tv_hoek\",\"with_group\":true}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":624,"y":221,"wires":[["9a06efe3bda6b90b"]]},{"id":"75ada55d170ffe5c","type":"change","z":"e359fa80fca30826","name":"data to payload","rules":[{"t":"set","p":"payload","pt":"msg","to":"SonosData","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":435,"y":221,"wires":[["30a1d85ac625480c"]]},{"id":"fda164707482efec","type":"stoptimer","z":"e359fa80fca30826","duration":"2","units":"Second","payloadtype":"num","payloadval":"0","name":"2S","x":273,"y":221,"wires":[["75ada55d170ffe5c"],[]]},{"id":"b9fa910c39e8d944","type":"junction","z":"e359fa80fca30826","x":187,"y":221,"wires":[["fda164707482efec"]]},{"id":"7fdee56812924314","type":"junction","z":"e359fa80fca30826","x":1003,"y":187,"wires":[["b9fa910c39e8d944"]]},{"id":"ee4789b5297f59bb","type":"api-call-service","z":"e359fa80fca30826","name":"TTS","server":"dbc269b7ec5d8849","version":5,"debugenabled":false,"domain":"tts","service":"edge_say","areaId":[],"deviceId":[],"entityId":["media_player.tv_hoek"],"data":"","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":921,"y":170,"wires":[["7fdee56812924314"]]},{"id":"f0391a6711c1ad78","type":"function","z":"e359fa80fca30826","name":"makeMSG","func":"msg.payload ={\n data: {\n message:'Dit is een test'\n }\n};\nreturn msg;","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":767,"y":170,"wires":[["ee4789b5297f59bb"]]},{"id":"7acec0b4b2227604","type":"api-call-service","z":"e359fa80fca30826","name":"Volume","server":"dbc269b7ec5d8849","version":5,"debugenabled":false,"domain":"media_player","service":"volume_set","areaId":[],"deviceId":[],"entityId":["media_player.tv_hoek"],"data":"{\"volume_level\":\"0.3\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":608,"y":170,"wires":[["f0391a6711c1ad78"]]},{"id":"95f5813531ea6b5d","type":"change","z":"e359fa80fca30826","name":"sonos data","rules":[{"t":"set","p":"SonosData","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":457,"y":170,"wires":[["7acec0b4b2227604"]]},{"id":"5e56fba696c1e1c5","type":"api-call-service","z":"e359fa80fca30826","name":"sonos snapshot","server":"dbc269b7ec5d8849","version":5,"debugenabled":false,"domain":"sonos","service":"snapshot","areaId":[],"deviceId":[],"entityId":["media_player.tv_hoek"],"data":"{\"entity_id\":\"media_player.tv_hoek\",\"with_group\":true}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":277,"y":170,"wires":[["95f5813531ea6b5d"]]},{"id":"e248ea0411a8a2d8","type":"inject","z":"e359fa80fca30826","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":94,"y":170,"wires":[["5e56fba696c1e1c5"]]},{"id":"dbc269b7ec5d8849","type":"server","name":"Home Assistant 1","version":5,"addon":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false,"cacheJson":false,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":": ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"default","statusTimeFormat":"h:m","enableGlobalContextStore":true}]

Greatly appreciated! Thanks