TestTest Test

TestTestTestTestTestTestTestTestTestTestTest

[{"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":80,"y":220,"wires":[{"id":"36f24f05.a1113"}]}],"out":[{"x":1200,"y":560,"wires":[{"id":"cf28bd85.b12fc","port":0},{"id":"5560412e.fcb47","port":1}]}],"env":[],"meta":{"module":"Smart TTS","type":"TTS","version":"1.2.0","author":"IT freak Jake","keywords":"HomeAssistant, TTS, GoogleHome"},"color":"#A6BBCF","icon":"node-red-contrib-cast/google-home-mini2.svg"},{"id":"8e58633b.f0026","type":"group","z":"3e3d3934.fbc6d6","name":"Smart TTS","style":{"stroke":"#7f7f7f","fill":"#7f7f7f","fill-opacity":"0.5","label":true,"color":"#ffffff"},"nodes":["3ac677bb.275e68","c3026439.c756b8","b2e28c40.cc33f","cdca0a80.3e4f08","5888d60c.4b3528","dbf55503.964ed8","b6d37498.2a6e88","d3b3bfd.2513e4","37dd2238.d0ba4e","291f823b.84186e","9dfe1506.db76b8","637a9b01.1afb04","e5691011.03755","2671e1f.1d2131e"],"x":34,"y":93,"w":1228,"h":708},{"id":"3ac677bb.275e68","type":"group","z":"3e3d3934.fbc6d6","g":"8e58633b.f0026","name":"Input","style":{"label":true},"nodes":["36f24f05.a1113","52ba4ebd.ca25d","8d7d69d2.dd3748"],"x":94,"y":179,"w":262,"h":82},{"id":"c3026439.c756b8","type":"group","z":"3e3d3934.fbc6d6","g":"8e58633b.f0026","name":"Finding right spotify account","style":{"label":true},"nodes":["8f92e984.4bf3d8","f8f82d68.d8154","f78be701.caa4d8","475e5491.13d49c","d5831aca.d85f28"],"x":974,"y":119,"w":202,"h":122},{"id":"b2e28c40.cc33f","type":"group","z":"3e3d3934.fbc6d6","g":"8e58633b.f0026","name":"TTS","style":{"label":true},"nodes":["cf9f8b52.2cbcf8","1a050acf.d66195","c6b58226.981d6","8028ecb9.afeb8","e8dc8f5c.9aa8c","b08767b1.35d8b8","bd4ba1ca.637ea","af704d45.c9ab9","5cb1ea9d.b76c54","d17daa45.a76b28"],"x":114,"y":456.5,"w":442,"h":127},{"id":"cdca0a80.3e4f08","type":"group","z":"3e3d3934.fbc6d6","g":"8e58633b.f0026","name":"Initial media type recognition","style":{"label":true},"nodes":["280e7c6a.4b9704","2b67559e.1b3bda","9cd2d33f.db241","a2453a2c.3f89a8","58dc90cd.3df0e","7a4a6b02.2d2f04","c798dbca.54c9c8","9ac1fc4e.8b62b"],"x":374,"y":139,"w":242,"h":202},{"id":"5888d60c.4b3528","type":"group","z":"3e3d3934.fbc6d6","g":"8e58633b.f0026","name":"Output","style":{"label":true},"nodes":["5560412e.fcb47","cf28bd85.b12fc","183fef05.d67d81","4273b52b.86a48c"],"x":1034,"y":479,"w":162,"h":142},{"id":"dbf55503.964ed8","type":"group","z":"3e3d3934.fbc6d6","g":"8e58633b.f0026","name":"URL resume","style":{"label":true},"nodes":["3b565f46.6690d","ee62661d.93d598","b4b60ec3.50046","d44ee31d.60fe2","ac081f9a.357bf","145a44d9.24ae5b","d79352df.ab181","2ab0f9d3.c86b06"],"x":594,"y":639,"w":362,"h":102},{"id":"b6d37498.2a6e88","type":"group","z":"3e3d3934.fbc6d6","g":"8e58633b.f0026","name":"Getting spotify accounts data","style":{"label":true},"nodes":["d3bb549f.dd7428","1da76cf2.815583","8069829d.6b527","67a459f5.6e4e58","81d7a2cc.b23d1","72f5c729.99a848"],"x":674,"y":119,"w":282,"h":102},{"id":"d3b3bfd.2513e4","type":"group","z":"3e3d3934.fbc6d6","g":"8e58633b.f0026","name":"Spotify resume","style":{"label":true},"nodes":["34c74096.de4","c1bbcdf0.cd99","284d5dbb.3b0742","39421d5.c1f6ae2"],"x":614,"y":359,"w":162,"h":122},{"id":"9dfe1506.db76b8","type":"group","z":"3e3d3934.fbc6d6","g":"8e58633b.f0026","name":"Getting ytube accounts data","style":{"label":true},"nodes":["97c2d021.92663","3b07a3ee.e0c41c","9d1fc864.18bbb8","bea5a031.bc8b8","5046d0e8.a90bb","b30300bc.0d0b1"],"x":634,"y":239,"w":282,"h":102},{"id":"637a9b01.1afb04","type":"group","z":"3e3d3934.fbc6d6","g":"8e58633b.f0026","name":"Finding right ytube account","style":{"label":true},"nodes":["b1d37ac3.a33f38","97603a8b.fc0428","34cfa225.c5127e","1ca7637e.f4acad","13d63878.6a03f8","fecb31e3.760f7"],"x":934,"y":259,"w":302,"h":102},{"id":"e5691011.03755","type":"group","z":"3e3d3934.fbc6d6","g":"8e58633b.f0026","name":"YouTube music resume","style":{"label":true},"nodes":["5c9a8a8f.14b294","f29d0296.eaecc","d18a94ff.490d18","d420afee.9a2fc","df8533b4.7e8f5","324f7274.a3881e","597cb36a.138bcc","714fa835.876998","7c2774a8.acd06c"],"x":594,"y":499,"w":382,"h":122},{"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":"36f24f05.a1113","type":"function","z":"3e3d3934.fbc6d6","g":"3ac677bb.275e68","name":"CONFIG","func":"// +-----------+\n// | Smart TTS |\n// +-----------+\n\n//By IT freak Jake\n//Version: 1.2.0\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.youtube_account_1\",\n\"media_player.youtube_account_2\",\n\"media_player.youtube_account_3\",\n\"media_player.youtube_account_4\"\n];\n\n//Default TTS service like google_translate_say or reversotts_say\nconst default_tts_service=\"google_translate_say\";\n\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;\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!');}\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}\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    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":180,"y":220,"wires":[["52ba4ebd.ca25d"]],"icon":"node-red/cog.svg"},{"id":"52ba4ebd.ca25d","type":"api-call-service","z":"3e3d3934.fbc6d6","g":"3ac677bb.275e68","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":275,"y":220,"wires":[["8d7d69d2.dd3748"]],"l":false},{"id":"8d7d69d2.dd3748","type":"ha-wait-until","z":"3e3d3934.fbc6d6","g":"3ac677bb.275e68","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":315,"y":220,"wires":[["280e7c6a.4b9704"],["280e7c6a.4b9704"]],"l":false},{"id":"8f92e984.4bf3d8","type":"function","z":"3e3d3934.fbc6d6","g":"c3026439.c756b8","name":"Find right spotify account","func":"let playing_accounts_count=0,\nplaying_spotify_account,\nplaying_spotcast_account;\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(msg.speaker_data.attributes.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(msg.speaker_data.attributes.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":1015,"y":180,"wires":[["f8f82d68.d8154"]],"l":false},{"id":"f8f82d68.d8154","type":"switch","z":"3e3d3934.fbc6d6","g":"c3026439.c756b8","name":"Is right account found","property":"is_right_account_found","propertyType":"msg","rules":[{"t":"true"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":1055,"y":180,"wires":[["475e5491.13d49c"],["f78be701.caa4d8"]],"l":false},{"id":"f78be701.caa4d8","type":"change","z":"3e3d3934.fbc6d6","g":"c3026439.c756b8","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":1095,"y":200,"wires":[["d5831aca.d85f28"]],"l":false},{"id":"475e5491.13d49c","type":"change","z":"3e3d3934.fbc6d6","g":"c3026439.c756b8","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":1095,"y":160,"wires":[["d5831aca.d85f28"]],"l":false},{"id":"d5831aca.d85f28","type":"function","z":"3e3d3934.fbc6d6","g":"c3026439.c756b8","name":"Connector","func":"return msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1135,"y":180,"wires":[["cf9f8b52.2cbcf8"]],"icon":"node-red/inject.svg","l":false},{"id":"cf9f8b52.2cbcf8","type":"api-call-service","z":"3e3d3934.fbc6d6","g":"b2e28c40.cc33f","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":155,"y":520,"wires":[["af704d45.c9ab9"]],"l":false},{"id":"1a050acf.d66195","type":"api-call-service","z":"3e3d3934.fbc6d6","g":"b2e28c40.cc33f","name":"TTS","server":"918a63e0.1bc5a","version":3,"debugenabled":false,"service_domain":"tts","service":"{{tts_service}}","entityId":"{{speaker}}","data":"{\"message\":\"{{message}}\"}","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":275,"y":520,"wires":[["d17daa45.a76b28"]],"l":false},{"id":"c6b58226.981d6","type":"ha-wait-until","z":"3e3d3934.fbc6d6","g":"b2e28c40.cc33f","name":"Wait for start","server":"918a63e0.1bc5a","version":0,"outputs":2,"entityId":"{{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":355,"y":520,"wires":[["8028ecb9.afeb8"],[]],"l":false},{"id":"8028ecb9.afeb8","type":"delay","z":"3e3d3934.fbc6d6","g":"b2e28c40.cc33f","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":395,"y":520,"wires":[["e8dc8f5c.9aa8c"]],"l":false},{"id":"e8dc8f5c.9aa8c","type":"ha-wait-until","z":"3e3d3934.fbc6d6","g":"b2e28c40.cc33f","name":"Wait for end","server":"918a63e0.1bc5a","version":0,"outputs":2,"entityId":"{{speaker}}","entityIdFilterType":"exact","property":"state","comparator":"is","value":"idle","valueType":"str","timeout":"5","timeoutType":"num","timeoutUnits":"minutes","entityLocation":"","entityLocationType":"none","checkCurrentState":true,"blockInputOverrides":true,"x":435,"y":520,"wires":[["bd4ba1ca.637ea"],[]],"l":false},{"id":"b08767b1.35d8b8","type":"api-call-service","z":"3e3d3934.fbc6d6","g":"b2e28c40.cc33f","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":235,"y":500,"wires":[["1a050acf.d66195"]],"l":false},{"id":"bd4ba1ca.637ea","type":"api-call-service","z":"3e3d3934.fbc6d6","g":"b2e28c40.cc33f","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":475,"y":520,"wires":[["5cb1ea9d.b76c54"]],"l":false},{"id":"af704d45.c9ab9","type":"switch","z":"3e3d3934.fbc6d6","g":"b2e28c40.cc33f","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":195,"y":520,"wires":[["b08767b1.35d8b8"],["1a050acf.d66195"]],"l":false},{"id":"5cb1ea9d.b76c54","type":"switch","z":"3e3d3934.fbc6d6","g":"b2e28c40.cc33f","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":515,"y":520,"wires":[["c1bbcdf0.cd99"],["5c9a8a8f.14b294"],["f29d0296.eaecc"],["ee62661d.93d598"],["291f823b.84186e"]],"l":false},{"id":"d17daa45.a76b28","type":"delay","z":"3e3d3934.fbc6d6","g":"b2e28c40.cc33f","name":"","pauseType":"delay","timeout":"700","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":315,"y":520,"wires":[["c6b58226.981d6"]],"l":false},{"id":"280e7c6a.4b9704","type":"api-current-state","z":"3e3d3934.fbc6d6","g":"cdca0a80.3e4f08","name":"Speaker current state","server":"918a63e0.1bc5a","version":2,"outputs":2,"halt_if":"playing","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"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":415,"y":220,"wires":[["2b67559e.1b3bda"],["9cd2d33f.db241"]],"l":false},{"id":"2b67559e.1b3bda","type":"switch","z":"3e3d3934.fbc6d6","g":"cdca0a80.3e4f08","name":"Is it Spotify?","property":"speaker_data.attributes.media_content_id","propertyType":"msg","rules":[{"t":"cont","v":"spotify","vt":"str"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":455,"y":200,"wires":[["c798dbca.54c9c8"],["7a4a6b02.2d2f04"]],"l":false},{"id":"9cd2d33f.db241","type":"change","z":"3e3d3934.fbc6d6","g":"cdca0a80.3e4f08","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":455,"y":300,"wires":[["cf9f8b52.2cbcf8"]],"l":false},{"id":"a2453a2c.3f89a8","type":"change","z":"3e3d3934.fbc6d6","g":"cdca0a80.3e4f08","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":575,"y":300,"wires":[["cf9f8b52.2cbcf8"]],"l":false},{"id":"58dc90cd.3df0e","type":"switch","z":"3e3d3934.fbc6d6","g":"cdca0a80.3e4f08","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":535,"y":260,"wires":[["9ac1fc4e.8b62b"],["9ac1fc4e.8b62b"],["a2453a2c.3f89a8"]],"l":false},{"id":"7a4a6b02.2d2f04","type":"function","z":"3e3d3934.fbc6d6","g":"cdca0a80.3e4f08","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":495,"y":260,"wires":[["58dc90cd.3df0e"]],"l":false},{"id":"c798dbca.54c9c8","type":"switch","z":"3e3d3934.fbc6d6","g":"cdca0a80.3e4f08","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":495,"y":180,"wires":[["72f5c729.99a848"],["9cd2d33f.db241"]],"l":false},{"id":"9ac1fc4e.8b62b","type":"switch","z":"3e3d3934.fbc6d6","g":"cdca0a80.3e4f08","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":575,"y":260,"wires":[["b30300bc.0d0b1"],["9cd2d33f.db241"]],"l":false},{"id":"5560412e.fcb47","type":"switch","z":"3e3d3934.fbc6d6","g":"5888d60c.4b3528","name":"Delete variables?","property":"delete_variables","propertyType":"msg","rules":[{"t":"true"},{"t":"false"}],"checkall":"false","repair":false,"outputs":2,"x":1115,"y":540,"wires":[["cf28bd85.b12fc"],[]],"l":false},{"id":"cf28bd85.b12fc","type":"change","z":"3e3d3934.fbc6d6","g":"5888d60c.4b3528","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"}],"action":"","property":"","from":"","to":"","reg":false,"x":1155,"y":520,"wires":[[]],"l":false},{"id":"183fef05.d67d81","type":"function","z":"3e3d3934.fbc6d6","g":"5888d60c.4b3528","name":"Debug","func":"if(msg.debug)\n{\n    node.warn(\"Smart TTS debug output: \");\n    node.warn(msg);\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1115,"y":580,"wires":[[]],"icon":"font-awesome/fa-bug","l":false},{"id":"4273b52b.86a48c","type":"function","z":"3e3d3934.fbc6d6","g":"5888d60c.4b3528","name":"Connector","func":"return msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1075,"y":560,"wires":[["5560412e.fcb47","183fef05.d67d81"]],"icon":"node-red/inject.svg","l":false},{"id":"3b565f46.6690d","type":"api-call-service","z":"3e3d3934.fbc6d6","g":"dbf55503.964ed8","name":"URL resume","server":"918a63e0.1bc5a","version":3,"debugenabled":false,"service_domain":"media_player","service":"play_media","entityId":"{{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":675,"y":700,"wires":[["b4b60ec3.50046"]],"l":false},{"id":"ee62661d.93d598","type":"delay","z":"3e3d3934.fbc6d6","g":"dbf55503.964ed8","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":635,"y":700,"wires":[["3b565f46.6690d"]],"l":false},{"id":"b4b60ec3.50046","type":"switch","z":"3e3d3934.fbc6d6","g":"dbf55503.964ed8","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":715,"y":700,"wires":[["d44ee31d.60fe2"],["2ab0f9d3.c86b06"]],"l":false},{"id":"d44ee31d.60fe2","type":"function","z":"3e3d3934.fbc6d6","g":"dbf55503.964ed8","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":755,"y":680,"wires":[["ac081f9a.357bf"]],"l":false},{"id":"ac081f9a.357bf","type":"delay","z":"3e3d3934.fbc6d6","g":"dbf55503.964ed8","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":795,"y":680,"wires":[["145a44d9.24ae5b"]],"l":false},{"id":"145a44d9.24ae5b","type":"ha-wait-until","z":"3e3d3934.fbc6d6","g":"dbf55503.964ed8","name":"Wait for start","server":"918a63e0.1bc5a","version":0,"outputs":2,"entityId":"{{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":835,"y":680,"wires":[["d79352df.ab181"],["d79352df.ab181"]],"l":false},{"id":"d79352df.ab181","type":"api-call-service","z":"3e3d3934.fbc6d6","g":"dbf55503.964ed8","name":"URL set position","server":"918a63e0.1bc5a","version":3,"debugenabled":false,"service_domain":"media_player","service":"media_seek","entityId":"{{speaker}}","data":"{    \"seek_position\": {{media_position}}}","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":875,"y":680,"wires":[["2ab0f9d3.c86b06"]],"l":false},{"id":"2ab0f9d3.c86b06","type":"function","z":"3e3d3934.fbc6d6","g":"dbf55503.964ed8","name":"Connector","func":"return msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":915,"y":700,"wires":[["4273b52b.86a48c"]],"icon":"node-red/inject.svg","l":false},{"id":"d3bb549f.dd7428","type":"api-current-state","z":"3e3d3934.fbc6d6","g":"b6d37498.2a6e88","name":"Spotify current state","server":"918a63e0.1bc5a","version":2,"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"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":795,"y":180,"wires":[["1da76cf2.815583"]],"l":false},{"id":"1da76cf2.815583","type":"function","z":"3e3d3934.fbc6d6","g":"b6d37498.2a6e88","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":835,"y":180,"wires":[["8069829d.6b527"]],"l":false},{"id":"8069829d.6b527","type":"switch","z":"3e3d3934.fbc6d6","g":"b6d37498.2a6e88","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":"true","repair":false,"outputs":2,"x":875,"y":180,"wires":[["81d7a2cc.b23d1"],["67a459f5.6e4e58"]],"l":false},{"id":"67a459f5.6e4e58","type":"function","z":"3e3d3934.fbc6d6","g":"b6d37498.2a6e88","name":"Set account","func":"msg.spotify_temporary_account=msg.spotify_accounts[msg.counter];\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":755,"y":180,"wires":[["d3bb549f.dd7428"]],"l":false},{"id":"81d7a2cc.b23d1","type":"change","z":"3e3d3934.fbc6d6","g":"b6d37498.2a6e88","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":915,"y":160,"wires":[["8f92e984.4bf3d8"]],"l":false},{"id":"72f5c729.99a848","type":"change","z":"3e3d3934.fbc6d6","g":"b6d37498.2a6e88","name":"Set counter","rules":[{"t":"set","p":"counter","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":715,"y":160,"wires":[["67a459f5.6e4e58"]],"l":false},{"id":"34c74096.de4","type":"api-call-service","z":"3e3d3934.fbc6d6","g":"d3b3bfd.2513e4","name":"Select source with ID","server":"918a63e0.1bc5a","version":3,"debugenabled":false,"service_domain":"spotcast","service":"start","entityId":"{{speaker}}","data":"{\"account\":\"{{right_spotcast_account}}\",\"force_playback\":true}","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":695,"y":440,"wires":[["39421d5.c1f6ae2"]],"l":false},{"id":"c1bbcdf0.cd99","type":"switch","z":"3e3d3934.fbc6d6","g":"d3b3bfd.2513e4","name":"Use speaker name?","property":"use_spotify_speaker_name","propertyType":"msg","rules":[{"t":"true"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":655,"y":420,"wires":[["284d5dbb.3b0742"],["34c74096.de4"]],"l":false},{"id":"284d5dbb.3b0742","type":"api-call-service","z":"3e3d3934.fbc6d6","g":"d3b3bfd.2513e4","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":695,"y":400,"wires":[["39421d5.c1f6ae2"]],"l":false},{"id":"39421d5.c1f6ae2","type":"function","z":"3e3d3934.fbc6d6","g":"d3b3bfd.2513e4","name":"Connector","func":"return msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":735,"y":420,"wires":[["4273b52b.86a48c"]],"icon":"node-red/inject.svg","l":false},{"id":"37dd2238.d0ba4e","type":"comment","z":"3e3d3934.fbc6d6","g":"8e58633b.f0026","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 issue: \nIf 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. If you know how to fix it please contact me ([email protected]).\n\nRequirements:\n- Home Assistant\n- Official Home Assistant Google Cast integration\n- Google Cast-enabled speaker (Like Google Home)\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":120,"y":140,"wires":[]},{"id":"291f823b.84186e","type":"function","z":"3e3d3934.fbc6d6","g":"8e58633b.f0026","name":"Connector","func":"return msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":615,"y":760,"wires":[["2671e1f.1d2131e"]],"icon":"node-red/inject.svg","l":false},{"id":"97c2d021.92663","type":"api-current-state","z":"3e3d3934.fbc6d6","g":"9dfe1506.db76b8","name":"Ytube current state","server":"918a63e0.1bc5a","version":2,"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"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":755,"y":300,"wires":[["3b07a3ee.e0c41c"]],"l":false},{"id":"3b07a3ee.e0c41c","type":"function","z":"3e3d3934.fbc6d6","g":"9dfe1506.db76b8","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":795,"y":300,"wires":[["9d1fc864.18bbb8"]],"l":false},{"id":"9d1fc864.18bbb8","type":"switch","z":"3e3d3934.fbc6d6","g":"9dfe1506.db76b8","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":"true","repair":false,"outputs":2,"x":835,"y":300,"wires":[["5046d0e8.a90bb"],["bea5a031.bc8b8"]],"l":false},{"id":"bea5a031.bc8b8","type":"function","z":"3e3d3934.fbc6d6","g":"9dfe1506.db76b8","name":"Set account","func":"msg.ytube_temporary_account=msg.ytube_accounts[msg.counter];\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":715,"y":300,"wires":[["97c2d021.92663"]],"l":false},{"id":"5046d0e8.a90bb","type":"change","z":"3e3d3934.fbc6d6","g":"9dfe1506.db76b8","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":875,"y":280,"wires":[["b1d37ac3.a33f38"]],"l":false},{"id":"b30300bc.0d0b1","type":"change","z":"3e3d3934.fbc6d6","g":"9dfe1506.db76b8","name":"Set counter","rules":[{"t":"set","p":"counter","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":675,"y":280,"wires":[["bea5a031.bc8b8"]],"l":false},{"id":"b1d37ac3.a33f38","type":"function","z":"3e3d3934.fbc6d6","g":"637a9b01.1afb04","name":"Find right ytube account","func":"for(i=0;i<msg.ytube_accounts_count;i++)\n{\n    if(msg.media_type==\"ytube\" && msg.speaker==msg.ytube_accounts_data[i].attributes._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\" && msg.speaker==msg.ytube_accounts_data[i].attributes._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":975,"y":300,"wires":[["97603a8b.fc0428"]],"l":false},{"id":"97603a8b.fc0428","type":"switch","z":"3e3d3934.fbc6d6","g":"637a9b01.1afb04","name":"Is right account found","property":"is_right_account_found","propertyType":"msg","rules":[{"t":"true"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":1015,"y":300,"wires":[["1ca7637e.f4acad"],["34cfa225.c5127e"]],"l":false},{"id":"34cfa225.c5127e","type":"change","z":"3e3d3934.fbc6d6","g":"637a9b01.1afb04","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":1055,"y":320,"wires":[["1ca7637e.f4acad"]],"l":false},{"id":"1ca7637e.f4acad","type":"switch","z":"3e3d3934.fbc6d6","g":"637a9b01.1afb04","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":1095,"y":300,"wires":[["13d63878.6a03f8"],["fecb31e3.760f7"]],"l":false},{"id":"13d63878.6a03f8","type":"api-call-service","z":"3e3d3934.fbc6d6","g":"637a9b01.1afb04","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":1155,"y":300,"wires":[["fecb31e3.760f7"]],"l":false},{"id":"fecb31e3.760f7","type":"function","z":"3e3d3934.fbc6d6","g":"637a9b01.1afb04","name":"Connector","func":"return msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1195,"y":320,"wires":[["cf9f8b52.2cbcf8"]],"icon":"node-red/inject.svg","l":false},{"id":"5c9a8a8f.14b294","type":"api-call-service","z":"3e3d3934.fbc6d6","g":"e5691011.03755","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_resume\"}","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":655,"y":540,"wires":[["7c2774a8.acd06c"]],"l":false},{"id":"f29d0296.eaecc","type":"api-call-service","z":"3e3d3934.fbc6d6","g":"e5691011.03755","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\":speaker_data.attributes.friendly_name}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":635,"y":580,"wires":[["597cb36a.138bcc"]],"l":false},{"id":"d18a94ff.490d18","type":"api-call-service","z":"3e3d3934.fbc6d6","g":"e5691011.03755","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":735,"y":580,"wires":[["714fa835.876998"]],"l":false},{"id":"d420afee.9a2fc","type":"api-call-service","z":"3e3d3934.fbc6d6","g":"e5691011.03755","name":"URL set position","server":"918a63e0.1bc5a","version":3,"debugenabled":false,"service_domain":"media_player","service":"media_seek","entityId":"{{speaker}}","data":"{    \"seek_position\": {{media_position}}}","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":895,"y":580,"wires":[["7c2774a8.acd06c"]],"l":false},{"id":"df8533b4.7e8f5","type":"ha-wait-until","z":"3e3d3934.fbc6d6","g":"e5691011.03755","name":"Wait for start","server":"918a63e0.1bc5a","version":0,"outputs":2,"entityId":"{{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":855,"y":580,"wires":[["d420afee.9a2fc"],["d420afee.9a2fc"]],"l":false},{"id":"324f7274.a3881e","type":"delay","z":"3e3d3934.fbc6d6","g":"e5691011.03755","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":815,"y":580,"wires":[["df8533b4.7e8f5"]],"l":false},{"id":"597cb36a.138bcc","type":"delay","z":"3e3d3934.fbc6d6","g":"e5691011.03755","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":675,"y":580,"wires":[["d18a94ff.490d18"]],"l":false},{"id":"714fa835.876998","type":"function","z":"3e3d3934.fbc6d6","g":"e5691011.03755","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":775,"y":580,"wires":[["324f7274.a3881e"]],"l":false},{"id":"7c2774a8.acd06c","type":"function","z":"3e3d3934.fbc6d6","g":"e5691011.03755","name":"Connector","func":"return msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":935,"y":560,"wires":[["4273b52b.86a48c"]],"icon":"node-red/inject.svg","l":false},{"id":"2671e1f.1d2131e","type":"function","z":"3e3d3934.fbc6d6","g":"8e58633b.f0026","name":"Connector","func":"return msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":935,"y":760,"wires":[["4273b52b.86a48c"]],"icon":"node-red/inject.svg","l":false},{"id":"918a63e0.1bc5a","type":"server","name":"Home Assistant","version":1,"legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

Flow Info

Created 3 years, 11 months ago
Rating: not yet rated

Actions

Rate:

Node Types

Core
  • change (x10)
  • comment (x1)
  • delay (x6)
  • function (x19)
  • inject (x2)
  • switch (x14)
Other

Tags

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