XBMC Notifications

I meant can you send it via curl to the XBMC successfully?

Nope, I haven’t been able to. I’ve only been able to send it to XBMC through a web browser.

Try this:

curl -i -X POST -H "Content-Type: application/json" -d "{\"jsonrpc\": \"2.0\", \"method\": \"GUI.ShowNotification\", \"params\": {\"title\": \"Motion Detected\", \"message\": \"Front Door\"}, \"id\": 1}" http://My.WAN.IP.Address:8080/jsonrpc

Yup, that works perfect. The XBMC notification is displayed. Now how does the curl command get translated into something groovy friendly?

Thanks for all your help on this, I can see this coming in handy with both Plex & XBMC users that want on-screen notifications when something happens, and possibly down the road it can display live feeds like described in this post - http://homeawesomation.wordpress.com/2013/02/18/doorbell-ipcam-xbmc-update/

No clue as of yet, at least locally (still trying to figure that out). If you don’t mind opening a port on your router and going outside your LAN, there is a httpPostJson example in the docs.

You could also send this from HAM Bridge, triggered by a simple get request. Of course if you need to send live params and parse them HAM Bridge does not support that yet (and may never).

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

Hey nelemansc here is my xbmc/kodi notification app using sendHubCommand.

/**
 *  XBMC Notification
 *
 *  Copyright 2014 Richard
 *
 *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 *  in compliance with the License. You may obtain a copy of the License at:
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
 *  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
 *  for the specific language governing permissions and limitations under the License.
 *
 */
definition(
    name: "XBMC Notification",
    namespace: "",
    author: "Richard",
    description: "Sends status of smartthings Device to XBMC",
    category: "",
    iconUrl: "https://cdn2.iconfinder.com/data/icons/pack3-baco-flurry-icons-style/512/XBMC.png",
    iconX2Url: "https://cdn2.iconfinder.com/data/icons/pack3-baco-flurry-icons-style/512/XBMC.png")

import groovy.json.JsonBuilder


preferences {
	section("Choose one or more, when..."){
		input "motion", "capability.motionSensor", title: "Motion Here", required: false, multiple: true
		input "contactOpen", "capability.contactSensor", title: "Contact Opens", required: false, multiple: true
		input "contactClosed", "capability.contactSensor", title: "Contact Closes", required: false, multiple: true
		input "acceleration", "capability.accelerationSensor", title: "Acceleration Detected", required: false, multiple: true
		input "mySwitchOn", "capability.switch", title: "Switch Turned On", required: false, multiple: true
		input "mySwitchOff", "capability.switch", title: "Switch Turned Off", required: false, multiple: true
		input "arrivalPresence", "capability.presenceSensor", title: "Arrival Of", required: false, multiple: true
		input "departurePresence", "capability.presenceSensor", title: "Departure Of", required: false, multiple: true
		input "smoke", "capability.smokeDetector", title: "Smoke Detected", required: false, multiple: true
		input "water", "capability.waterSensor", title: "Water Sensor Wet", required: false, multiple: true
		input "locksLocked", "capability.lock", title: "Lock Locked?",  required: false, multiple:true
        input "locksUnlocked", "capability.lock", title: "Lock Unlock?",  required: false, multiple:true

        
	}
    
    section("Run when SmartThings is set to") {
		input "setMode", "mode", title: "Mode?",  required: false, multiple:true
	}
    
    section("XBMC Notifications LivingRoom:") {
    input "xbmcserver", "text", title: "XBMC IP", description: "IP Address", required: false
    input "xbmcport", "number", title: "XBMC Port", description: "Port", required: false
    }
    
    section("XBMC Notifications Bedroom:") {
    input "xbmcserver2", "text", title: "XBMC IP", description: "IP Address", required: false
    input "xbmcport2", "number", title: "XBMC Port", description: "Port", required: false
    }
    
}

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

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

def subscribeToEvents() {
	subscribe(contactOpen, "contact.open", eventHandler)
	subscribe(contactClosed, "contact.closed", eventHandler)
	subscribe(acceleration, "acceleration.active", eventHandler)
    subscribe(Noacceleration, "acceleration.inactive", eventHandler)
	subscribe(motion, "motion.active", eventHandler)
    subscribe(Nomotion, "motion.inactive", eventHandler)
	subscribe(mySwitchOn, "switch.on", eventHandler)
	subscribe(mySwitchOff, "switch.off", eventHandler)
	subscribe(arrivalPresence, "presence.present", eventHandler)
	subscribe(departurePresence, "presence.not present", eventHandler)
	subscribe(smoke, "smoke.detected", eventHandler)
	subscribe(smoke, "smoke.tested", eventHandler)
	subscribe(smoke, "carbonMonoxide.detected", eventHandler)
	subscribe(water, "water.wet", eventHandler)
    subscribe(locksLocked, "lock.locked", eventHandler)
    subscribe(locksUnlocked, "lock.unlocked", eventHandler)
    subscribe(location, modeChangeHandler)

}

def eventHandler(evt) {
	sendmessage(evt)
    sendmessage1(evt)

}

def sendmessage(evt) {
        def lanaddress = "${settings.xbmcserver}:${settings.xbmcport}"
        def deviceNetworkId = "1234"
        def toReplace = evt.displayName
		def replaced = toReplace.replaceAll(' ', '%20')
        def name = replaced
    	def value = evt.value
        def img = "http://static.squarespace.com/static/5129591ae4b0fd698ebf65c0/51384d05e4b079b8225cdf28/51384d06e4b000a8acbd05b5/1362644479952/smartthings.png"
        def json = new JsonBuilder()
        json.call("jsonrpc":"2.0","method":"GUI.ShowNotification","params":[title: "${name}",message: "${value}",image: "${img}"],"id":1)
        def xbmcmessage = "/jsonrpc?request="+json.toString()
        def result = new physicalgraph.device.HubAction("""GET $xbmcmessage HTTP/1.1\r\nHOST: $lanaddress\r\n\r\n""", physicalgraph.device.Protocol.LAN, "${deviceNetworkId}")
        sendHubCommand(result)
}

