Sonos Custom Message


(Steve) #1

I’m very new to this but I’ve already created multiple IFTTT and SmartThings labs etc… but one thing I can’t figure out is how do I have my sonos speaker play a custom message at a given date/time?
When using IFTTT it only turns on the sonos.

Thoughts? Thanks in advance!

(What I own so far: Sonos, SmartThings water sensors, Hue bulbs, & have IFTTT login)


(Ron S) #2

Here’s a most basic custom Sonos app whereby you can select a Sonos Player for standard modes.
E.g.

  1. During Home/Away mode, you may want to use your Family Room Sonos.
  2. During night, you may want Bedroom Sonos to play notification.

Currently, this shabby app will allow you to select Sonos for modes, play any contact sensor status when changed from open/close and of course the mode changes. In the process of extending it but this will give you the basic idea… The messages are hardcoded as of now but you can change it and make it much friendlier… This is very basic.

// Automatically generated. Make future change here.
definition(
    name: "Sonos Notifier",
    namespace: "rsarkar",
    author: "Ron Sarkar",
    description: "Sonos Notifier",
    category: "My Apps",
    iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
    iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png",
    iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png")

preferences {
	section {
		input "sonos1", "capability.musicPlayer", title: "Sonos Device for Home Mode?", required: true
	}
	section {
		input "sonos2", "capability.musicPlayer", title: "Sonos Device for Away Mode?", required: true
	}
	section {
		input "sonos3", "capability.musicPlayer", title: "Sonos Device for Night Mode?", required: true
	}
	section("Choose one or more doors..."){
		input "doors", "capability.contactSensor", title: "Doors?", required: false, multiple: true
	}
}

def installed() {
	log.debug "Installed with settings: ${settings}"
	subscribeToEvents()
}

def updated() {
	log.debug "Updated with settings: ${settings}"
	unsubscribe()
	subscribeToEvents()
}

def subscribeToEvents() {
	subscribe(doors, "contact", doorEventHandler)
    subscribe(location, modeChangeHandler)
}

def doorEventHandler(evt) {
	//log.debug "Current mode = ${location.mode}"
    def msg = "$evt.displayName is $evt.value";
    log.debug msg;
    switch (location.mode) {
        case 'Home':
        	log.debug ("Home Mode is Home");
            playNotification(sonos1, msg);
            break
        case 'Away':
            log.debug ("Home Mode is Away");
            playNotification(sonos2, msg);
            break
        case 'Night':
            log.debug ("Home Mode is Night");
            playNotification(sonos3, msg);
            break
        default:
            break
    }    
}

def modeChangeHandler(evt){
	playNotification(sonos2, "Home mode has changed to ${location.mode}");
}

private playNotification(player, msg){
    log.trace "Playing $msg on $player";
    state.sound = textToSpeech(msg instanceof List ? msg : msg) 
    log.info(state.sound.uri)
    player.playTrackAndRestore(state.sound.uri, state.sound.duration, 50);	
}

(Morgan) #3

Just do the Sonos Custom Message, and just select on a schedule. I do it to remind me to take the garbage to the curb each week and it works great.


(Steve) #4

THRASH99ER, what am I missing? I can’t seem to do it that easily. Go into SmartThings app, then what? It seems I have to go into the water sensor and activate the alarm using sonos custom message. What’s the path you’re taking? THANKS!!!


(Steve) #5

Crap, I think I just figured it out. It was too easy. Thanks THRASH99ER and SMARt for responding


((Possibly not the Matt you're looking for)) #6

This is a great use of the Sonos notifications, @thrash99er. I am definitely trying this.

For other readers, this can done done with the SmartApp “Sonos Notify with Sound” in SmartThings Labs.