Skip to content

Instantly share code, notes, and snippets.

@cheeaun
Last active August 4, 2016 17:25
Show Gist options
  • Save cheeaun/5234591 to your computer and use it in GitHub Desktop.
Save cheeaun/5234591 to your computer and use it in GitHub Desktop.
Sonos-2-HipChat notification node.js script
npm install sonos
npm install git://github.com/balbeko/node-hipchat.git
var config = {
apiKey: 'HIPCHAT API KEY',
ipAddress: 'IP ADDRESS TO SONOS',
roomID: 'ROOM ID IN HIPCHAT',
msgFrom: 'Sonos',
msgColor: 'purple',
pollInterval: 15000
};
var Sonos = require('sonos').Sonos;
var https = require('https');
var HipChat = require('node-hipchat');
var hipClient = new HipChat(config.apiKey);
// hipClient.listRooms(function(rooms){
// console.dir(rooms)
// });
console.log('Connecting Sonos...');
var sonos = new Sonos(config.ipAddress);
var lastTitle = null;
setInterval(function(){
console.log('Polling...');
sonos.currentTrack(function(e, track){
if (e){
console.error(e);
return;
}
if (!track){
console.error(track);
return;
};
var title = track.title;
if (!title) return;
if (title == lastTitle) return;
lastTitle = title;
var item = track._item;
var path = '';
if (item){
console.log(item);
try {
path = decodeURIComponent(item.res[0]['_']);
} catch (e){}
}
var message = '♫ ' + track.title + (track.artist ? (' – ' + track.artist) : '');
hipClient.postMessage({
room_id: config.roomID,
from: config.msgFrom,
message: message,
color: config.msgColor
});
});
}, config.pollInterval);
@tatchison-skyhook
Copy link

are there any instructions for how to install/run this?

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