XBMC Notifications

I decided to dig up this old thread and get XBMC notifications working through a Smartapp. Notifications work on any version of XBMC newer than 12.0 (Gotham) on Windows, OS X, or Linux. I have not gotten sendHubCommand to work, so currently all the traffic passed to XBMC has to come from the ST cloud instead of local. You will have to open up a port on your network to get this working at its current state.

/**
 *  XBMC Notifications
 *
 *  Author: nelemansc@gmail.com
 *  Date: 2014-11-18
 *
 *  
 *	This will display a pop-up notification in XBMC to alert you of anything you deem beneficial.		
 *						
 *	Requirements:
 *	XBMC (Kodi) 12.0 or newer
 *  Port open on network to allow traffic from SmartThings cloud to XBMC 
 *  Enable the XBMC webserver found in Settings > Network > Webserver
 *
 *  Set the following settings in XBMC:
 *  Allow control of XBMC via HTTP - Yes
 *  Port - your choice
 *  Username - your choice
 *  Password - your choice
 *
 *  
 */

definition(
    name: "XBMC Notifier",
    namespace: "nelemansc",
    author: "nelemansc@gmail.com",
    description: "Get a notification in XBMC when any of a variety of SmartThings are activated.  Supports motion, contact, acceleration, presence, smoke, moisture, and switches.",
    category: "Convenience",
    iconUrl: "http://i59.tinypic.com/2zqyhs2.png",
    iconX2Url: "http://i59.tinypic.com/2zqyhs2.png",
    iconX3Url: "http://i59.tinypic.com/2zqyhs2.png")

preferences {
	section("Choose one or more, when..."){
		input "motion", "capability.motionSensor", title: "Motion Here", required: false
		input "contact", "capability.contactSensor", title: "Contact Opens", required: false
		input "acceleration", "capability.accelerationSensor", title: "Acceleration Detected", required: false
		input "mySwitch", "capability.switch", title: "Switch Turned On", required: false
		input "arrivalPresence", "capability.presenceSensor", title: "Arrival Of", required: false
		input "departurePresence", "capability.presenceSensor", title: "Departure Of", required: false
		input "smoke", "capability.smokeDetector", title: "Smoke Detected", required: false
		input "water", "capability.waterSensor", title: "Water Sensor Wet", required: false
    }
	section("Enter WAN IP address"){
		input "IPAddress", "text", title: "IP Address", required: true
	}
	section("XBMC webserver port"){
		input "Port", "text", title: "Port", required: true
	}
 	section("XBMC webserver Credentials") {
        input "Username", "text", title: "Username", required: true
        input "Password", "text", title: "Password", required: true
  	}
}

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

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

def subscribeToEvents() {
	subscribe(contact, "contact.open", sendMessage)
	subscribe(acceleration, "acceleration.active", sendMessage)
	subscribe(motion, "motion.active", sendMessage)
	subscribe(mySwitch, "switch.on", sendMessage)
	subscribe(arrivalPresence, "presence.present", sendMessage)
	subscribe(departurePresence, "presence.not present", sendMessage)
    subscribe(smoke, "smoke.detected", sendMessage)
	subscribe(smoke, "smoke.tested", sendMessage)
	subscribe(smoke, "carbonMonoxide.detected", sendMessage)
	subscribe(water, "water.wet", sendMessage)
}
    