def sendmessage1(evt) {
        def lanaddress = "${settings.xbmcserver2}:${settings.xbmcport2}"
        def deviceNetworkId = "1234"
        def toReplace = evt.displayName
		def replaced = toReplace.replaceAll(' ', '%20')
        def name = replaced
        def value = evt.value
        def img = "http://static.squarespace.com/static/5129591ae4b0fd698ebf65c0/51384d05e4b079b8225cdf28/51384d06e4b000a8acbd05b5/1362644479952/smartthings.png"
        def json = new JsonBuilder()
        json.call("jsonrpc":"2.0","method":"GUI.ShowNotification","params":[title: "${name}",message: "${value}",image: "${img}"],"id":1)
        def xbmcmessage = "/jsonrpc?request="+json.toString()
        def result = new physicalgraph.device.HubAction("""GET $xbmcmessage HTTP/1.1\r\nHOST: $lanaddress\r\n\r\n""", physicalgraph.device.Protocol.LAN, "${deviceNetworkId}")
        sendHubCommand(result)

}
def modeChangeHandler(evt) {
	sendmessage3(evt)
    sendmessage4(evt)

}

def sendmessage3(evt) {
        def lanaddress = "${settings.xbmcserver}:${settings.xbmcport}"
        def deviceNetworkId = "1234"
        def mode = evt.value
        def msg = "Mode%20Activated"
        def img = "http://static.squarespace.com/static/5129591ae4b0fd698ebf65c0/51384d05e4b079b8225cdf28/51384d06e4b000a8acbd05b5/1362644479952/smartthings.png"
        def json = new JsonBuilder()
        json.call("jsonrpc":"2.0","method":"GUI.ShowNotification","params":[title: "${mode}",message: "${msg}",image: "${img}"],"id":1)
        def xbmcmessage = "/jsonrpc?request="+json.toString()
        def result = new physicalgraph.device.HubAction("""GET $xbmcmessage HTTP/1.1\r\nHOST: $lanaddress\r\n\r\n""", physicalgraph.device.Protocol.LAN, "${deviceNetworkId}")
        sendHubCommand(result)
}

def sendmessage4(evt) {
        def lanaddress = "${settings.xbmcserver2}:${settings.xbmcport2}"
        def deviceNetworkId = "1234"
        def mode = evt.value
        def msg = "Mode%20Activated"
        def img = "http://static.squarespace.com/static/5129591ae4b0fd698ebf65c0/51384d05e4b079b8225cdf28/51384d06e4b000a8acbd05b5/1362644479952/smartthings.png"
        def json = new JsonBuilder()
        json.call("jsonrpc":"2.0","method":"GUI.ShowNotification","params":[title: "${mode}",message: "${msg}",image: "${img}"],"id":1)
        def xbmcmessage = "/jsonrpc?request="+json.toString()
        def result = new physicalgraph.device.HubAction("""GET $xbmcmessage HTTP/1.1\r\nHOST: $lanaddress\r\n\r\n""", physicalgraph.device.Protocol.LAN, "${deviceNetworkId}")
        sendHubCommand(result)
        
}
4 Likes

@rog Wow, this is awesome! Ability to send the notification to multiple XBMC instances, sendHubCommand, and the SmartThings image on top of it all. You win, lol. Thanks a lot for sharing!

Hey nelemansc, glad i could share the code with you. I made some small changes so you can get the latest version on my here. If you have an IP camera you can also check my smartapp that runs a security camera addon when motion is detected.

1 Like

I used both XBMC notifier and the KODI notifier with multiple rooms.Unfortunately no event showed up in my kodi instance!
Any ideas?I also opened the web server port with port forwarding to my router but nothing changed.

If you have any solution please reply!

Are you using my version from github? if so you don’t need to use your external ip/port forwarding. Just use the local ip and port setup of the machine running Kodi.

I am using yours.I had username and password on all kodi installations.I removed them but still nothing.Any ideas?

I found it.It was actually the firewall!Problem solved.Now I want to see if it works with enabled username and password.

I got the code to work as well, thanks! Works on all 4 TVs, Fire TVs and Raspberry Pi running XBMC and Kodi.
I was going to look into how I could do some type of text to speech but now I can select important notifications to actually STOP my video and with a pause, speak a notification. Read about that here RELEASE Generic Media Renderer (DLNA Speakers). Cheap Sonos Alternative (Update V2)

Thanks for pointing out that thread Chuck, TTS is the last part of my Home Automation setup.

What version of Kodi are you using, is that a skin and what are you using for the tv guide?

i am using openelec which is based on Kodi 14. The skin in the pic above is 1080xf.mb3, let me know if you need more info.

Edit

Forgot to mention that am using serverwmc as my pvr backend.

I’m not sure I understand, I’m a bit lost :frowning:
So you copy and past the script on a new smartapps, then publishing
But what do you have to do from the Kodi side?

All you have to do is enable Kodi’s webserver and make sure the settings in the smartapp match the IP and webserver port of the kodi machine .

Maybe this already does this and I have to wait until I get home to test it out anyhow…but is there a way to add functionality for other events? I have a notification when someone knocks on my front door. Would be very cool to have that pop up and let me know on the screen in Kodi in case its too loud or the knock isn’t loud enough…even cooler if I could get Kodi to mute in such cases.