Presence: call local URL on arrive and depart

Hi,

I’m looking at Smartthings to control some presence related activities at my place via the local LAN.
In order to do that I would need to call a local URL (e.g. http://10.10.10.30/light/on) when a specific presence sensor enters the Smartthings hub range and a separate local URL (e.g. http://10.10.10.30/light/off) once the presence sensor leaves the range of the hub.

So far I looked at the presence notification push/text apps which could be a good start I think.
However, how do I call the local URL on arrive and depart?

Can someone point me in the right direction?

Thanks !

That functionality has just recently been added to SmartThings. You can try to figure it out from the existing device handlers that use the LAN requests, or wait for the documentation, which should be coming soon.

For starters, you would have to create your own SmartApp, and you can use either one of those apps you mentioned as a starting point. Instead of sending the notification, you would simply make the LAN request.

Idefix:

You should be able to hack my code - I have it working to send http from the local hub to a PC on my LAN. Actually, you gave me the lead that got me there (thank you). See my last post in the thread titled “SmartThings Labs and LAN Devices” here in the Developer’s section.

Eric

Hi Eric,

I will have a detailed look at your code on the weekend.
Based on a quick look, it is much clearer now. I should be able to get this implemented.

Will post the code once ready.

Hi guys,

I have finally come around to adapt the code after upgrading my ST to the lab firmware.

I’m using the code to update switches on my Mi Casa Verde to toggle scenes based on the presence status of different persons.
In addition to switching the Vera devices (I use a virtual switch) ST will also send a notification to your phone once the person arrives or departs.

I hope this will help someone looking for a similar solution.

/**
 *  Presence Presence Update in Vera & Push Notification
 *
 *  Author: SmartThings, adapted by Idefix
 *
 *  use http://tuxgraphics.org/toolbox/network_address_calculator_add.html to convert your IP 
 *  (Convert dotted decimal IP-address or mask to binary and hex) and port (Convert decimal to binary and hex) to hex
 * 
 *  VeraID is the DeviceID of the switch you want to control. Look for it in the Device Advanced tab in Vera
 * 
 *  Device will be set to ON when presence is detected and OFF upon leaving
 *
 */

preferences {
	section("When a presence sensor arrives or departs this location..") {
		input "presence", "capability.presenceSensor", title: "Which sensor?"
	}
	section("Set Vera DeviceID...") {
		input "VeraID1", "number", title: "DeviceID"
	}
}

def installed() {
	subscribe(presence, "presence", presenceHandler)
}

def updated() {
	unsubscribe()
	subscribe(presence, "presence", presenceHandler)
   
}

def presenceHandler(evt) {
	
	def deviceNetworkId = "0A0A000A:D98"  //  "10.10.0.10:3480" update with your Vera IP in hex format
	def ip = "10.10.0.10:3480"            // This is the ip and port of the Vera in the network

	if (evt.value == "present") {
		log.debug "${presence.label ?: presence.name} has arrived at the ${location}"
    		
		sendHubCommand(new physicalgraph.device.HubAction("""GET /data_request?id=lu_action&DeviceNum=${VeraID1}&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1 HTTP/1.1\r\nHOST: $ip\r\n\r\n""", physicalgraph.device.Protocol.LAN, "${deviceNetworkId}"))

		sendPush("${presence.label ?: presence.name} has arrived at the ${location}")

	} else if (evt.value == "not present") {
		log.debug "${presence.label ?: presence.name} has left the ${location}"

		sendHubCommand(new physicalgraph.device.HubAction("""GET /data_request?id=lu_action&DeviceNum=${VeraID1}&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=0 HTTP/1.1\r\nHOST: $ip\r\n\r\n""", physicalgraph.device.Protocol.LAN, "${deviceNetworkId}"))

		sendPush("${presence.label ?: presence.name} has left the ${location}")
	}
}