Smart TTS for Home Assistant

How it works:

If nothing is playing, TTS will say the message and set the previous volume.

If the speaker is playing something from URL, Spotify or YouTube music, TTS will say message, set the previous volume, and resume playing.

Known issues:

  • If you are playing playlist directly from YouTube music instead of ytube music player integration, then after TTS only track will be resumed, not the whole playlist. HA media player provides the only name of playing playlist what is not enough information for the system to know what playlist should it play after TTS.

  • If you are sending TTS for a group, and speakers of this group aren't in this same state, then it causes unwanted behavior

If you know how to fix any of those issues please contact me (darkjumpy@gmail.com).

Requirements:

How to start:

  1. Double click on Smart TTS node under subflows
  2. Setup your config
  3. Done!

Input variables:

  • msg.speaker (required) ID of Google Cast-enabled speaker.

  • msg.message (required) TTS message.

  • msg.volume (optional) The volume of TTS messages. If the variable is not provided volume is not changing.

  • msg.tts_service (optional) TTS service used to say message. If variable is not provided default TTS service is used.

[{"id":"3e3d3934.fbc6d6","type":"subflow","name":"Smart TTS","info":"If nothing is playing, TTS will say the message and set the previous volume.\nIf the speaker is playing something from URL, Spotify or YouTube music, TTS will \nsay message, set the previous volume, and resume playing. (More info in README)","category":"","in":[{"x":60,"y":340,"wires":[{"id":"d5e8c87966b22e98"}]}],"out":[{"x":3400,"y":440,"wires":[{"id":"3f076a8f58dfc56c","port":0},{"id":"f6ec512f88c189e6","port":1}]}],"env":[],"meta":{"module":"Smart TTS","type":"TTS","version":"1.3.1","author":"IT freak Jake","keywords":"HomeAssistant, TTS, GoogleHome, Alexa"},"color":"#A6BBCF","icon":"node-red-contrib-cast/google-home-mini2.svg"},{"id":"066ed1257cae1df0","type":"group","z":"3e3d3934.fbc6d6","name":"Smart TTS","style":{"stroke":"#7f7f7f","fill":"#7f7f7f","fill-opacity":"0.5","label":true,"color":"#ffffff"},"nodes":["44f34f0c52659971","e6dd074f2ea3bc0d","0d6f89101aca78f4","197abba88c1324f5","db80cd457a851c07","5730dc3d115d2688","cfcc6f3f7e982f8c","6657ec7501ad8137","bc40469aabd918e8","847406122c07558c","53c66210e71ee4fb","d27cceb034ea5156","48aa78022ed8ef2f","85dd8af450d1d465","df70af48a130f602","3fdd5edae3cb1dc1","e4ea572d031d0ba7","435032474aed39f5","5f09360362d5e81b","8db273c85d1f4b04","b9c102631689476d","4b9d74d12cbd3e65","df3d995d84e9d2a1","3d1bdae6980660a7","dc7b3b8c84ba81b3","fa06bc39f6a3f587","628d5eb3df91c82b"],"x":14,"y":173,"w":3408,"h":468},{"id":"847406122c07558c","type":"group","z":"3e3d3934.fbc6d6","g":"066ed1257cae1df0","name":"Input","style":{"label":true},"nodes":["dd5da2561d1da094","1e37368a3df1025c","d2c059c5008bde4f","112de556e278482b","9b19615010b376bd","80f20973bdbdf8bc","d5e8c87966b22e98"],"x":74,"y":279,"w":342,"h":122},{"id":"53c66210e71ee4fb","type":"group","z":"3e3d3934.fbc6d6","g":"066ed1257cae1df0","name":"Finding right spotify account","style":{"label":true},"nodes":["e78353045515f7ac","6c5f41b09fec25df","e7ef777a7a6a045b","f7a3183be871f7be","fefc8eafda0a45d3"],"x":2054,"y":199,"w":202,"h":122},{"id":"d27cceb034ea5156","type":"group","z":"3e3d3934.fbc6d6","g":"066ed1257cae1df0","name":"Google TTS","style":{"label":true},"nodes":["a17e2b9756663274","702dffcc5490bb73","f888d49f2f9eb005","b0873892e8b7fbbb","6cd4dde5d62342ab","f546cb88fbc5731f","7f8df83e9505adc9","ac42a053329cbf4b","b97e31754ff057e1","7d62342f06f99e2b","50e99bb2719a3f28"],"x":2274,"y":356.5,"w":482,"h":127},{"id":"48aa78022ed8ef2f","type":"group","z":"3e3d3934.fbc6d6","g":"066ed1257cae1df0","name":"Initial media type recognition","style":{"label":true},"nodes":["d319ad189b10e442","3ffd12db55d5d4f7","2c7d414d5ce3d55c","6c22ee606bc18a49","1fc09ff71f8b284f","3da46c7a5d14a695","b1f786f11d3f4ff5","8d38296d8f450521"],"x":1394,"y":239,"w":242,"h":222},{"id":"85dd8af450d1d465","type":"group","z":"3e3d3934.fbc6d6","g":"066ed1257cae1df0","name":"Output","style":{"label":true},"nodes":["f6ec512f88c189e6","3f076a8f58dfc56c","e43cf9554a16153f","f673bb49a0efe0d8"],"x":3234,"y":359,"w":162,"h":142},{"id":"df70af48a130f602","type":"group","z":"3e3d3934.fbc6d6","g":"066ed1257cae1df0","name":"URL resume","style":{"label":true},"nodes":["7bf2cba7be12c0ab","f71c9d143e44c939","37c3dc3962fdb048","906d9044423b3c0e","455aa9ada539bd23","4964d71cfc6a381d","c10fa6b314c14cb3","4f534abc1e3b5d13"],"x":2814,"y":479,"w":362,"h":102},{"id":"3fdd5edae3cb1dc1","type":"group","z":"3e3d3934.fbc6d6","g":"066ed1257cae1df0","name":"Getting spotify accounts data","style":{"label":true},"nodes":["336644d9ab890862","b7ba3ae27f20c256","c787d03aa23c1bed","bc998ed765619c8d","28bc62ecb9f97b72","edf546d8678d9d28"],"x":1654,"y":219,"w":282,"h":102},{"id":"e4ea572d031d0ba7","type":"group","z":"3e3d3934.fbc6d6","g":"066ed1257cae1df0","name":"Spotify resume","style":{"label":true},"nodes":["e2e2dbece34f204a","d1c952b1829de173","d3f6b9920ed775bf","ac4182012b76547c"],"x":2814,"y":199,"w":162,"h":122},{"id":"435032474aed39f5","type":"group","z":"3e3d3934.fbc6d6","g":"066ed1257cae1df0","name":"Getting ytube accounts data","style":{"label":true},"nodes":["b1ed0e4502e868ec","d62a6e8382a0b0d9","a061f5aa036aac7a","4ce1843a0dc41d2c","1589c198804e476a","fb5d263edc8e1fa5"],"x":1654,"y":339,"w":282,"h":102},{"id":"5f09360362d5e81b","type":"group","z":"3e3d3934.fbc6d6","g":"066ed1257cae1df0","name":"Finding right ytube account","style":{"label":true},"nodes":["e873bc062009dd69","e6e24ed61aa7f756","b7fafb402587e5ed","21bebf04e67eea85","23a123904807c5dc","064d732d19478a76"],"x":1954,"y":339,"w":302,"h":102},{"id":"8db273c85d1f4b04","type":"group","z":"3e3d3934.fbc6d6","g":"066ed1257cae1df0","name":"YouTube music resume","style":{"label":true},"nodes":["df4dbbbcd9bab984","2ea3596d48999a54","c881ccccfc5106c8","96e41efe7416310d","8c17ed997d95b47c","946db825271e70fe","90f3d929d2f350a9","adf6e8ed5be0fba7","cdd2dcb74f70afd5"],"x":2814,"y":339,"w":362,"h":122},{"id":"b9c102631689476d","type":"group","z":"3e3d3934.fbc6d6","g":"066ed1257cae1df0","name":"Alexa TTS","style":{"label":true},"nodes":["3b512a399c7eacb5","b6176ac0e7c4a21c","9b8c5c2b1e178dc9","356ad3b53d40d040","2d5633eadb576528","77c5dbb579d16c3e","a74b0f14555de090","2505628870b85dc6","99d22c066760b088","999e89fc46396b94"],"x":2314,"y":499,"w":442,"h":102},{"id":"4b9d74d12cbd3e65","type":"group","z":"3e3d3934.fbc6d6","g":"066ed1257cae1df0","name":"Error handling","style":{"label":true},"nodes":["ab7ec373068e28fb","1e1403ab211b4b11"],"x":114,"y":419,"w":222,"h":82},{"id":"df3d995d84e9d2a1","type":"group","z":"3e3d3934.fbc6d6","g":"066ed1257cae1df0","name":"Getting speakers groups info","style":{"label":true},"nodes":["5a1f368902eb0a12","439642d88e48109f","b1a1f2a6ba107ea2","bb833fe4ab6e20b8","c7a912d0f8fc62de","b1c761bed53d40a9"],"x":434,"y":259,"w":282,"h":102},{"id":"3d1bdae6980660a7","type":"group","z":"3e3d3934.fbc6d6","g":"066ed1257cae1df0","name":"Is it group","style":{"label":true},"nodes":["743515015cc33efd","514a87c252fde2f9","76e6aa845545b821"],"x":734,"y":259,"w":162,"h":102},{"id":"dc7b3b8c84ba81b3","type":"group","z":"3e3d3934.fbc6d6","g":"066ed1257cae1df0","name":"Get group speakers info","style":{"label":true},"nodes":["384861426abe5b8c","31d6ba68118e9ac6","d294aed085fda93c","7dd78dad790672e8","addaed19b41880be","fcae45f78aa92775"],"x":914,"y":259,"w":282,"h":102},{"id":"fa06bc39f6a3f587","type":"group","z":"3e3d3934.fbc6d6","g":"066ed1257cae1df0","name":"Get more speaker info","style":{"label":true},"nodes":["6f211fb74b2b7f49","c43eca78f57978d1","4a4e522685dc3866"],"x":1214,"y":259,"w":162,"h":82},{"id":"3801c35.52e3d3c","type":"inject","z":"3e3d3934.fbc6d6","name":"Minimal configuration example","props":[{"p":"speaker","v":"media_player.google_home_speaker","vt":"str"},{"p":"message","v":"Smart TTS test","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":160,"y":20,"wires":[[]]},{"id":"9d48e8b2.66b518","type":"inject","z":"3e3d3934.fbc6d6","name":"Full configuration example","props":[{"p":"speaker","v":"media_player.google_home_speaker","vt":"str"},{"p":"message","v":"Smart TTS test","vt":"str"},{"p":"volume","v":"0.6","vt":"num"},{"p":"tts_service","v":"google_translate_say","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":150,"y":60,"wires":[[]]},{"id":"a92ec755.7755c8","type":"inject","z":"3e3d3934.fbc6d6","name":"Full configuration example (Alexa)","props":[{"p":"speaker","v":"media_player.alexa_speaker","vt":"str"},{"p":"message","v":"Smart TTS test","vt":"str"},{"p":"volume","v":"0.6","vt":"num"},{"p":"tts_service","v":"alexa_default","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":180,"y":140,"wires":[[]]},{"id":"d0df345.46a3dc8","type":"inject","z":"3e3d3934.fbc6d6","name":"Minimal configuration example (Alexa)","props":[{"p":"speaker","v":"media_player.alexa_speaker","vt":"str"},{"p":"message","v":"Smart TTS test","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":190,"y":100,"wires":[[]]},{"id":"44f34f0c52659971","type":"comment","z":"3e3d3934.fbc6d6","g":"066ed1257cae1df0","name":"README","info":"How it works:\n\nIf nothing is playing, TTS will say the message and set the previous volume.\n\nIf the speaker is playing something from URL, Spotify or YouTube music, TTS will \nsay message, set the previous volume, and resume playing.\n\nKnown issues: \n- If you are playing playlist directly from YouTube music instead of ytube music player integration,\nthen after TTS only track will be resumed, not the whole playlist. HA media player provides the only \nname of playing playlist what is not enough information for the system to know what \nplaylist should it play after TTS.\n\n- If you are sending TTS for a group, and speakers of this group aren't in this same state, \nthen it causes unwanted behavior\n\nIf you know how to fix any of those issues please contact me ([email protected]).\n\nRequirements:\n- Home Assistant\nIf you are using Google Home speakers\n- Official Home Assistant Google Cast integration\nIf you are using Alexa speakers\n- Custom Home Assistant Alexa Media Player integration (https://github.com/custom-components/alexa_media_player)\nIf you are using Spotify: \n- Official Home Assistant Spotify integration\n- Custom Home Assistant Spotcast integration (https://github.com/fondberg/spotcast)\nIf you are using YouTube music:\n- Custom Home Assistant ytube music player integration (https://github.com/KoljaWindeler/ytube_music_player)\n\nHow to start:\n1. Double click on Smart TTS node under subflows\n2. Setup your config\n3. Done!\n\nInput variables:\n\n- msg.speaker (required)\n    ID of Google Cast-enabled speaker.\n\n- msg.message (required)\n    TTS message.\n\n- msg.volume (optional)\n    The volume of TTS messages. If the variable is not \n    provided volume is not changing.\n    \n- msg.tts_service (optional)\n    TTS service used to say message. If variable \n    is not provided default TTS service is used.\n","x":100,"y":240,"wires":[]},{"id":"e6dd074f2ea3bc0d","type":"function","z":"3e3d3934.fbc6d6","g":"066ed1257cae1df0","name":"Connector","func":"return msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":2835,"y":600,"wires":[["0d6f89101aca78f4"]],"icon":"node-red/inject.svg","l":false},{"id":"0d6f89101aca78f4","type":"function","z":"3e3d3934.fbc6d6","g":"066ed1257cae1df0","name":"Connector","func":"return msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":3155,"y":600,"wires":[["f673bb49a0efe0d8"]],"icon":"node-red/inject.svg","l":false},{"id":"197abba88c1324f5","type":"function","z":"3e3d3934.fbc6d6","g":"066ed1257cae1df0","name":"Connector","func":"return msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1695,"y":460,"wires":[["db80cd457a851c07"]],"icon":"node-red/inject.svg","l":false},{"id":"db80cd457a851c07","type":"function","z":"3e3d3934.fbc6d6","g":"066ed1257cae1df0","name":"Connector","func":"return msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":2235,"y":460,"wires":[["50e99bb2719a3f28"]],"icon":"node-red/inject.svg","l":false},{"id":"5730dc3d115d2688","type":"function","z":"3e3d3934.fbc6d6","g":"066ed1257cae1df0","name":"Connector","func":"return msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":515,"y":560,"wires":[["99d22c066760b088"]],"icon":"node-red/inject.svg","l":false},{"id":"cfcc6f3f7e982f8c","type":"function","z":"3e3d3934.fbc6d6","g":"066ed1257cae1df0","name":"Connector","func":"return msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":3155,"y":300,"wires":[["f673bb49a0efe0d8"]],"icon":"node-red/inject.svg","l":false},{"id":"6657ec7501ad8137","type":"function","z":"3e3d3934.fbc6d6","g":"066ed1257cae1df0","name":"Connector","func":"return msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":955,"y":380,"wires":[["bc40469aabd918e8"]],"icon":"node-red/inject.svg","l":false},{"id":"bc40469aabd918e8","type":"function","z":"3e3d3934.fbc6d6","g":"066ed1257cae1df0","name":"Connector","func":"return msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1155,"y":380,"wires":[["6f211fb74b2b7f49"]],"icon":"node-red/inject.svg","l":false},{"id":"dd5da2561d1da094","type":"switch","z":"3e3d3934.fbc6d6","g":"847406122c07558c","name":"TTS type","property":"tts_service","propertyType":"msg","rules":[{"t":"neq","v":"alexa_default","vt":"str"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":255,"y":340,"wires":[["9b19615010b376bd"],["d2c059c5008bde4f"]],"l":false},{"id":"1e37368a3df1025c","type":"api-current-state","z":"3e3d3934.fbc6d6","g":"847406122c07558c","name":"Speaker current state","server":"918a63e0.1bc5a","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"{{speaker}}","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"speaker_data","propertyType":"msg","value":"","valueType":"entity"}],"for":0,"forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":375,"y":360,"wires":[["5730dc3d115d2688"]],"l":false},{"id":"d2c059c5008bde4f","type":"api-call-service","z":"3e3d3934.fbc6d6","g":"847406122c07558c","name":"Turn on speaker","server":"918a63e0.1bc5a","version":3,"debugenabled":false,"service_domain":"media_player","service":"turn_on","entityId":"{{speaker}}","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":295,"y":360,"wires":[["112de556e278482b"]],"l":false},{"id":"112de556e278482b","type":"ha-wait-until","z":"3e3d3934.fbc6d6","g":"847406122c07558c","name":"Wait for turning on","server":"918a63e0.1bc5a","version":0,"outputs":2,"entityId":"{{speaker}}","entityIdFilterType":"exact","property":"state","comparator":"is_not","value":"off","valueType":"str","timeout":"5","timeoutType":"num","timeoutUnits":"seconds","entityLocation":"","entityLocationType":"none","checkCurrentState":true,"blockInputOverrides":true,"x":335,"y":360,"wires":[["1e37368a3df1025c"],["1e37368a3df1025c"]],"l":false},{"id":"9b19615010b376bd","type":"api-current-state","z":"3e3d3934.fbc6d6","g":"847406122c07558c","name":"Speaker current state","server":"918a63e0.1bc5a","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"{{speaker}}","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"speaker_data","propertyType":"msg","value":"","valueType":"entity"}],"for":0,"forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":315,"y":320,"wires":[["80f20973bdbdf8bc"]],"l":false},{"id":"e78353045515f7ac","type":"function","z":"3e3d3934.fbc6d6","g":"53c66210e71ee4fb","name":"Find right spotify account","func":"let playing_accounts_count=0,\nplaying_spotify_account,\nplaying_spotcast_account,\nspeaker_media_content_id,\nspeaker_friendly_name;\n\nif(msg.is_it_speaker_in_group===true)\n{\n    speaker_media_content_id=msg.speakers_groups_data[msg.which_speaker_group].attributes.media_content_id;\n    speaker_friendly_name=msg.speakers_groups_data[msg.which_speaker_group].attributes.friendly_name;\n}\nelse\n{\n    speaker_media_content_id=msg.speaker_data.attributes.media_content_id;\n    speaker_friendly_name=msg.speaker_data.attributes.friendly_name;\n}\n\nfor(i=0;i<msg.spotify_accounts_count;i++)\n{\n    if(!msg.compare_spotify_speaker_name)\n    {\n        if(msg.spotify_accounts_data[i].state===\"playing\")\n        {\n            playing_accounts_count++;\n            playing_spotify_account=msg.spotify_accounts[i];\n            playing_spotcast_account=msg.spotcast_accounts[i];\n        }\n        if(speaker_media_content_id===msg.spotify_accounts_data[i].attributes.media_content_id)\n        {\n            msg.is_right_account_found=true;\n            msg.right_spotify_account=msg.spotify_accounts[i];\n            msg.right_spotify_account_source=msg.spotify_accounts_data[i].attributes.source;\n            msg.right_spotcast_account=msg.spotcast_accounts[i];\n            break;\n        }\n    }\n    else\n    {\n        if(speaker_friendly_name===msg.spotify_accounts_data[i].attributes.source)\n        {\n            msg.is_right_account_found=true;\n            msg.right_spotify_account=msg.spotify_accounts[i];\n            msg.right_spotify_account_source=msg.spotify_accounts_data[i].attributes.source;\n            msg.right_spotcast_account=msg.spotcast_accounts[i];\n            break;\n        }\n    }\n}\nif(!msg.compare_spotify_speaker_name && !msg.spotify_require_identical_media_content_id && !msg.is_right_account_found && playing_accounts_count==1)\n{\n    msg.is_right_account_found=true;\n    msg.right_spotify_account=playing_spotify_account;\n    msg.right_spotcast_account=playing_spotcast_account;\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":2095,"y":260,"wires":[["6c5f41b09fec25df"]],"l":false},{"id":"6c5f41b09fec25df","type":"switch","z":"3e3d3934.fbc6d6","g":"53c66210e71ee4fb","name":"Is right account found","property":"is_right_account_found","propertyType":"msg","rules":[{"t":"true"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":2135,"y":260,"wires":[["f7a3183be871f7be"],["e7ef777a7a6a045b"]],"l":false},{"id":"e7ef777a7a6a045b","type":"change","z":"3e3d3934.fbc6d6","g":"53c66210e71ee4fb","name":"Set media type to NONE","rules":[{"t":"set","p":"media_type","pt":"msg","to":"NONE","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":2175,"y":280,"wires":[["fefc8eafda0a45d3"]],"l":false},{"id":"f7a3183be871f7be","type":"change","z":"3e3d3934.fbc6d6","g":"53c66210e71ee4fb","name":"Set media type to spotify","rules":[{"t":"set","p":"media_type","pt":"msg","to":"spotify","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":2175,"y":240,"wires":[["fefc8eafda0a45d3"]],"l":false},{"id":"fefc8eafda0a45d3","type":"function","z":"3e3d3934.fbc6d6","g":"53c66210e71ee4fb","name":"Connector","func":"return msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":2215,"y":260,"wires":[["50e99bb2719a3f28"]],"icon":"node-red/inject.svg","l":false},{"id":"a17e2b9756663274","type":"api-call-service","z":"3e3d3934.fbc6d6","g":"d27cceb034ea5156","name":"Pause speaker","server":"918a63e0.1bc5a","version":3,"debugenabled":false,"service_domain":"media_player","service":"media_pause","entityId":"{{resume_speaker}}","data":"","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":2355,"y":420,"wires":[["ac42a053329cbf4b"]],"l":false},{"id":"702dffcc5490bb73","type":"api-call-service","z":"3e3d3934.fbc6d6","g":"d27cceb034ea5156","name":"TTS","server":"918a63e0.1bc5a","version":3,"debugenabled":false,"service_domain":"tts","service":"{{tts_service}}","entityId":"{{tts_speaker}}","data":"{\"message\":\"{{message}}\"}","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":2475,"y":420,"wires":[["7d62342f06f99e2b"]],"l":false},{"id":"f888d49f2f9eb005","type":"ha-wait-until","z":"3e3d3934.fbc6d6","g":"d27cceb034ea5156","name":"Wait for start","server":"918a63e0.1bc5a","version":0,"outputs":2,"entityId":"{{tts_speaker}}","entityIdFilterType":"exact","property":"state","comparator":"is","value":"playing","valueType":"str","timeout":"25","timeoutType":"num","timeoutUnits":"seconds","entityLocation":"","entityLocationType":"none","checkCurrentState":true,"blockInputOverrides":true,"x":2555,"y":420,"wires":[["b0873892e8b7fbbb"],[]],"l":false},{"id":"b0873892e8b7fbbb","type":"delay","z":"3e3d3934.fbc6d6","g":"d27cceb034ea5156","name":"","pauseType":"delay","timeout":"2","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":2595,"y":420,"wires":[["6cd4dde5d62342ab"]],"l":false},{"id":"6cd4dde5d62342ab","type":"ha-wait-until","z":"3e3d3934.fbc6d6","g":"d27cceb034ea5156","name":"Wait for end","server":"918a63e0.1bc5a","version":0,"outputs":2,"entityId":"{{tts_speaker}}","entityIdFilterType":"exact","property":"state","comparator":"is_not","value":"playing","valueType":"str","timeout":"5","timeoutType":"num","timeoutUnits":"minutes","entityLocation":"","entityLocationType":"none","checkCurrentState":true,"blockInputOverrides":true,"x":2635,"y":420,"wires":[["7f8df83e9505adc9"],[]],"l":false},{"id":"f546cb88fbc5731f","type":"api-call-service","z":"3e3d3934.fbc6d6","g":"d27cceb034ea5156","name":"Set volume","server":"918a63e0.1bc5a","version":3,"debugenabled":false,"service_domain":"media_player","service":"volume_set","entityId":"{{tts_speaker}}","data":"{\"volume_level\":\"{{volume}}\"}","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":2435,"y":400,"wires":[["702dffcc5490bb73"]],"l":false},{"id":"7f8df83e9505adc9","type":"api-call-service","z":"3e3d3934.fbc6d6","g":"d27cceb034ea5156","name":"Set volume","server":"918a63e0.1bc5a","version":3,"debugenabled":false,"service_domain":"media_player","service":"volume_set","entityId":"{{tts_speaker}}","data":"{\"volume_level\":\"{{speaker_data.attributes.volume_level}}\"}","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":2675,"y":420,"wires":[["b97e31754ff057e1"]],"l":false},{"id":"ac42a053329cbf4b","type":"switch","z":"3e3d3934.fbc6d6","g":"d27cceb034ea5156","name":"","property":"volume","propertyType":"msg","rules":[{"t":"btwn","v":"0","vt":"num","v2":"1","v2t":"num"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":2395,"y":420,"wires":[["f546cb88fbc5731f"],["702dffcc5490bb73"]],"l":false},{"id":"b97e31754ff057e1","type":"switch","z":"3e3d3934.fbc6d6","g":"d27cceb034ea5156","name":"Which media type resume","property":"media_type","propertyType":"msg","rules":[{"t":"eq","v":"spotify","vt":"str"},{"t":"eq","v":"ytube","vt":"str"},{"t":"eq","v":"YouTube","vt":"str"},{"t":"eq","v":"url","vt":"str"},{"t":"else"}],"checkall":"false","repair":false,"outputs":5,"x":2715,"y":420,"wires":[["d1c952b1829de173"],["df4dbbbcd9bab984"],["2ea3596d48999a54"],["f71c9d143e44c939"],["e6dd074f2ea3bc0d"]],"l":false},{"id":"7d62342f06f99e2b","type":"delay","z":"3e3d3934.fbc6d6","g":"d27cceb034ea5156","name":"","pauseType":"delay","timeout":"700","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"outputs":1,"x":2515,"y":420,"wires":[["f888d49f2f9eb005"]],"l":false},{"id":"50e99bb2719a3f28","type":"function","z":"3e3d3934.fbc6d6","g":"d27cceb034ea5156","name":"Setup IDs","func":"if(msg.is_it_speaker_in_group===true)\n{\n    msg.tts_speaker=msg.speaker;\n    msg.resume_speaker=msg.speakers_groups[msg.which_speaker_group];\n    msg.resume_speaker_friendly_name=msg.speakers_groups_data[msg.which_speaker_group].attributes.friendly_name;\n}\nelse\n{\n    msg.tts_speaker=msg.speaker;\n    msg.resume_speaker=msg.speaker;\n    msg.resume_speaker_friendly_name=msg.speaker_data.attributes.friendly_name;\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":2315,"y":420,"wires":[["a17e2b9756663274"]],"l":false},{"id":"d319ad189b10e442","type":"switch","z":"3e3d3934.fbc6d6","g":"48aa78022ed8ef2f","name":"Is it Spotify?","property":"speaker_data.attributes.app_name","propertyType":"msg","rules":[{"t":"eq","v":"Spotify","vt":"str"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":1475,"y":300,"wires":[["3da46c7a5d14a695"],["1fc09ff71f8b284f"]],"l":false},{"id":"3ffd12db55d5d4f7","type":"change","z":"3e3d3934.fbc6d6","g":"48aa78022ed8ef2f","name":"Set media type to NONE","rules":[{"t":"set","p":"media_type","pt":"msg","to":"NONE","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1475,"y":420,"wires":[["197abba88c1324f5"]],"l":false},{"id":"2c7d414d5ce3d55c","type":"change","z":"3e3d3934.fbc6d6","g":"48aa78022ed8ef2f","name":"Set media type to url","rules":[{"t":"set","p":"media_type","pt":"msg","to":"url","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1595,"y":420,"wires":[["197abba88c1324f5"]],"l":false},{"id":"6c22ee606bc18a49","type":"switch","z":"3e3d3934.fbc6d6","g":"48aa78022ed8ef2f","name":"Is it YT?","property":"media_type","propertyType":"msg","rules":[{"t":"eq","v":"YouTube","vt":"str"},{"t":"eq","v":"ytube","vt":"str"},{"t":"else"}],"checkall":"false","repair":false,"outputs":3,"x":1555,"y":360,"wires":[["b1f786f11d3f4ff5"],["b1f786f11d3f4ff5"],["2c7d414d5ce3d55c"]],"l":false},{"id":"1fc09ff71f8b284f","type":"function","z":"3e3d3934.fbc6d6","g":"48aa78022ed8ef2f","name":"Is it YT?","func":"msg.media_type=msg.speaker_data.attributes.app_name==\"YouTube Music\" ? \"YouTube\":\"url\";\nif(msg.media_type==\"url\")msg.media_type=msg.speaker_data.attributes.media_content_id.includes(\".googlevideo.\") ? \"ytube\":\"url\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1515,"y":360,"wires":[["6c22ee606bc18a49"]],"l":false},{"id":"3da46c7a5d14a695","type":"switch","z":"3e3d3934.fbc6d6","g":"48aa78022ed8ef2f","name":"Use Spotify?","property":"spotify_accounts_count","propertyType":"msg","rules":[{"t":"gte","v":"1","vt":"num"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":1515,"y":280,"wires":[["edf546d8678d9d28"],["3ffd12db55d5d4f7"]],"l":false},{"id":"b1f786f11d3f4ff5","type":"switch","z":"3e3d3934.fbc6d6","g":"48aa78022ed8ef2f","name":"Use YT?","property":"ytube_accounts_count","propertyType":"msg","rules":[{"t":"gte","v":"1","vt":"num"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":1595,"y":360,"wires":[["fb5d263edc8e1fa5"],["3ffd12db55d5d4f7"]],"l":false},{"id":"8d38296d8f450521","type":"switch","z":"3e3d3934.fbc6d6","g":"48aa78022ed8ef2f","name":"Is speaker playing","property":"speaker_data.state","propertyType":"msg","rules":[{"t":"eq","v":"playing","vt":"str"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":1435,"y":320,"wires":[["d319ad189b10e442"],["3ffd12db55d5d4f7"]],"l":false},{"id":"f6ec512f88c189e6","type":"switch","z":"3e3d3934.fbc6d6","g":"85dd8af450d1d465","name":"Delete variables?","property":"delete_variables","propertyType":"msg","rules":[{"t":"true"},{"t":"false"}],"checkall":"false","repair":false,"outputs":2,"x":3315,"y":420,"wires":[["3f076a8f58dfc56c"],[]],"l":false},{"id":"3f076a8f58dfc56c","type":"change","z":"3e3d3934.fbc6d6","g":"85dd8af450d1d465","name":"Delete variables","rules":[{"t":"delete","p":"speaker","pt":"msg"},{"t":"delete","p":"message","pt":"msg"},{"t":"delete","p":"volume","pt":"msg"},{"t":"delete","p":"tts_service","pt":"msg"},{"t":"delete","p":"spotify_accounts","pt":"msg"},{"t":"delete","p":"spotcast_accounts","pt":"msg"},{"t":"delete","p":"spotify_require_identical_media_content_id","pt":"msg"},{"t":"delete","p":"compare_spotify_speaker_name","pt":"msg"},{"t":"delete","p":"use_spotify_speaker_name","pt":"msg"},{"t":"delete","p":"debug","pt":"msg"},{"t":"delete","p":"spotify_accounts_count","pt":"msg"},{"t":"delete","p":"spotify_accounts_data","pt":"msg"},{"t":"delete","p":"speaker_data","pt":"msg"},{"t":"delete","p":"is_right_account_found","pt":"msg"},{"t":"delete","p":"right_spotify_account","pt":"msg"},{"t":"delete","p":"right_spotify_account_source","pt":"msg"},{"t":"delete","p":"right_spotcast_account","pt":"msg"},{"t":"delete","p":"media_type","pt":"msg"},{"t":"delete","p":"media_position","pt":"msg"},{"t":"delete","p":"delete_variables","pt":"msg"},{"t":"delete","p":"ytube_accounts","pt":"msg"},{"t":"delete","p":"ytube_accounts_count","pt":"msg"},{"t":"delete","p":"ytube_accounts_data","pt":"msg"},{"t":"delete","p":"right_ytube_account","pt":"msg"},{"t":"delete","p":"alexa_notify_service","pt":"msg"},{"t":"delete","p":"delay","pt":"msg"},{"t":"delete","p":"alexa_pause_on_tts","pt":"msg"},{"t":"delete","p":"speakers_groups","pt":"msg"},{"t":"delete","p":"speakers_inside_groups","pt":"msg"},{"t":"delete","p":"is_it_group","pt":"msg"},{"t":"delete","p":"is_it_speaker_in_group","pt":"msg"},{"t":"delete","p":"speakers_groups_count","pt":"msg"},{"t":"delete","p":"speakers_groups_data","pt":"msg"},{"t":"delete","p":"tts_speaker","pt":"msg"},{"t":"delete","p":"resume_speaker","pt":"msg"},{"t":"delete","p":"resume_speaker_friendly_name","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":3355,"y":400,"wires":[[]],"l":false},{"id":"e43cf9554a16153f","type":"function","z":"3e3d3934.fbc6d6","g":"85dd8af450d1d465","name":"Debug","func":"if(msg.debug)\n{\n    node.warn(\"Smart TTS debug output: \");\n    node.warn(msg);\n}","outputs":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":3315,"y":460,"wires":[],"icon":"font-awesome/fa-bug","l":false},{"id":"f673bb49a0efe0d8","type":"function","z":"3e3d3934.fbc6d6","g":"85dd8af450d1d465","name":"Connector","func":"return msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":3275,"y":440,"wires":[["f6ec512f88c189e6","e43cf9554a16153f"]],"icon":"node-red/inject.svg","l":false},{"id":"7bf2cba7be12c0ab","type":"api-call-service","z":"3e3d3934.fbc6d6","g":"df70af48a130f602","name":"URL resume","server":"918a63e0.1bc5a","version":3,"debugenabled":false,"service_domain":"media_player","service":"play_media","entityId":"{{resume_speaker}}","data":"{    \"media_content_id\": \"\"& speaker_data.attributes.media_content_id &\"\",    \"media_content_type\": \"audio/mp3\"}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":2895,"y":540,"wires":[["37c3dc3962fdb048"]],"l":false},{"id":"f71c9d143e44c939","type":"delay","z":"3e3d3934.fbc6d6","g":"df70af48a130f602","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"outputs":1,"x":2855,"y":540,"wires":[["7bf2cba7be12c0ab"]],"l":false},{"id":"37c3dc3962fdb048","type":"switch","z":"3e3d3934.fbc6d6","g":"df70af48a130f602","name":"Has duration?","property":"speaker_data.attributes.media_position","propertyType":"msg","rules":[{"t":"istype","v":"number","vt":"number"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":2935,"y":540,"wires":[["906d9044423b3c0e"],["4f534abc1e3b5d13"]],"l":false},{"id":"906d9044423b3c0e","type":"function","z":"3e3d3934.fbc6d6","g":"df70af48a130f602","name":"Float to int","func":"msg.media_position=Math.floor(msg.speaker_data.attributes.media_position);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":2975,"y":520,"wires":[["455aa9ada539bd23"]],"l":false},{"id":"455aa9ada539bd23","type":"delay","z":"3e3d3934.fbc6d6","g":"df70af48a130f602","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"outputs":1,"x":3015,"y":520,"wires":[["4964d71cfc6a381d"]],"l":false},{"id":"4964d71cfc6a381d","type":"ha-wait-until","z":"3e3d3934.fbc6d6","g":"df70af48a130f602","name":"Wait for start","server":"918a63e0.1bc5a","version":0,"outputs":2,"entityId":"{{resume_speaker}}","entityIdFilterType":"exact","property":"state","comparator":"is","value":"playing","valueType":"str","timeout":"25","timeoutType":"num","timeoutUnits":"seconds","entityLocation":"","entityLocationType":"none","checkCurrentState":true,"blockInputOverrides":true,"x":3055,"y":520,"wires":[["c10fa6b314c14cb3"],["c10fa6b314c14cb3"]],"l":false},{"id":"c10fa6b314c14cb3","type":"api-call-service","z":"3e3d3934.fbc6d6","g":"df70af48a130f602","name":"URL set position","server":"918a63e0.1bc5a","version":3,"debugenabled":false,"service_domain":"media_player","service":"media_seek","entityId":"{{resume_speaker}}","data":"{    \"seek_position\": {{media_position}}}","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":3095,"y":520,"wires":[["4f534abc1e3b5d13"]],"l":false},{"id":"4f534abc1e3b5d13","type":"function","z":"3e3d3934.fbc6d6","g":"df70af48a130f602","name":"Connector","func":"return msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":3135,"y":540,"wires":[["f673bb49a0efe0d8"]],"icon":"node-red/inject.svg","l":false},{"id":"336644d9ab890862","type":"api-current-state","z":"3e3d3934.fbc6d6","g":"3fdd5edae3cb1dc1","name":"Spotify current state","server":"918a63e0.1bc5a","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"{{spotify_temporary_account}}","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"spotify_temporary_data","propertyType":"msg","value":"","valueType":"entity"}],"for":0,"forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":1775,"y":280,"wires":[["b7ba3ae27f20c256"]],"l":false},{"id":"b7ba3ae27f20c256","type":"function","z":"3e3d3934.fbc6d6","g":"3fdd5edae3cb1dc1","name":"Set data","func":"msg.spotify_accounts_data[msg.counter]=msg.spotify_temporary_data;\nmsg.counter++;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1815,"y":280,"wires":[["c787d03aa23c1bed"]],"l":false},{"id":"c787d03aa23c1bed","type":"switch","z":"3e3d3934.fbc6d6","g":"3fdd5edae3cb1dc1","name":"Is it all?","property":"counter","propertyType":"msg","rules":[{"t":"gte","v":"spotify_accounts_count","vt":"msg"},{"t":"lt","v":"spotify_accounts_count","vt":"msg"}],"checkall":"false","repair":false,"outputs":2,"x":1855,"y":280,"wires":[["28bc62ecb9f97b72"],["bc998ed765619c8d"]],"l":false},{"id":"bc998ed765619c8d","type":"function","z":"3e3d3934.fbc6d6","g":"3fdd5edae3cb1dc1","name":"Set account","func":"msg.spotify_temporary_account=msg.spotify_accounts[msg.counter];\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1735,"y":280,"wires":[["336644d9ab890862"]],"l":false},{"id":"28bc62ecb9f97b72","type":"change","z":"3e3d3934.fbc6d6","g":"3fdd5edae3cb1dc1","name":"Delete","rules":[{"t":"delete","p":"spotify_temporary_account","pt":"msg"},{"t":"delete","p":"spotify_temporary_data","pt":"msg"},{"t":"delete","p":"counter","pt":"msg"},{"t":"set","p":"is_right_account_found","pt":"msg","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":1895,"y":260,"wires":[["e78353045515f7ac"]],"l":false},{"id":"edf546d8678d9d28","type":"change","z":"3e3d3934.fbc6d6","g":"3fdd5edae3cb1dc1","name":"Set counter","rules":[{"t":"set","p":"counter","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":1695,"y":260,"wires":[["bc998ed765619c8d"]],"l":false},{"id":"e2e2dbece34f204a","type":"api-call-service","z":"3e3d3934.fbc6d6","g":"e4ea572d031d0ba7","name":"Select source with ID","server":"918a63e0.1bc5a","version":3,"debugenabled":false,"service_domain":"spotcast","service":"start","entityId":"{{resume_speaker}}","data":"{\"account\":\"{{right_spotcast_account}}\",\"force_playback\":true}","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":2895,"y":280,"wires":[["ac4182012b76547c"]],"l":false},{"id":"d1c952b1829de173","type":"switch","z":"3e3d3934.fbc6d6","g":"e4ea572d031d0ba7","name":"Use speaker name?","property":"use_spotify_speaker_name","propertyType":"msg","rules":[{"t":"true"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":2855,"y":260,"wires":[["d3f6b9920ed775bf"],["e2e2dbece34f204a"]],"l":false},{"id":"d3f6b9920ed775bf","type":"api-call-service","z":"3e3d3934.fbc6d6","g":"e4ea572d031d0ba7","name":"Select source with name","server":"918a63e0.1bc5a","version":3,"debugenabled":false,"service_domain":"spotcast","service":"start","entityId":"","data":"{\"account\":right_spotcast_account,\"device_name\":right_spotify_account_source,\"force_playback\":true}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":2895,"y":240,"wires":[["ac4182012b76547c"]],"l":false},{"id":"ac4182012b76547c","type":"function","z":"3e3d3934.fbc6d6","g":"e4ea572d031d0ba7","name":"Connector","func":"return msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":2935,"y":260,"wires":[["cfcc6f3f7e982f8c"]],"icon":"node-red/inject.svg","l":false},{"id":"b1ed0e4502e868ec","type":"api-current-state","z":"3e3d3934.fbc6d6","g":"435032474aed39f5","name":"Ytube current state","server":"918a63e0.1bc5a","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"{{ytube_temporary_account}}","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"ytube_temporary_data","propertyType":"msg","value":"","valueType":"entity"}],"for":0,"forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":1775,"y":400,"wires":[["d62a6e8382a0b0d9"]],"l":false},{"id":"d62a6e8382a0b0d9","type":"function","z":"3e3d3934.fbc6d6","g":"435032474aed39f5","name":"Set data","func":"msg.ytube_accounts_data[msg.counter]=msg.ytube_temporary_data;\nmsg.counter++;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1815,"y":400,"wires":[["a061f5aa036aac7a"]],"l":false},{"id":"a061f5aa036aac7a","type":"switch","z":"3e3d3934.fbc6d6","g":"435032474aed39f5","name":"Is it all?","property":"counter","propertyType":"msg","rules":[{"t":"gte","v":"ytube_accounts_count","vt":"msg"},{"t":"lt","v":"ytube_accounts_count","vt":"msg"}],"checkall":"false","repair":false,"outputs":2,"x":1855,"y":400,"wires":[["1589c198804e476a"],["4ce1843a0dc41d2c"]],"l":false},{"id":"4ce1843a0dc41d2c","type":"function","z":"3e3d3934.fbc6d6","g":"435032474aed39f5","name":"Set account","func":"msg.ytube_temporary_account=msg.ytube_accounts[msg.counter];\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1735,"y":400,"wires":[["b1ed0e4502e868ec"]],"l":false},{"id":"1589c198804e476a","type":"change","z":"3e3d3934.fbc6d6","g":"435032474aed39f5","name":"Delete","rules":[{"t":"delete","p":"ytube_temporary_account","pt":"msg"},{"t":"delete","p":"ytube_temporary_data","pt":"msg"},{"t":"delete","p":"counter","pt":"msg"},{"t":"set","p":"is_right_account_found","pt":"msg","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":1895,"y":380,"wires":[["e873bc062009dd69"]],"l":false},{"id":"fb5d263edc8e1fa5","type":"change","z":"3e3d3934.fbc6d6","g":"435032474aed39f5","name":"Set counter","rules":[{"t":"set","p":"counter","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":1695,"y":380,"wires":[["4ce1843a0dc41d2c"]],"l":false},{"id":"e873bc062009dd69","type":"function","z":"3e3d3934.fbc6d6","g":"5f09360362d5e81b","name":"Find right ytube account","func":"let speaker_id=msg.speaker;\n\nif(msg.is_it_speaker_in_group===true)\n{\n    speaker_id=msg.speakers_groups_data[msg.which_speaker_group].entity_id;\n}\n\nfor(i=0;i<msg.ytube_accounts_count;i++)\n{\n    if(msg.media_type==\"ytube\" && speaker_id==msg.ytube_accounts_data[i].attributes.remote_player_id && msg.ytube_accounts_data[i].state===\"playing\")\n    {\n        msg.is_right_account_found=true;\n        msg.right_ytube_account=msg.ytube_accounts[i];\n        break;\n    }\n    else if(msg.media_type==\"YouTube\" && speaker_id==msg.ytube_accounts_data[i].attributes.remote_player_id)\n    {\n        msg.is_right_account_found=true;\n        msg.right_ytube_account=msg.ytube_accounts[i];\n        break;\n    }\n}\nif(msg.media_type==\"YouTube\" && !msg.is_right_account_found)\n{\n    for(i=0;i<msg.ytube_accounts_count;i++)\n    {\n        if(msg.media_type==\"YouTube\" && msg.ytube_accounts_data[i].state!==\"playing\")\n        {\n            msg.is_right_account_found=true;\n            msg.right_ytube_account=msg.ytube_accounts[i];\n            break;\n        }\n    }\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1995,"y":380,"wires":[["e6e24ed61aa7f756"]],"l":false},{"id":"e6e24ed61aa7f756","type":"switch","z":"3e3d3934.fbc6d6","g":"5f09360362d5e81b","name":"Is right account found","property":"is_right_account_found","propertyType":"msg","rules":[{"t":"true"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":2035,"y":380,"wires":[["21bebf04e67eea85"],["b7fafb402587e5ed"]],"l":false},{"id":"b7fafb402587e5ed","type":"change","z":"3e3d3934.fbc6d6","g":"5f09360362d5e81b","name":"Set media type to NONE","rules":[{"t":"set","p":"media_type","pt":"msg","to":"NONE","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":2075,"y":400,"wires":[["064d732d19478a76"]],"l":false},{"id":"21bebf04e67eea85","type":"switch","z":"3e3d3934.fbc6d6","g":"5f09360362d5e81b","name":"Is it YT?","property":"media_type","propertyType":"msg","rules":[{"t":"eq","v":"ytube","vt":"str"},{"t":"eq","v":"YouTube","vt":"str"}],"checkall":"false","repair":false,"outputs":2,"x":2115,"y":380,"wires":[["23a123904807c5dc"],["064d732d19478a76"]],"l":false},{"id":"23a123904807c5dc","type":"api-call-service","z":"3e3d3934.fbc6d6","g":"5f09360362d5e81b","name":"Interrupt start","server":"918a63e0.1bc5a","version":3,"debugenabled":false,"service_domain":"ytube_music_player","service":"call_method","entityId":"{{right_ytube_account}}","data":"{\"command\":\"interrupt_start\"}","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":2175,"y":380,"wires":[["064d732d19478a76"]],"l":false},{"id":"064d732d19478a76","type":"function","z":"3e3d3934.fbc6d6","g":"5f09360362d5e81b","name":"Connector","func":"return msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":2215,"y":400,"wires":[["50e99bb2719a3f28"]],"icon":"node-red/inject.svg","l":false},{"id":"df4dbbbcd9bab984","type":"api-call-service","z":"3e3d3934.fbc6d6","g":"8db273c85d1f4b04","name":"Interrupt resume","server":"918a63e0.1bc5a","version":3,"debugenabled":false,"service_domain":"ytube_music_player","service":"call_method","entityId":"{{right_ytube_account}}","data":"{\"command\":\"interrupt_resume\"}","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":2855,"y":380,"wires":[["cdd2dcb74f70afd5"]],"l":false},{"id":"2ea3596d48999a54","type":"api-call-service","z":"3e3d3934.fbc6d6","g":"8db273c85d1f4b04","name":"Set output","server":"918a63e0.1bc5a","version":3,"debugenabled":false,"service_domain":"media_player","service":"select_source","entityId":"media_player.ytube_music_player","data":"{\"source\": resume_speaker_friendly_name}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":2855,"y":420,"wires":[["90f3d929d2f350a9"]],"l":false},{"id":"c881ccccfc5106c8","type":"api-call-service","z":"3e3d3934.fbc6d6","g":"8db273c85d1f4b04","name":"Play media","server":"918a63e0.1bc5a","version":3,"debugenabled":false,"service_domain":"media_player","service":"play_media","entityId":"media_player.ytube_music_player","data":"{\"media_content_id\":\"{{speaker_data.attributes.media_content_id}}\",\"media_content_type\":\"track\"}","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":2935,"y":420,"wires":[["adf6e8ed5be0fba7"]],"l":false},{"id":"96e41efe7416310d","type":"api-call-service","z":"3e3d3934.fbc6d6","g":"8db273c85d1f4b04","name":"URL set position","server":"918a63e0.1bc5a","version":3,"debugenabled":false,"service_domain":"media_player","service":"media_seek","entityId":"{{resume_speaker}}","data":"{    \"seek_position\": {{media_position}}}","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":3095,"y":420,"wires":[["cdd2dcb74f70afd5"]],"l":false},{"id":"8c17ed997d95b47c","type":"ha-wait-until","z":"3e3d3934.fbc6d6","g":"8db273c85d1f4b04","name":"Wait for start","server":"918a63e0.1bc5a","version":0,"outputs":2,"entityId":"{{resume_speaker}}","entityIdFilterType":"exact","property":"state","comparator":"is","value":"playing","valueType":"str","timeout":"25","timeoutType":"num","timeoutUnits":"seconds","entityLocation":"","entityLocationType":"none","checkCurrentState":true,"blockInputOverrides":true,"x":3055,"y":420,"wires":[["96e41efe7416310d"],["96e41efe7416310d"]],"l":false},{"id":"946db825271e70fe","type":"delay","z":"3e3d3934.fbc6d6","g":"8db273c85d1f4b04","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"outputs":1,"x":3015,"y":420,"wires":[["8c17ed997d95b47c"]],"l":false},{"id":"90f3d929d2f350a9","type":"delay","z":"3e3d3934.fbc6d6","g":"8db273c85d1f4b04","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"outputs":1,"x":2895,"y":420,"wires":[["c881ccccfc5106c8"]],"l":false},{"id":"adf6e8ed5be0fba7","type":"function","z":"3e3d3934.fbc6d6","g":"8db273c85d1f4b04","name":"Float to int","func":"msg.media_position=Math.floor(msg.speaker_data.attributes.media_position);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":2975,"y":420,"wires":[["946db825271e70fe"]],"l":false},{"id":"cdd2dcb74f70afd5","type":"function","z":"3e3d3934.fbc6d6","g":"8db273c85d1f4b04","name":"Connector","func":"return msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":3135,"y":400,"wires":[["f673bb49a0efe0d8"]],"icon":"node-red/inject.svg","l":false},{"id":"3b512a399c7eacb5","type":"api-call-service","z":"3e3d3934.fbc6d6","g":"b9c102631689476d","name":"Pause speaker","server":"918a63e0.1bc5a","version":3,"debugenabled":false,"service_domain":"media_player","service":"media_pause","entityId":"{{speaker}}","data":"","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":2395,"y":540,"wires":[["2d5633eadb576528"]],"l":false},{"id":"b6176ac0e7c4a21c","type":"delay","z":"3e3d3934.fbc6d6","g":"b9c102631689476d","name":"delay","pauseType":"delayv","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":2595,"y":560,"wires":[["356ad3b53d40d040"]],"l":false},{"id":"9b8c5c2b1e178dc9","type":"api-call-service","z":"3e3d3934.fbc6d6","g":"b9c102631689476d","name":"Set volume","server":"918a63e0.1bc5a","version":3,"debugenabled":false,"service_domain":"media_player","service":"volume_set","entityId":"{{speaker}}","data":"{\"volume_level\":\"{{volume}}\"}","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":2475,"y":540,"wires":[["77c5dbb579d16c3e"]],"l":false},{"id":"356ad3b53d40d040","type":"api-call-service","z":"3e3d3934.fbc6d6","g":"b9c102631689476d","name":"Set volume","server":"918a63e0.1bc5a","version":3,"debugenabled":false,"service_domain":"media_player","service":"volume_set","entityId":"{{speaker}}","data":"{\"volume_level\":\"{{speaker_data.attributes.volume_level}}\"}","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":2635,"y":560,"wires":[["999e89fc46396b94"]],"l":false},{"id":"2d5633eadb576528","type":"switch","z":"3e3d3934.fbc6d6","g":"b9c102631689476d","name":"","property":"volume","propertyType":"msg","rules":[{"t":"btwn","v":"0","vt":"num","v2":"1","v2t":"num"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":2435,"y":560,"wires":[["9b8c5c2b1e178dc9"],["77c5dbb579d16c3e"]],"l":false},{"id":"77c5dbb579d16c3e","type":"function","z":"3e3d3934.fbc6d6","g":"b9c102631689476d","name":"Setup alexa notify service and calculate time","func":"msg.alexa_notify_service=\"alexa_media_\"+msg.speaker.substring(13);\nmsg.delay=((msg.message.length/12)+1)*1000;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":2515,"y":560,"wires":[["a74b0f14555de090"]],"l":false},{"id":"a74b0f14555de090","type":"api-call-service","z":"3e3d3934.fbc6d6","g":"b9c102631689476d","name":"Alexa TTS","server":"918a63e0.1bc5a","version":3,"debugenabled":false,"service_domain":"notify","service":"{{alexa_notify_service}}","entityId":"","data":"{\"message\":\"{{message}}\",\"data\":{\"type\":\"tts\"}}","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":2555,"y":560,"wires":[["b6176ac0e7c4a21c"]],"l":false},{"id":"2505628870b85dc6","type":"api-call-service","z":"3e3d3934.fbc6d6","g":"b9c102631689476d","name":"Play speaker","server":"918a63e0.1bc5a","version":3,"debugenabled":false,"service_domain":"media_player","service":"media_play","entityId":"{{speaker}}","data":"","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":2715,"y":560,"wires":[["e6dd074f2ea3bc0d"]],"l":false},{"id":"99d22c066760b088","type":"switch","z":"3e3d3934.fbc6d6","g":"b9c102631689476d","name":"Pause?","property":"alexa_pause_on_tts","propertyType":"msg","rules":[{"t":"true"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":2355,"y":560,"wires":[["3b512a399c7eacb5"],["2d5633eadb576528"]],"l":false},{"id":"999e89fc46396b94","type":"delay","z":"3e3d3934.fbc6d6","g":"b9c102631689476d","name":"delay","pauseType":"delayv","timeout":"100","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":2675,"y":560,"wires":[["2505628870b85dc6"]],"l":false},{"id":"ab7ec373068e28fb","type":"function","z":"3e3d3934.fbc6d6","g":"4b9d74d12cbd3e65","name":"Debug","func":"node.warn(\"Smart TTS ERROR: \");\nnode.warn(msg.error);\nif(msg.debug)\n{\n    node.warn(\"Smart TTS debug output: \");\n    node.warn(msg);\n}","outputs":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":295,"y":460,"wires":[],"icon":"font-awesome/fa-bug","l":false},{"id":"5a1f368902eb0a12","type":"api-current-state","z":"3e3d3934.fbc6d6","g":"df3d995d84e9d2a1","name":"Group current state","server":"918a63e0.1bc5a","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"{{speakers_temporary_group}}","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"speakers_group_temporary_data","propertyType":"msg","value":"","valueType":"entity"}],"for":0,"forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":555,"y":320,"wires":[["439642d88e48109f"]],"l":false},{"id":"439642d88e48109f","type":"function","z":"3e3d3934.fbc6d6","g":"df3d995d84e9d2a1","name":"Set data","func":"msg.speakers_groups_data[msg.counter]=msg.speakers_group_temporary_data;\nmsg.counter++;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":595,"y":320,"wires":[["b1a1f2a6ba107ea2"]],"l":false},{"id":"b1a1f2a6ba107ea2","type":"switch","z":"3e3d3934.fbc6d6","g":"df3d995d84e9d2a1","name":"Is it all?","property":"counter","propertyType":"msg","rules":[{"t":"gte","v":"speakers_groups_count","vt":"msg"},{"t":"lt","v":"speakers_groups_count","vt":"msg"}],"checkall":"false","repair":false,"outputs":2,"x":635,"y":320,"wires":[["c7a912d0f8fc62de"],["bb833fe4ab6e20b8"]],"l":false},{"id":"bb833fe4ab6e20b8","type":"function","z":"3e3d3934.fbc6d6","g":"df3d995d84e9d2a1","name":"Set group","func":"msg.speakers_temporary_group=msg.speakers_groups[msg.counter];\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":515,"y":320,"wires":[["5a1f368902eb0a12"]],"l":false},{"id":"c7a912d0f8fc62de","type":"change","z":"3e3d3934.fbc6d6","g":"df3d995d84e9d2a1","name":"Delete","rules":[{"t":"delete","p":"speakers_temporary_group","pt":"msg"},{"t":"delete","p":"speakers_group_temporary_data","pt":"msg"},{"t":"delete","p":"counter","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":675,"y":300,"wires":[["743515015cc33efd"]],"l":false},{"id":"b1c761bed53d40a9","type":"change","z":"3e3d3934.fbc6d6","g":"df3d995d84e9d2a1","name":"Set counter","rules":[{"t":"set","p":"counter","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":475,"y":300,"wires":[["bb833fe4ab6e20b8"]],"l":false},{"id":"743515015cc33efd","type":"function","z":"3e3d3934.fbc6d6","g":"3d1bdae6980660a7","name":"Group type rocognition","func":"for(i=0;i<msg.speakers_groups_count;i++)\n{\n    if(msg.speaker===msg.speakers_groups[i])\n    {\n        msg.is_it_group=true;\n        msg.is_it_speaker_in_group=false;\n        msg.which_speaker_group=i;\n        break;\n    }\n}\nif(msg.is_it_group===false)\n{\n    for(i=0;i<msg.speakers_groups_count;i++)\n    {\n        if(msg.speaker_data.state===msg.speakers_groups_data[i].state && \n        msg.speaker_data.attributes.media_content_id===msg.speakers_groups_data[i].attributes.media_content_id && \n        msg.speakers_groups_data[i].state===\"playing\")\n        {\n            for(j=0;j<msg.speakers_inside_groups[i].length;j++)\n            {\n                if(msg.speaker===msg.speakers_inside_groups[i][j])\n                {\n                    msg.is_it_group=false;\n                    msg.is_it_speaker_in_group=true;\n                    msg.which_speaker_group=i;\n                    break;\n                }\n            }\n        }\n        if(msg.is_it_speaker_in_group===true)break;\n    }\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":775,"y":320,"wires":[["514a87c252fde2f9"]],"l":false},{"id":"514a87c252fde2f9","type":"switch","z":"3e3d3934.fbc6d6","g":"3d1bdae6980660a7","name":"Is it group?","property":"is_it_group","propertyType":"msg","rules":[{"t":"true"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":815,"y":320,"wires":[["76e6aa845545b821"],["6657ec7501ad8137"]],"l":false},{"id":"76e6aa845545b821","type":"switch","z":"3e3d3934.fbc6d6","g":"3d1bdae6980660a7","name":"Is group not playing?","property":"speaker_data.state","propertyType":"msg","rules":[{"t":"neq","v":"playing","vt":"str"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":855,"y":300,"wires":[["fcae45f78aa92775"],["6657ec7501ad8137"]],"l":false},{"id":"384861426abe5b8c","type":"api-current-state","z":"3e3d3934.fbc6d6","g":"dc7b3b8c84ba81b3","name":"Speaker current state","server":"918a63e0.1bc5a","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"{{speaker_temporary}}","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"speaker_temporary_state","propertyType":"msg","value":"","valueType":"entityState"}],"for":0,"forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":1035,"y":320,"wires":[["31d6ba68118e9ac6"]],"l":false},{"id":"31d6ba68118e9ac6","type":"function","z":"3e3d3934.fbc6d6","g":"dc7b3b8c84ba81b3","name":"Set data","func":"msg.speakers_inside_group_state[msg.counter]=msg.speaker_temporary_state;\nmsg.counter++;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1075,"y":320,"wires":[["d294aed085fda93c"]],"l":false},{"id":"d294aed085fda93c","type":"switch","z":"3e3d3934.fbc6d6","g":"dc7b3b8c84ba81b3","name":"Is it all?","property":"counter","propertyType":"msg","rules":[{"t":"gte","v":"speakers_inside_group_count","vt":"msg"},{"t":"lt","v":"speakers_inside_group_count","vt":"msg"}],"checkall":"false","repair":false,"outputs":2,"x":1115,"y":320,"wires":[["addaed19b41880be"],["7dd78dad790672e8"]],"l":false},{"id":"7dd78dad790672e8","type":"function","z":"3e3d3934.fbc6d6","g":"dc7b3b8c84ba81b3","name":"Set speaker","func":"msg.speaker_temporary=msg.speakers_inside_groups[msg.which_speaker_group][msg.counter];\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":995,"y":320,"wires":[["384861426abe5b8c"]],"l":false},{"id":"addaed19b41880be","type":"change","z":"3e3d3934.fbc6d6","g":"dc7b3b8c84ba81b3","name":"Delete","rules":[{"t":"delete","p":"msg.speaker_temporary","pt":"msg"},{"t":"delete","p":"msg.speaker_temporary_state","pt":"msg"},{"t":"delete","p":"counter","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1155,"y":300,"wires":[["6f211fb74b2b7f49"]],"l":false},{"id":"fcae45f78aa92775","type":"function","z":"3e3d3934.fbc6d6","g":"dc7b3b8c84ba81b3","name":"Set variables","func":"msg.counter=0;\nmsg.speakers_inside_group_count=msg.speakers_inside_groups[msg.which_speaker_group].length;\nmsg.speakers_inside_group_state=new Array(msg.speakers_inside_group_count);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":955,"y":300,"wires":[["7dd78dad790672e8"]],"icon":"node-red/swap.svg","l":false},{"id":"6f211fb74b2b7f49","type":"api-call-service","z":"3e3d3934.fbc6d6","g":"fa06bc39f6a3f587","name":"Turn on speaker","server":"918a63e0.1bc5a","version":3,"debugenabled":false,"service_domain":"media_player","service":"turn_on","entityId":"{{speaker}}","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1255,"y":300,"wires":[["c43eca78f57978d1"]],"l":false},{"id":"c43eca78f57978d1","type":"ha-wait-until","z":"3e3d3934.fbc6d6","g":"fa06bc39f6a3f587","name":"Wait for turning on","server":"918a63e0.1bc5a","version":0,"outputs":2,"entityId":"{{speaker}}","entityIdFilterType":"exact","property":"state","comparator":"is_not","value":"off","valueType":"str","timeout":"5","timeoutType":"num","timeoutUnits":"seconds","entityLocation":"","entityLocationType":"none","checkCurrentState":true,"blockInputOverrides":true,"x":1295,"y":300,"wires":[["4a4e522685dc3866"],["4a4e522685dc3866"]],"l":false},{"id":"4a4e522685dc3866","type":"api-current-state","z":"3e3d3934.fbc6d6","g":"fa06bc39f6a3f587","name":"Speaker current state","server":"918a63e0.1bc5a","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"{{speaker}}","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"speaker_data","propertyType":"msg","value":"","valueType":"entity"}],"for":0,"forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":1335,"y":300,"wires":[["8d38296d8f450521"]],"l":false},{"id":"1e1403ab211b4b11","type":"catch","z":"3e3d3934.fbc6d6","g":"4b9d74d12cbd3e65","name":"","scope":null,"uncaught":false,"x":200,"y":460,"wires":[["ab7ec373068e28fb"]]},{"id":"80f20973bdbdf8bc","type":"switch","z":"3e3d3934.fbc6d6","g":"847406122c07558c","name":"Use groups?","property":"speakers_groups_count","propertyType":"msg","rules":[{"t":"gte","v":"1","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":375,"y":320,"wires":[["b1c761bed53d40a9"],["2dda79e9d18654dc"]],"l":false},{"id":"2dda79e9d18654dc","type":"function","z":"3e3d3934.fbc6d6","name":"Connector","func":"return msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":515,"y":440,"wires":[["628d5eb3df91c82b"]],"icon":"node-red/inject.svg","l":false},{"id":"628d5eb3df91c82b","type":"function","z":"3e3d3934.fbc6d6","g":"066ed1257cae1df0","name":"Connector","func":"return msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1155,"y":440,"wires":[["6f211fb74b2b7f49"]],"icon":"node-red/inject.svg","l":false},{"id":"d5e8c87966b22e98","type":"function","z":"3e3d3934.fbc6d6","g":"847406122c07558c","name":"CONFIG","func":"// +-----------+\n// | Smart TTS |\n// +-----------+\n\n//By IT freak Jake\n//Version: 1.3.1\n//Node-RED project page link:\n//https://flows.nodered.org/flow/d0f137bc6323fd8200b8221cea22d713\n\n// +--------+\n// | Config |\n// +--------+\n\n//Media players ID's from Spotify integration\n//If you don't use spotify make it empty like example below\n//msg.spotify_accounts=[];\n//(Remember about removing example media players)\nmsg.spotify_accounts=\n[\n\"media_player.spotify_account_1\",\n\"media_player.spotify_account_2\",\n\"media_player.spotify_account_3\",\n\"media_player.spotify_account_4\"\n];\n\n//Accounts from Spotcast integration\n//(In the same order as spotify accounts)\n//If you don't use spotify make it empty like example below\n//msg.spotcast_accounts=[];\n//(Remember about removing example media players)\nmsg.spotcast_accounts=\n[\n\"default\",\n\"account_2\",\n\"account_3\",\n\"account_4\"\n];\n\n//Media players ID's from ytube_music_player integration \n//If you don't use YouTube music make it empty like example below\n//msg.ytube_accounts=[];\n//(Remember about removing example media players)\nmsg.ytube_accounts=\n[\n\"media_player.ytube_account_1\",\n\"media_player.ytube_account_2\",\n\"media_player.ytube_account_3\",\n\"media_player.ytube_account_4\"\n];\n\n//Speakers groups ID's\n//If you don't use groups make it empty like example below\n//msg.speakers_groups=[];\n//(Remember about removing example media players)\nmsg.speakers_groups=\n[\n\"media_player.group1\",\n\"media_player.group2\",\n\"media_player.group3\"\n];\n\n//Speakers inside groups ID's\n//(In the same order as speakers groups ID's)\n//If you don't use groups make it empty like example below\n//msg.speakers_inside_groups=[];\n//(Remember about removing example media players)\nmsg.speakers_inside_groups=\n[\n  [//Speakers in media_player.group1\n    \"media_player.speaker1_in_group1\",\n    \"media_player.speaker2_in_group1\",\n    \"media_player.speaker3_in_group1\"\n  ],  \n  [//Speakers in media_player.group2\n    \"media_player.speaker1_in_group2\",\n    \"media_player.speaker2_in_group2\",\n    \"media_player.speaker3_in_group2\"\n  ],  \n  [//Speakers in media_player.group3\n    \"media_player.speaker1_in_group3\",\n    \"media_player.speaker2_in_group3\",\n    \"media_player.speaker3_in_group3\",\n    \"media_player.speaker4_in_group3\"\n  ]\n];\n\n//Default TTS service like google_translate_say or reversotts_say\n//For Alexa it's alexa_default\nconst default_tts_service=\"google_translate_say\";\n\n//Pause media when calling TTS on Alexa speaker\nmsg.alexa_pause_on_tts=true;\n\n// +----------+\n// | Advanced |\n// +----------+\n\n//If the speaker and Spotify has other media ID but \n//the Spotify account is the only one playing \n//and speaker is playing from Spotify\n//smart TTS is using this Spotify account to resume.\n//Changing this variable on true will disable this function \nmsg.spotify_require_identical_media_content_id=false;\n\n//Compare speaker name with Spotify source name instead\n//of comparing media content ID when looking for Spotify\n//account which is playing on the speaker\nmsg.compare_spotify_speaker_name=true;\n\n//Use Spotify speaker name instead of HA media player ID\n//when using Spotcast service\n//(Speaker friendly name and Spotify source\n//speaker name must be this same)\nmsg.use_spotify_speaker_name=true;\n\n//Delete variables used in smart TTS on end\nmsg.delete_variables=true;\n\n//Enable debug output\nmsg.debug=false;\n\n\n// +----------------+\n// | DO NOT CHANGE! |\n// +----------------+\n\nlet is_config_ok=true,\nspotify_exist=true,\nspotcast_exist=true,\nspeakers_groups_exist=true,\nspeakers_inside_groups_exist=true;\nmsg.is_it_group=false;\nmsg.is_it_speaker_in_group=false;\n\nif(typeof(msg.speaker)==='undefined'){\n    is_config_ok=false;\n    node.warn('Smart TTS: Speaker ID is missing!');}\nif(typeof(msg.message)==='undefined'){\n    is_config_ok=false;\n    node.warn('Smart TTS: TTS message is missing!');}\nif(typeof(default_tts_service)==='undefined'){\n    is_config_ok=false;\n    node.warn('Smart TTS: \"default_tts_service\" is missing!');}\nif(typeof(msg.spotify_require_identical_media_content_id)==='undefined'){\n    is_config_ok=false;\n    node.warn('Smart TTS: \"msg.spotify_require_identical_media_id\" is missing!');}\nif(typeof(msg.compare_spotify_speaker_name)==='undefined'){\n    is_config_ok=false;\n    node.warn('Smart TTS: \"msg.compare_spotify_speaker_name\" is missing!');}\nif(typeof(msg.use_spotify_speaker_name)==='undefined'){\n    is_config_ok=false;\n    node.warn('Smart TTS: \"msg.use_spotify_speaker_name\" is missing!');}\nif(typeof(msg.delete_variables)==='undefined'){\n    is_config_ok=false;\n    node.warn('Smart TTS: \"msg.delete_variables\" is missing!');}\nif(typeof(msg.debug)==='undefined'){\n    is_config_ok=false;\n    node.warn('Smart TTS: \"msg.debug\" is missing!');}\nif(typeof(msg.spotify_accounts)==='undefined'){\n    is_config_ok=false;\n    spotify_exist=false;\n    node.warn('Smart TTS: \"msg.spotify_accounts[]\" is missing!');}\nif(typeof(msg.spotcast_accounts)==='undefined'){\n    is_config_ok=false;\n    spotcast_exist=false;\n    node.warn('Smart TTS: \"msg.spotcast_accounts[]\" is missing!');}\nif(typeof(msg.ytube_accounts)==='undefined'){\n    is_config_ok=false;\n    node.warn('Smart TTS: \"msg.ytube_accounts[]\" is missing!');}\nif(typeof(msg.speakers_groups)==='undefined'){\n    is_config_ok=false;\n    speakers_groups_exist=false;\n    node.warn('Smart TTS: \"msg.speakers_groups[]\" is missing!');}\nif(typeof(msg.speakers_inside_groups)==='undefined'){\n    is_config_ok=false;\n    speakers_inside_groups_exist=false;\n    node.warn('Smart TTS: \"msg.speakers_inside_groups[]\" is missing!');}\nif(typeof(msg.alexa_pause_on_tts)==='undefined'){\n    is_config_ok=false;\n    node.warn('Smart TTS: \"msg.alexa_pause_on_tts\" is missing!');}\n    \nif(spotify_exist && spotcast_exist){\n    if(msg.spotify_accounts.length!==msg.spotcast_accounts.length){\n    is_config_ok=false;\n    node.warn('Smart TTS: \"msg.spotify_accounts[]\" and \"msg.spotcast_accounts[]\" must have the same number of variables!');}\n}\nif(speakers_groups_exist && speakers_inside_groups_exist){\n    if(msg.speakers_groups.length!==msg.speakers_inside_groups.length){\n    is_config_ok=false;\n    node.warn('Smart TTS: \"msg.speakers_groups[]\" and \"msg.speakers_inside_groups[]\" must have the same number of variables!');}\n}\n\n\nif(is_config_ok)\n{\n    msg.spotify_accounts_count=msg.spotify_accounts.length;\n    msg.spotify_accounts_data=new Array(msg.spotify_accounts_count);\n    msg.ytube_accounts_count=msg.ytube_accounts.length;\n    msg.ytube_accounts_data=new Array(msg.ytube_accounts_count);\n    msg.speakers_groups_count=msg.speakers_groups.length;\n    msg.speakers_groups_data=new Array(msg.speakers_groups_count);\n    if(typeof(msg.tts_service)==='undefined')msg.tts_service=default_tts_service;\n    return msg;\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":160,"y":340,"wires":[["dd5da2561d1da094"]],"icon":"node-red/cog.svg"},{"id":"918a63e0.1bc5a","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30}]

Flow Info

Created 1 year, 4 months ago
Updated 8 months, 2 weeks ago
Rating: 5 2

Actions

Rate:

Node Types

Core
  • catch (x1)
  • change (x13)
  • comment (x1)
  • delay (x8)
  • function (x36)
  • inject (x4)
  • switch (x23)
Other
  • api-call-service (x20)
  • api-current-state (x7)
  • group (x18)
  • ha-wait-until (x6)
  • server (x1)
  • subflow (x1)

Tags

  • HomeAssistant
  • TTS
  • GoogleHome
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option