hklages / node-red-contrib-sonos-plus

A set of Node-RED nodes to control SONOS player in your local network.
MIT License
76 stars 14 forks source link

Sporadic Error on restoring snap (play snap) #119

Closed Flight777 closed 3 years ago

Flight777 commented 3 years ago

Description

Great fan of your work!!

So here is my issue:

After the wife has been complaining that the doorbell (playing an MP3 with Sonos Polly Node) disrupts her music and f-ups the groups she had going, I'm trying to program a solution where:

I've got this somewhat working now with the flow below (I'm a beginner so might not do it effieciently!!)

What I do is basically:

  1. Queu the incoming notificiation message
  2. Branch off, see which groups exists currently in house (houshold.get.groups)
  3. Split the payload into individual messages for each Sonos group
  4. Take a snapshot of each coordinator of a group (payload[0])
  5. Queu these messages, to wait until notification is played
  6. Branch off with and join all messages into one to signal the queud notification of 1. to be released and notification played.
  7. After notification played, release queu of 5. to restore all snaps (play snap)

A bit complex, but the only way I could get around it at the moment with my limited knowledge.

This seems to work at first when I test it, but after each 2nd or 3rd sequence I get this and need to redeploy to get it working again:

image

I don't see any "undefines" in the message payloads, but I might be looking wrong?

What node/command (topic)/state (payload)

node: command: state:

In case of a bug: Are you able to reproduce the error

Versions and Infrastructure

what system: node-red-contrib-sonos-plus version: Node-RED version:

Flow example:

image

