Sending notifications via Pushing Box


(Jay) #1

I wanted to use PushingBox.com for getting notifications from ST. PB service supports sending notifications to Twitter, email and a whole bunch of push notifications apps for iOS and Android. I ended writing a quick ST app to support sending notifications using PB (based on the “Notify if” stock app) . Code is below.

Known issue: I need a way to URL encode user input.

preferences {
section(“Choose one or more, when…”){
input “motion”, “capability.motionSensor”, title: “Motion Here”, required: false, multiple: true
input “contact”, “capability.contactSensor”, title: “Contact Opens”, required: false, multiple: true
input “acceleration”, “capability.accelerationSensor”, title: “Acceleration Detected”, required: false, multiple: true
input “mySwitch”, “capability.switch”, title: “Switch Turned On”, 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
}
section(“Then send this message in a push notification”){
input “messageText”, “text”, title: “Message Text”
}
section(“Then enter PushingBox.com devid”){
input “devid”, “text”, title: “devid”
}

}

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)
}

def sendMessage(evt) {
log.debug " $evt.name: $evt.value, $messageText"

def successClosure = { response ->
  log.debug " Request was successful, $response"
}
httpGet("http://api.pushingbox.com/pushingbox?devid=$devid&title=Smart+Things&msg=$messageText", successClosure)

}


(Jay) #2

Apologies for the formatting issues in the code, I got bitten by the 1st post formatting bug. re-posting the code:

preferences {
	section("Choose one or more, when..."){
		input "motion", "capability.motionSensor", title: "Motion Here", required: false, multiple: true
		input "contact", "capability.contactSensor", title: "Contact Opens", required: false, multiple: true
		input "acceleration", "capability.accelerationSensor", title: "Acceleration Detected", required: false, multiple: true
		input "mySwitch", "capability.switch", title: "Switch Turned On", 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
	}
	section("Then send this message in a push notification"){
		input "messageText", "text", title: "Message Text"
	}
	section("Then enter PushingBox.com devid"){
		input "devid", "text", title: "devid"
	}

}

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)
}

def sendMessage(evt) {
	log.debug " $evt.name: $evt.value, $messageText"	

	def successClosure = { response ->
	  log.debug " Request was successful, $response"
	}
	
	/* to do: messageText need to be URL encoded */ 
	httpGet("http://api.pushingbox.com/pushingbox?devid=$devid&title=Smart+Things&msg=$messageText", successClosure)

}

(Michael Chunn) #3

Does anyone know if api.pushingbox.com is the only URL that is allowed in the httpGet/Post methods? I want to talk back to my own server but it gave me the error in the console log “error peer not authenticated”. I have no problems talking to the pushingbox server.