Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Using Google Relay Assistant in Home Assistant and playing back responses
[{"id":"4559289f.b3b438","type":"tab","label":"Assistant Relay","disabled":false,"info":""},{"id":"a87f10d7.69ca1","type":"delay","z":"4559289f.b3b438","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"20","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"x":340,"y":140,"wires":[["e4181900.7ce448"]]},{"id":"cc5745c5.422758","type":"http request","z":"4559289f.b3b438","name":"post","method":"POST","ret":"obj","paytoqs":false,"url":"http://localhost:3000/assistant","tls":"","persist":false,"proxy":"","authType":"","x":770,"y":140,"wires":[["613a534a.7da58c"]]},{"id":"e4181900.7ce448","type":"function","z":"4559289f.b3b438","name":"set payload and headers","func":"msg.message = msg.payload;\nmsg.payload = {\n \"name\": \"Jon\",\n \"command\": msg.message,\n \"broadcast\": false\n};\nmsg.headers = {};\nmsg.headers['Content-Type'] = 'application/json';\nreturn msg;","outputs":1,"noerr":0,"x":570,"y":140,"wires":[["cc5745c5.422758"]]},{"id":"1e0fbc6d.63d9a4","type":"inject","z":"4559289f.b3b438","name":"Good night","topic":"media_player.kitchen_mini","payload":"Good night","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":140,"wires":[["a87f10d7.69ca1"]]},{"id":"94ec4458.0ce508","type":"http request","z":"4559289f.b3b438","name":"get audio","method":"GET","ret":"bin","paytoqs":false,"url":"","tls":"","persist":false,"proxy":"","authType":"","x":780,"y":220,"wires":[["3e0b1315.f6784c"]]},{"id":"c2274863.13b0b8","type":"function","z":"4559289f.b3b438","name":"set payload and headers","func":"const regex = /v=(?<filename>.*)/s;\nlet str = msg.payload.audio;\n\nmsg.url = 'http://localhost:3000' + msg.payload.audio;\nmsg.payload = \"\";\nmsg.headers = {};\nmsg.headers['Accept'] = 'audio/x-wav';\nmsg.headers['Range'] = 'bytes=0-';\n\nlet groups = str.match(regex).groups;\nlet {filename} = groups;\n\n\nmsg.filename = `/config/www/relay/${filename}.wav`;\n\nmsg.file = `${filename}.wav`;\n\nreturn msg;","outputs":1,"noerr":0,"x":570,"y":220,"wires":[["94ec4458.0ce508"]]},{"id":"61f439cb.f48058","type":"api-call-service","z":"4559289f.b3b438","name":"play audio","server":"e16dd2e.15c043","version":1,"debugenabled":true,"service_domain":"media_player","service":"play_media","entityId":"{{topic}}","data":"{\"media_content_id\":\"https://ha.hastarin.com/local/relay/{{file}}\",\"media_content_type\":\"music\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1130,"y":200,"wires":[[]]},{"id":"988cb97f.d8bef8","type":"link in","z":"4559289f.b3b438","name":"","links":["c95372fd.2dea","e57b38d2.b8bcc8"],"x":175,"y":40,"wires":[["a87f10d7.69ca1"]]},{"id":"3e0b1315.f6784c","type":"file","z":"4559289f.b3b438","name":"save","filename":"","appendNewline":false,"createDir":true,"overwriteFile":"true","encoding":"none","x":930,"y":220,"wires":[["61f439cb.f48058","ce46d625.268dd8"]]},{"id":"f06e2561.428ae8","type":"comment","z":"4559289f.b3b438","name":"requires find-remove","info":"https://www.npmjs.com/package/find-remove\n\nYou'll need to install this module and edit your functionGlobalContext in setting.js file\n\n```\nfunctionGlobalContext: {\n findRemove:require('find-remove')\n}","x":1150,"y":280,"wires":[]},{"id":"c11adc91.66a91","type":"comment","z":"4559289f.b3b438","name":"allow time for audio to download","info":"","x":1010,"y":100,"wires":[]},{"id":"5056def9.ffa93","type":"comment","z":"4559289f.b3b438","name":"message payload should be the message to Google Assistant","info":"","x":480,"y":40,"wires":[]},{"id":"7380c95d.105b08","type":"comment","z":"4559289f.b3b438","name":"topic should be the entity_id to play back on eg. media_player.googlehome","info":"","x":520,"y":80,"wires":[]},{"id":"ce46d625.268dd8","type":"function","z":"4559289f.b3b438","name":"delete old files","func":"let findRemoveSync = global.get('findRemove');\nvar result = findRemoveSync('/config/www/relay', {age: {seconds: 3600}, extensions: '.wav', limit: 100});\n\nreturn msg;","outputs":1,"noerr":0,"x":1140,"y":320,"wires":[[]]},{"id":"613a534a.7da58c","type":"delay","z":"4559289f.b3b438","name":"","pauseType":"delay","timeout":"300","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":950,"y":140,"wires":[["c2274863.13b0b8"]]},{"id":"e16dd2e.15c043","type":"server","z":"","name":"Home Assistant"}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.