Automation ideas for pet dog whilst away?

oh bugger that works in the web browser, so simple when you know how.

Thanks.

1 Like

The function in node-red still doesn’t work however and says “error load media”

var urls = ["/home/pi/.node-red/public/alert1.wav", 
            "/home/pi/.node-red/public/alert2.wav",
            "/home/pi/.node-red/public/alert3.wav"]
msg.url = urls[Math.floor(Math.random() * urls.length)];
msg.contentType = "audio/vnd.wav";
return msg;

But if I change it to this instead it now works

var urls = ["http://192.168.0.4:1880/alert1.wav", 
            "http://192.168.0.4:1880/alert2.wav",
            "http://192.168.0.4:1880/alert3.wav"]
msg.url = urls[Math.floor(Math.random() * urls.length)];
msg.contentType = "audio/vnd.wav";
return msg;

This means I can now delete those 3x HTTP nodes as they are no longer needed anymore.

OK this is my final Node-Red Flow

Node-Red code you can import:

[{"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":"192.168.0.19","port":"8009","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":"192.168.0.19","port":"8009","volume":"","x":830,"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 specify the static LAN IP address of your Google Home speaker in the IP field. \n\nSpecify the port number of: \n\n8009\n\nThe MediaURL field should be 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. \n\n\n\n\n\n","x":670,"y":200,"wires":[]},{"id":"1cc52c04.80b9c4","type":"comment","z":"a300d823.d91888","name":"Google Home / Cast","info":"In the Cast devices specify the static LAN IP address of your Google Home speaker in the IP field. \n\nSpecify the port number of: \n\n8009\n\nThe MediaURL field should be 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. \n\n\n\n\n\n","x":830,"y":100,"wires":[]},{"id":"f650984d.1fba88","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\"]\nmsg.url = urls[Math.floor(Math.random() * urls.length)];\nmsg.contentType = \"audio/vnd.wav\";\nreturn msg;","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\"]\nmsg.url = urls[Math.floor(Math.random() * urls.length)];\nmsg.contentType = \"audio/vnd.wav\";\nreturn msg;","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":1010,"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 youe own Node-Red.","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 youe own Node-Red.","x":430,"y":200,"wires":[]},{"id":"db098590.052cd8","type":"mios-server","z":"","name":"Vera-Plus","host":"192.168.0.12","port":"3480"}]

I just need to record some audio files now and see if it actually works and stops him barking?

Thanks for your help again @ElCid

1 Like

As always love to help.

note - you can use the static folder as a local file server to.

1 Like

Well the whole setup works perfectly, just tested it putting the dog in the kitchen. The tablet in the lounge detects him barking each time and it triggers the random .wav files to play on the Google Home speaker in the kitchen, all working very nicely !

However the dog pretty much ignored my voice recordings and continued to bark and scratch at the door. He’s not use to being left on his own even for two damn minutes, need to do a lot of training with him I think.

Might try a low or high frequency noise next on a .wav file that or a muzzle


@ElCid

In the Cast node you can specify the volume, I have set it to 70.

This works and increased the volume to 70 when the flow is triggered.

image

I would like to set the volume back down again after to say 40. But not sure how to do this.

I tried adding another Cast node after the first one with its volume set to 40 but it didn’t work.

Add a pause. This kind of devices usually needs some interval between commands.

Using a change node try feeding one of the below into a cast node, with just ip and port configured.

  • msg.lowerVolumeLimit or msg.payload.lowerVolumeLimit will set the volume to this value, if the current volume is below this value.
  • msg.upperVolumeLimit or msg.payload.upperVolumeLimit will set the volume to this value, if the current volume is above this limit.

Hi

The msg.payload.lowerVolumeLimit works when the flow is run it increases the volume of the Google Home speaker before playing the .wav file.

However I am not sure how to then decrease the volume back down again after the .wav file has finished playing.

I tried something like this but it doesn’t work.

This works and lowers the volume after a 30 second delay. Not sure if its the best way to do it.

does it not work if you have the casts in line with a small delay between e.g.


the last change node before final cast set like this

[{"id":"8201bedc.782588","type":"change","z":"a8699ddc.35b368","name":"vol down","rules":[{"t":"set","p":"upperVolumeLimit","pt":"msg","to":"40","tot":"str"},{"t":"set","p":"ip","pt":"msg","to":"192.168.1.20","tot":"str"},{"t":"set","p":"port","pt":"msg","to":"8009","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":770,"y":180,"wires":[["5f71942a.6bb15c"]]}]

Hi

I’ve tried what you suggested the volume is increased to 50 then the .wav file plays.

However after the .wav file has finished playing nothing further happens, the volume is not decreased back down to 30 as I have set in the Volume Down function.

what is the full debug message after the first cast?

I don’t know I just changed the function nodes.

Instead of using msg.payload.lowerVolumeLimit and msg.payload.upperVolumeLimit I set both the function nodes to just use msg.payload.volume instead.

The first volume up function sets the volume to 50 then the .wav play. The second function then sets the volume to 30 but the .wav then plays again at the lower volume level.

So I don’t think they can all be in a single line / flow.

yes i think its possible , maybe that a property still exists. post your function nodes.

Volume Up Function:

image

Volume Down Function:

image

Yes the msg.url and contentType will still exist

Try - For volume down change node.

Nice idea but it is still playing the .wav file for a second time at the lower volume level.

It doesn’t seem to be deleting the url and contentType

image

I Deployed and restarted All Flows.

Ok i reworked the original function

no need for all those nodes, the cast node needs no settings all settings are in function node.

It should? send a cast then wait 3 seconds(editable in function node) and send a volume change cast.

[{"id":"4e22b00.de0eb5","type":"http in","z":"4484ee28.caa3c","name":"","url":"http","method":"get","upload":false,"swaggerDoc":"","x":180,"y":640,"wires":[["d5bce64d.ef7c68"]]},{"id":"d5bce64d.ef7c68","type":"function","z":"4484ee28.caa3c","name":"","func":"var urls = [\"ip:1880/naughty-dog.wav\", \n            \"ip:1880/media2.wav\",\n            \"ip:1880/media3.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.1.12\";\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}, 3000);\nreturn;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":350,"y":640,"wires":[["b734f44.e9a4b08","c8c40ac0.6b727"]]},{"id":"c8c40ac0.6b727","type":"function","z":"4484ee28.caa3c","name":"cast block","func":"// this is a representation of a cast as i do not have the node\n// the cast will need no settings\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":540,"y":640,"wires":[[]]}]

Hi

Thanks for this !

Here is the code I now have in the function block.

var urls = ["http://192.168.0.4:1880/alert1.wav", 
            "http://192.168.0.4:1880/alert2.wav",
            "http://192.168.0.4:1880/alert3.wav",
            "http://192.168.0.4:1880/alert4.wav",
            "http://192.168.0.4:1880/alert5.wav"]

msg.payload.url = urls[Math.floor(Math.random() * urls.length)];
msg.payload.volume = 50;
msg.payload.contentType = "audio/vnd.wav";
msg.payload.ip = "192.168.0.19";
msg.payload["port"] = 8009;
node.send(msg);
setTimeout(function(){
delete msg.payload.url;
delete msg.payload.contentType;
msg.payload.volume = 30;
node.send(msg);
}, 3000);
return;

When I initiate the Flow it changes the volume on the Google Home speaker up to 50% but then right away it changes the volume down to 30% and then the .wav file plays at the lower volume.

I then change 3000 to 30000 aka 30 seconds and now it seems to be working perfectly.
It plays the .wav at 50% and then 30 seconds later lowers the volume to 30%.

Thank you very much !