[{"id":"5fe0f4e4.8d99ec","type":"tab","label":"Flow 3","disabled":false,"info":""},{"id":"b95327ac.d42df8","type":"link in","z":"5fe0f4e4.8d99ec","name":"Sonos ALL","links":["38d2c58d.a1a01a","e39578fb.a5c418","f95c52e1.5a1a4","fcb80863.97456","a3977a68.00d6e8"],"x":335,"y":260,"wires":[["57e427a4.fe07e8","8fcc658f.0a7e38"]]},{"id":"11b4f731.13ab79","type":"link out","z":"5fe0f4e4.8d99ec","name":"Sonos 192.168.31.70 Output","links":["8bef3326.273758"],"x":2435,"y":260,"wires":[]},{"id":"9aabd064.fdfd4","type":"sonospollytts","z":"5fe0f4e4.8d99ec","name":"","voice":"36","ssml":false,"sonosipaddress":"192.168.31.70","sonosvolume":"50","sonoshailing":"0","config":"23bb01a2.febe2e","property":"payload","propertyType":{},"rules":[{"host":"192.168.31.85"},{"host":"192.168.31.12"},{"host":"192.168.31.119"}],"x":1320,"y":260,"wires":[["11b4f731.13ab79","1f654329.d4de5d"]]},{"id":"1f654329.d4de5d","type":"switch","z":"5fe0f4e4.8d99ec","name":"Completed?","property":"completed","propertyType":"msg","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":1770,"y":320,"wires":[["49738be6.d821b4","cf3b6ccf.3870c"]]},{"id":"57e427a4.fe07e8","type":"q-gate","z":"5fe0f4e4.8d99ec","name":"Wait To Capture Sonos States","controlTopic":"control","defaultState":"queueing","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","queueCmd":"queue","defaultCmd":"default","triggerCmd":"trigger","flushCmd":"flush","resetCmd":"reset","peekCmd":"peek","dropCmd":"drop","statusCmd":"status","maxQueueLength":"1","keepNewest":false,"qToggle":false,"persist":true,"storeName":"default","x":750,"y":260,"wires":[["9aabd064.fdfd4"]]},{"id":"8fcc658f.0a7e38","type":"sonos-universal","z":"5fe0f4e4.8d99ec","confignode":"2ff51247.cdcfee","compatibilityMode":false,"command":"household.get.groups","state":"","stateType":"str","name":"","x":680,"y":460,"wires":[["84d776ba.79d9c8"]]},{"id":"84d776ba.79d9c8","type":"split","z":"5fe0f4e4.8d99ec","name":"Split All Sonos Groups To Indiv Message","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":980,"y":460,"wires":[["7a0712a2.e41ebc"]]},{"id":"afff634a.18ec4","type":"sonos-universal","z":"5fe0f4e4.8d99ec","confignode":"645aa842.c8c978","compatibilityMode":false,"command":"group.create.snap","state":"","stateType":"str","name":"Get Snapshots","x":1580,"y":460,"wires":[["c7c3dc24.afca7","5ba87937.8ab398","f2d36697.bbf638"]]},{"id":"7a0712a2.e41ebc","type":"change","z":"5fe0f4e4.8d99ec","name":"Set Snapshot Commands","rules":[{"t":"set","p":"playerName","pt":"msg","to":"payload[0].sonosName","tot":"msg"},{"t":"set","p":"snapVolumes","pt":"msg","to":"true","tot":"bool"},{"t":"set","p":"snapMutestates","pt":"msg","to":"true","tot":"bool"},{"t":"set","p":"group_backup","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1310,"y":460,"wires":[["afff634a.18ec4"]]},{"id":"c7c3dc24.afca7","type":"change","z":"5fe0f4e4.8d99ec","name":"Secure Data For Join","rules":[{"t":"set","p":"snaphot","pt":"msg","to":"payload","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"group_backup","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1800,"y":400,"wires":[["718eb76.b1dd548"]]},{"id":"718eb76.b1dd548","type":"join","z":"5fe0f4e4.8d99ec","name":"","mode":"auto","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":2030,"y":380,"wires":[["e1cb657b.15e778"]]},{"id":"5ba87937.8ab398","type":"q-gate","z":"5fe0f4e4.8d99ec","name":"Wait For Sound To Play","controlTopic":"control","defaultState":"queueing","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","queueCmd":"queue","defaultCmd":"default","triggerCmd":"trigger","flushCmd":"flush","resetCmd":"reset","peekCmd":"peek","dropCmd":"drop","statusCmd":"status","maxQueueLength":"20","keepNewest":false,"qToggle":false,"persist":false,"storeName":"default","x":2050,"y":460,"wires":[["dda31ab7.f9d9f8"]]},{"id":"e1cb657b.15e778","type":"change","z":"5fe0f4e4.8d99ec","name":"Allow Sound To Play","rules":[{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"open","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1040,"y":360,"wires":[["57e427a4.fe07e8"]]},{"id":"49738be6.d821b4","type":"change","z":"5fe0f4e4.8d99ec","name":"Allow To Reset Snapshots","rules":[{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"open","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":2370,"y":320,"wires":[["5ba87937.8ab398"]]},{"id":"cf3b6ccf.3870c","type":"change","z":"5fe0f4e4.8d99ec","name":"Set Back To Queu","rules":[{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"queue","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1950,"y":220,"wires":[["57e427a4.fe07e8"]]},{"id":"dda31ab7.f9d9f8","type":"sonos-universal","z":"5fe0f4e4.8d99ec","confignode":"645aa842.c8c978","compatibilityMode":false,"command":"group.play.snap","state":"","stateType":"str","name":"Restore Snapshots","x":2390,"y":460,"wires":[["28af421.228b4be"]]},{"id":"28af421.228b4be","type":"join","z":"5fe0f4e4.8d99ec","name":"","mode":"auto","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":2090,"y":780,"wires":[["bb8eaac9.92c8e8"]]},{"id":"bb8eaac9.92c8e8","type":"change","z":"5fe0f4e4.8d99ec","name":"Set Back To Queu","rules":[{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"queue","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":2330,"y":780,"wires":[["5ba87937.8ab398"]]},{"id":"f2d36697.bbf638","type":"debug","z":"5fe0f4e4.8d99ec","name":"Sonos Test","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1670,"y":840,"wires":[]},{"id":"23bb01a2.febe2e","type":"sonospollytts-config","name":"HASS_Polly","noderedipaddress":"192.168.31.10","noderedport":"1980","purgediratrestart":"leave"},{"id":"2ff51247.cdcfee","type":"sonos-config","name":"Living Room","serialnum":"78-28-CA-07-4D-34:F","ipaddress":"192.168.31.59"},{"id":"645aa842.c8c978","type":"sonos-config","name":"Kitchen Speaker","serialnum":"78-28-CA-03-3A-16:D","ipaddress":""}]

hklages commented 3 years ago

Hi - smart flow - need some more information.

Flight777 commented 3 years ago

Hi,

Thanks for looking into it! To answer your questions:

How many players / groups do you have in your household?

10 players in total (or 8 if you substract the two in surround mode with a playbase).

Do you join the player for the notification and also restore the groups after notification in sonospollytts?

SonosPolly joins a few of them (4) in a group to play the notification, but I take the snap of the situation before SonosPolly and restore if after SonosPollyTTS reports it is done.

Can it happen that you have several overlapping notifications? Doorbell rings, News is played, ...?

No, only one notification is played at a time. The flow is also only triggered for one notification at a time.

Does all notifications play on the same set of players?

In this flow yes.

hklages commented 3 years ago

OK understand. Combining and re-arranging 4 players should not take to long.

SonosPollyTTS reports it is done ...

Most of the commands (all actions in the create snapshot) are very fast, as they only "read" the SONOS player. But rearranging groups may take some seconds. Therefore, it could be helpful to add a delay node (2-5 seconds) after SonosPollyTTs has finished its job. That allows the Sonos system to rearrange the players. If the players are not in there final position, the restore snapshot will fail. Next release will submit an error message in that case.

No, only one notification is played at a time.

In that case you may remove the first gate and just put the "create snapshot" part in front of "play with SonosPollyTTX" part. "create snapshot" takes only millisecond and the different group commands are able to run in parallel.

Error message and sporadic error

I found the bug causing the error message and also the reason for "sporadic" problems. It happens when the snapshot being used does not match the current group.

All should be fixed in the next release available latest end of coming week (2020-12-18) - together with an example flow based on your nice split/join flow.

hklages commented 3 years ago

Hi. I just published the 4.5.4. That should fix the sporadic error. If you go to import, example, node-red-contrib-sonos-plus you find 2 examples. Take example 09 and use it to build your flow. You only have to put the notification in the middle.

Please let me know, whether the sporadic errors disappear.