Skip to content

Instantly share code, notes, and snippets.

@paulmooibroek
Last active October 31, 2015 17:24
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulmooibroek/f38309df456a0aa4c05b to your computer and use it in GitHub Desktop.
Save paulmooibroek/f38309df456a0aa4c05b to your computer and use it in GitHub Desktop.
Sonos TTS

Plays a warning message in Dutch once a day on a SONOS play 5 when the batteries of a Roomnode are below a critical level. Voice is in Dutch ( change nl-nl to "en-us" for English Tested on a Raspberry.

[{"id":"ba386057.845d3","type":"mqtt-broker","broker":"localhost","port":"1883"},{"id":"aa25eafc.55da18","type":"mqtt in","name":"Zolder Batterij vervangen","topic":"Zolder/Batterij","broker":"ba386057.845d3","x":113,"y":242,"z":"ee170d4e.11e8f","wires":[["3865d42b.c79a2c"]]},{"id":"3865d42b.c79a2c","type":"switch","name":"","property":"payload","rules":[{"t":"eq","v":"1"}],"checkall":"true","outputs":1,"x":297,"y":244,"z":"ee170d4e.11e8f","wires":[["4d98e0c1.b2672"]]},{"id":"9efec520.610138","type":"change","action":"replace","property":"payload","from":"","to":"De batterijen van de sensor op de zolder dienen vervangen te worden","reg":false,"name":"Melding Batterijen ","x":645,"y":239,"z":"ee170d4e.11e8f","wires":[["75deeb95.8a2114"]]},{"id":"4d98e0c1.b2672","type":"delay","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","rateUnits":"day","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":454,"y":241,"z":"ee170d4e.11e8f","wires":[["9efec520.610138"]]},{"id":"75deeb95.8a2114","type":"function","name":"SONOS Studie Speak Payload","func":"var text = msg.payload;\n\n/*\ninstall sonos Javascript -> https://www.npmjs.org/package/sonos\n\nExpand settings.js with sonos Context : functionGlobalContext: {wpi: require('wiring-pi'), sonos:require('sonos')}\n\nSome functions (see https://www.npmjs.org/package/sonos)\n\nsonos.getCurrentState(function(err, track) {\nconsole.log(err, track);\n });\nsonos.currentTrack(function(err, track) {\n console.log(err, track);\n});\nsonos.getMusicLibrary('playlists', {start: 0, total: 25}, function(err, result){\n console.log([err, result]);\n });\nsonos.play('caz_audio_01', function(err, playing) {\n console.log([err, playing]);\n});\n*/\n// See SONOS program , INFO over Sonos voor IP numbers\nvar sonos = new context.global.sonos.Sonos('10.19.0.95');\n\n//Replace all spaces with a _ because Sonos doesn't support spaces\ntext = text.replace(/ /g,'_');\n\n//For supported languages see www.voicerss.org/api/documentation.aspx\n//This url just redirects to voices because of the specific url format for the sonos\nvar url = 'http://i872953.iris.fhict.nl/speech/nl-nl_' + encodeURIComponent(text) + '.mp3';\n\nsonos.play(url, function(err, playing) {\n console.log([err, playing]);\n});","outputs":1,"x":913,"y":238,"z":"ee170d4e.11e8f","wires":[[]]}]
@rabarar
Copy link

rabarar commented Sep 21, 2014

I'm not able to get the Sonos to work? Any ideas? The module was installed, but the code seems to not find the module. Can can successfully use the package running the examples, so it's something with nodered and the inability to use the package. I'm not a js guru, but it looks like it fails here:

var sonos = new context.global.sonos.Sonos('192.16.1.16');

21 Sep 11:50:17 - [error] [function:SONOS Studie Speak Payload] TypeError: Cannot read property 'Sonos' of undefined

@mountaindude
Copy link

I am getting the same error - was a solution found to this?

@mountaindude
Copy link

Solved it, a sonos context had to be added to the node-red settings.js file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment