Final final ? Flow code with the new volume level controls and updated instructions.
[{"id":"a300d823.d91888","type":"tab","label":"Audio Alerts","disabled":false,"info":""},{"id":"7c792e59.49c9b","type":"comment","z":"a300d823.d91888","name":"Dog Barking? - Play Recorded Audio Messages (Double click text boxes for more info)","info":"","x":580,"y":40,"wires":[]},{"id":"f6382b78.927ec8","type":"mios-in","z":"a300d823.d91888","name":"Noise Alert (Virtual Motion Sensor)","server":"db098590.052cd8","item":"Kitchen:Noise Alert:ArmedTripped","exact":false,"x":180,"y":140,"wires":[["38aa21bd.36581e"]]},{"id":"38aa21bd.36581e","type":"switch","z":"a300d823.d91888","name":"Noise Detected","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":420,"y":140,"wires":[["f650984d.1fba88"]]},{"id":"46c31311.5c3a0c","type":"cast-to-client","z":"a300d823.d91888","name":"Kitchen-Speaker","url":"","contentType":"","message":"","language":"En-gb","ip":"","port":"","volume":"","x":670,"y":240,"wires":[["ddb1934a.dc148"]],"icon":"node-red-contrib-cast/google-home1.svg"},{"id":"d5547bb5.4c16b8","type":"http in","z":"a300d823.d91888","name":"http request from scene","url":"/audioTrigger1","method":"get","upload":false,"swaggerDoc":"","x":140,"y":240,"wires":[["defed89.98d6b28"]]},{"id":"69e3ad12.3c8d34","type":"comment","z":"a300d823.d91888","name":"Triggered from a Vera Scene","info":"Run this LUA code from your Vera Scene - Change to your Node-Red IP \nluup.inet.wget(\"http://192.168.0.4:1880/audioTrigger1\")\n\n/audioTrigger1 is specified in the HTTP IN Node in the URL field and can be changed if you wish.","x":160,"y":200,"wires":[]},{"id":"5939e7a.7204218","type":"cast-to-client","z":"a300d823.d91888","name":"Kitchen-Speaker","url":"","contentType":"","message":"","language":"En-gb","ip":"","port":"","volume":"","x":850,"y":140,"wires":[["9bdd6cda.cb492"]],"icon":"node-red-contrib-cast/google-home1.svg"},{"id":"817c54e1.981ec8","type":"comment","z":"a300d823.d91888","name":"Triggered by Vera device - Virtual Motion Sensor","info":"In Vera my virtual motion sensor is named \"Noise Alert\" and is in the \"Kitchen\" room. \n\nNOTE - Also the virtual motion sensor must be Armed.\n\nTherefore the MIOS device item I am monitoring for in Node-Red is:\n\nKitchen:Noise Alert:ArmedTripped\n\nYou can test and manually trip your virtual motion sensor by entering this in to a web browser:\n\nhttp://VERA-IP/port_3480/data_request?id=lu_variableset&DeviceNum=X&serviceId=urn:micasaverde-com:serviceId:SecuritySensor1&Variable=Tripped&Value=1\n\nEnter your Vera's IP address and the device number of your virtual motion sensor in the DeviceNum=X change X for the device number etc.\n\nYou can untrip it by setting it to ZERO instead\n\nTripped&Value=0","x":220,"y":100,"wires":[]},{"id":"6b14f43b.aefe3c","type":"comment","z":"a300d823.d91888","name":"Google Home / Cast","info":"In the Cast devices you don't need to specify the IP address of your Google Home speaker in the IP field or need to specify the port number,\nthese are instead specified in the Function Node(s).\n\nThe MediaURL field should be also left blank, you specify the URLs for the .wav files in the Function Node(s) instead.\n\nIn the Language field specify either:\n\nEn-gb OR En-us OR some other language. ","x":670,"y":200,"wires":[]},{"id":"1cc52c04.80b9c4","type":"comment","z":"a300d823.d91888","name":"Google Home / Cast","info":"In the Cast devices you don't need to specify the IP address of your Google Home speaker in the IP field or need to specify the port number,\nthese are instead specified in the Function Node(s).\n\nThe MediaURL field should be also left blank, you specify the URLs for the .wav files in the Function Node(s) instead.\n\nIn the Language field specify either:\n\nEn-gb OR En-us OR some other language. ","x":850,"y":100,"wires":[]},{"id":"f650984d.1fba88","type":"function","z":"a300d823.d91888","name":"Random Audio Files","func":"msg.payload ={};\nvar urls = [\"http://192.168.0.4:1880/alert1.wav\", \n \"http://192.168.0.4:1880/alert2.wav\",\n \"http://192.168.0.4:1880/alert3.wav\",\n \"http://192.168.0.4:1880/alert4.wav\",\n \"http://192.168.0.4:1880/alert5.wav\"]\n\nmsg.payload.url = urls[Math.floor(Math.random() * urls.length)];\nmsg.payload.volume = 50;\nmsg.payload.contentType = \"audio/vnd.wav\";\nmsg.payload.ip = \"192.168.0.19\";\nmsg.payload[\"port\"] = 8009;\nnode.send(msg);\nsetTimeout(function(){\ndelete msg.payload.url;\ndelete msg.payload.contentType;\nmsg.payload.volume = 30;\nnode.send(msg);\n}, 30000);\nreturn;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":620,"y":140,"wires":[["5939e7a.7204218"]]},{"id":"defed89.98d6b28","type":"function","z":"a300d823.d91888","name":"Random Audio Files","func":"var urls = [\"http://192.168.0.4:1880/alert1.wav\", \n \"http://192.168.0.4:1880/alert2.wav\",\n \"http://192.168.0.4:1880/alert3.wav\",\n \"http://192.168.0.4:1880/alert4.wav\",\n \"http://192.168.0.4:1880/alert5.wav\"]\n\nmsg.payload.url = urls[Math.floor(Math.random() * urls.length)];\nmsg.payload.volume = 50;\nmsg.payload.contentType = \"audio/vnd.wav\";\nmsg.payload.ip = \"192.168.0.19\";\nmsg.payload[\"port\"] = 8009;\nnode.send(msg);\nsetTimeout(function(){\ndelete msg.payload.url;\ndelete msg.payload.contentType;\nmsg.payload.volume = 30;\nnode.send(msg);\n}, 30000);\nreturn;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":400,"y":240,"wires":[["46c31311.5c3a0c"]]},{"id":"ddb1934a.dc148","type":"debug","z":"a300d823.d91888","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":870,"y":240,"wires":[]},{"id":"9bdd6cda.cb492","type":"debug","z":"a300d823.d91888","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1030,"y":140,"wires":[]},{"id":"e7db8dc5.c7926","type":"comment","z":"a300d823.d91888","name":"Function for Random Audio Files","info":"I uploaded my .wav files in to a Public HTTP folder I created. \n\nYou need to edit the Node-Red settings.js file to enable httpstatic\n\nDocumentation Here:\n\nhttps://nodered.org/docs/user-guide/runtime/configuration\n\nvar urls examples:\n\nvar urls = [\"http://192.168.0.4:1880/alert1.wav\", \"http://192.168.0.4:1880/alert2.wav\",\n \"http://192.168.0.4:1880/alert3.wav\"]\n \nChange the IP address to that of your own Node-Red.\n\nOn Line 10 you can set the volume level for the .wav file to play at.\n\nmsg.payload.volume = 50\n\nOn Line 17 you can set the volume level that the Google Home speaker should return to after the .wav file has played.\n\nOn Lines 11 and 12 specifiy the static LAN IP address of your Google Home speaker and its port number 8009.\n\nmsg.payload.ip = \"192.168.0.19\";\nmsg.payload[\"port\"] = 8009;\n\nOn line 19 you can specifiy the timeout in milliseconds. This is the amount of time until the volume will be decreased to the lower level, so make it long enough for your .wav files to finish playing. Default is 30000 aka 30 seconds. \n\n}, 30000);","x":590,"y":100,"wires":[]},{"id":"3b31a9bb.0784b6","type":"comment","z":"a300d823.d91888","name":"Function for Random Audio Files","info":"I uploaded my .wav files in to a Public HTTP folder I created. \n\nYou need to edit the Node-Red settings.js file to enable httpstatic\n\nDocumentation Here:\n\nhttps://nodered.org/docs/user-guide/runtime/configuration\n\nvar urls examples:\n\nvar urls = [\"http://192.168.0.4:1880/alert1.wav\", \"http://192.168.0.4:1880/alert2.wav\",\n \"http://192.168.0.4:1880/alert3.wav\"]\n \nChange the IP address to that of your own Node-Red.\n\nOn Line 10 you can set the volume level for the .wav file to play at.\n\nmsg.payload.volume = 50\n\nOn Line 17 you can set the volume level that the Google Home speaker should return to after the .wav file has played.\n\nOn Lines 11 and 12 specifiy the static LAN IP address of your Google Home speaker and its port number 8009.\n\nmsg.payload.ip = \"192.168.0.19\";\nmsg.payload[\"port\"] = 8009;\n\nOn line 19 you can specifiy the timeout in milliseconds. This is the amount of time until the volume will be decreased to the lower level, so make it long enough for your .wav files to finish playing. Default is 30000 aka 30 seconds. \n\n}, 30000);","x":430,"y":200,"wires":[]},{"id":"db098590.052cd8","type":"mios-server","z":"","name":"Vera-Plus","host":"192.168.0.12","port":"3480"}]