def sendMessage(evt) {

if (evt.name == "contact") {
	log.debug "Event - contact"
	def contactName = "$contact"
	def contactNameEncoded = "$contactName".encodeAsURL()
	def contactNameEncoded2 = "$contactNameEncoded".replaceAll(/%5B/,"")
	def contactNameEncodedFinal = "$contactNameEncoded2".replaceAll(/%5D/,"")
    def contactState = "$evt.value"
	def contactStateEncoded = "$contactState".encodeAsURL()
    log.debug "$contactNameEncodedFinal"
    httpGet("http://$Username:$Password@$IPAddress:$Port/jsonrpc?request=%7B%22jsonrpc%22:%222.0%22%2C%22method%22:%22GUI.ShowNotification%22%2C%22params%22:%7B%22title%22:%22SmartThings%22%2C%22message%22:%22$contactNameEncodedFinal%20$contactStateEncoded%22%7D%2C%22id%22:1%7D", successClosure)
	}
    
if (evt.name == "motion") {
log.debug "Event - motion"
	def motionName = "$motion"
	def motionNameEncoded = "$motionName".encodeAsURL()
	def motionNameEncoded2 = "$motionNameEncoded".replaceAll(/%5B/,"")
	def motionNameEncodedFinal = "$motionNameEncoded2".replaceAll(/%5D/,"")
    def motionState = "$evt.value"
	def motionStateEncoded = "$motionState".encodeAsURL()
    log.debug "$motionNameEncodedFinal"
    httpGet("http://$Username:$Password@$IPAddress:$Port/jsonrpc?request=%7B%22jsonrpc%22:%222.0%22%2C%22method%22:%22GUI.ShowNotification%22%2C%22params%22:%7B%22title%22:%22SmartThings%22%2C%22message%22:%22$motionNameEncodedFinal%20$motionStateEncoded%22%7D%2C%22id%22:1%7D", successClosure)
    }
    
if (evt.name == "acceleration") {
	log.debug "Event - acceleration"
	def accelerationName = "$acceleration"
	def accelerationNameEncoded = "$accelerationName".encodeAsURL()
	def accelerationNameEncoded2 = "$accelerationNameEncoded".replaceAll(/%5B/,"")
	def accelerationNameEncodedFinal = "$accelerationNameEncoded2".replaceAll(/%5D/,"")
    def accelerationState = "$evt.value"
	def accelerationStateEncoded = "$accelerationState".encodeAsURL()
    log.debug "$accelerationNameEncodedFinal"
    httpGet("http://$Username:$Password@$IPAddress:$Port/jsonrpc?request=%7B%22jsonrpc%22:%222.0%22%2C%22method%22:%22GUI.ShowNotification%22%2C%22params%22:%7B%22title%22:%22SmartThings%22%2C%22message%22:%22$accelerationNameEncodedFinal%20$accelerationStateEncoded%22%7D%2C%22id%22:1%7D", successClosure)
    }
    
if (evt.name == "switch") {
	log.debug "Event - switch"
	def switchName = "$mySwitch"
	def switchNameEncoded = "$switchName".encodeAsURL()
	def switchNameEncoded2 = "$switchNameEncoded".replaceAll(/%5B/,"")
	def switchNameEncodedFinal = "$switchNameEncoded2".replaceAll(/%5D/,"")	
    def switchState = "$evt.value"
	def switchStateEncoded = "$switchState".encodeAsURL()
    log.debug "$switchNameEncodedFinal"
    httpGet("http://$Username:$Password@$IPAddress:$Port/jsonrpc?request=%7B%22jsonrpc%22:%222.0%22%2C%22method%22:%22GUI.ShowNotification%22%2C%22params%22:%7B%22title%22:%22SmartThings%22%2C%22message%22:%22$switchNameEncodedFinal%20$switchStateEncoded%22%7D%2C%22id%22:1%7D", successClosure)

	}
    
if (evt.name == "presence") {
	log.debug "Event - presence"
	def presenceName = "$presence"
	def presenceNameEncoded = "$presenceName".encodeAsURL()
	def presenceNameEncoded2 = "$presenceNameEncoded".replaceAll(/%5B/,"")
	def presenceNameEncodedFinal = "$presenceNameEncoded2".replaceAll(/%5D/,"")
    def presenceState = "$evt.value"
	def presenceStateEncoded = "$presenceState".encodeAsURL()
    log.debug "$presenceNameEncodedFinal"
    httpGet("http://$Username:$Password@$IPAddress:$Port/jsonrpc?request=%7B%22jsonrpc%22:%222.0%22%2C%22method%22:%22GUI.ShowNotification%22%2C%22params%22:%7B%22title%22:%22SmartThings%22%2C%22message%22:%22$presenceNameEncodedFinal%20$presenceStateEncoded%22%7D%2C%22id%22:1%7D", successClosure)
    }
    
if (evt.name == "smoke") {
	log.debug "Event - smoke"
	def smokeName = "$smoke"
	def smokeNameEncoded = "$smokeName".encodeAsURL()
	def smokeNameEncoded2 = "$smokeNameEncoded".replaceAll(/%5B/,"")
	def smokeNameEncodedFinal = "$smokeNameEncoded2".replaceAll(/%5D/,"")
    def smokeState = "$evt.value"
	def smokeStateEncoded = "$smokeState".encodeAsURL()
    log.debug "$smokeNameEncodedFinal"
    httpGet("http://$Username:$Password@$IPAddress:$Port/jsonrpc?request=%7B%22jsonrpc%22:%222.0%22%2C%22method%22:%22GUI.ShowNotification%22%2C%22params%22:%7B%22title%22:%22SmartThings%22%2C%22message%22:%22$smokeNameEncodedFinal%20$smokeStateEncoded%22%7D%2C%22id%22:1%7D", successClosure)
    }
    
if (evt.name == "water") {
	log.debug "Event - water"
	def waterName = "$water"
	def waterNameEncoded = "$waterName".encodeAsURL()
	def waterNameEncoded2 = "$waterNameEncoded".replaceAll(/%5B/,"")
	def waterNameEncodedFinal = "$waterNameEncoded2".replaceAll(/%5D/,"")
    def waterState = "$evt.value"
	def waterStateEncoded = "$waterState".encodeAsURL()
    log.debug "$waterNameEncodedFinal"
    httpGet("http://$Username:$Password@$IPAddress:$Port/jsonrpc?request=%7B%22jsonrpc%22:%222.0%22%2C%22method%22:%22GUI.ShowNotification%22%2C%22params%22:%7B%22title%22:%22SmartThings%22%2C%22message%22:%22$waterNameEncodedFinal%20$waterStateEncoded%22%7D%2C%22id%22:1%7D", successClosure)
    }
    

	def successClosure = { response ->
	  log.debug " Request was successful, $response"
	}
}
3 Likes