Integrating IP-based devices?


(Alexander Lash) #1

Just received the first installment of my SmartThings - having quite a bit of fun scaring my dogs with automatic lighting.

I have a small pile of devices I’d like to integrate and I’ve just ordered a few more. Unfortunately, I don’t have a ThingShield.

Let’s start with the simplest device of the bunch - the ThingM blink(1). It’s a USB-powered RGB LED. The API is documented here: https://github.com/todbot/blink1/blob/master/docs/app-url-api.md - there’s also a public HTTP (i.e. not local) queue that’s tied to your device ID, which is what I’d use for this. (It works kind of like the electric Imp legacy HTTP API…another device I want to integrate soon. :slight_smile:

How would I go about registering specific devices since it’s not ZigBee? I could maybe do this as a SmartApp, since it’s unidirectional, but I’d like to expose it as a generic switchlevel device so it could be integrated WITH other SmartApps.


(Dan Lieberman) #2

@alexanderlash - We’re working on the ability for the hub to act as a proxy between the SmartThings Platform and devices on the local LAN. The initial release will focus on SSDP-based discovery of devices, and HTTP and UPnP for data transport and device control.

If you’re going to use a public internet-accessible API, it is possible to write a Device-Type Handler that talks to the public web service and exposes it as a device that can be interacted with by SmartApps, though we’re not quite there yet for the general user to be able to install these non- Zigbee or Z-Wave devices using the mobile app - you have to do it from within the developer web-app today.

Unfortunately, our Device-Type Handler documentation is pretty incomplete at the moment, especially when it comes to integrating with external web services from within the Device-Type Handler. If you can point me at the documentation, I’ll see if I can whip up a quick example.

Thanks,
-d


(Alexander Lash) #3

@dlieberman - gotcha. In this case yes, it’s a public API (and I’m super excited about the local IP features. Don’t get me wrong. :slight_smile:

What set of documentation? The service I’m trying to integrate with? It’s defined by three key properties.

  1. URLs contain device identifier
  2. Header contains API secrets
  3. Request body contains JSON

…actually it’s really close to how the SmartThings API works. :slight_smile:

Given that I wasn’t missing something special to commission these devices, I think I can put together everything I need for this one (and some videos!) - thanks!

P.S. Really enjoying working with the IDE and App. Very polished.


(Dan Lieberman) #4

@alexanderlash

So here’s a super-simple one-way Device-Type Handler with the switch capability that can send an HTTP request to turn a device on and off by tapping the tile (or sending a command from a SmartApp).

First, create a new Device Type (My Device Types -> New SmartDevice), name your device type, select the Switch capability, and click create. When you’re done with it, select Publish -> For Me.

Then, you can add the device manually in the IDE (My Devices -> New Device), name your device, use the Device Network ID to input the unique device ID that identifies your specific device with the remote cloud service (see device.deviceNetworkID in the example), and select your custom device type from the Type dropdown.

Here’s the example code:

metadata {

	// tile definitions
	tiles {
		standardTile("switch", "device.switch", width: 2, height: 2, canChangeIcon: true) {
			state "on", label: '${name}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#79b821"
			state "off", label: '${name}', action: "switch.on", icon: "st.switches.switch.off", backgroundColor: "#ffffff"
		}

		main "switch"
		details "switch"
	}
}

def parse(String description) {
	log.error "This device does not support incoming events"
	return null
}

def on() {
	put 'on';
}

def off() {
	put 'off';
}

private put(action) {
	def apiKey = "[YOUR_API_KEY]"

	rest(
			method: 'PUT',
			headers: ["Authorization": "Bearer ${apiKey}"],
                        endpoint: "http://endpoint_base_url ",
			path: "/device/${device.deviceNetworkId}/${action}",
			
	)
}

(Bill) #5

@dlieberman - any idea when we might see local-IP support in the platform?


(Dan Lieberman) #6

@wc-smith - Our engineering team is actively working on it, but unfortunately I don’t have an update yet on when it will be generally available.


(Gschrader) #7

@dlieberman can we get another update on local network devices, this is really holding me up on my planned usage of the SmartThings platform.


(Andrew Urman) #8

@gschrader we’re about to begin a private beta for LAN connected devices. If you haven’t signed up yet, head on over to smartthings.com/betatest and put your info in there.


(Gschrader) #9

@urman thanks I have now signed up, though since I’m a Canuck I had to fake out my zip code :slight_smile: