Event Handler to Receive Command from a Mac?

Hey All,

Brand spankin’ new here. I have a need to send a command/string from a home automation server (a Mac) to the hub where I can intercept it as an event and handle it based on what is in the string. Basically the Mac needs to be able to control some of the devices connected to the hub.

While I see how I can talk to the Mac from the Hub via http, I can’t find a method for going the other way. Is this possible?

2 Likes

Wow. After playing with the IDE a bit, it seems there is no way to communicate directly via http to a server on my LAN. It appears everything has to go out to the internet via some kind of SmartThings proxy.

Unfortunately, this is a deal breaker for me.

Supposedly they were working on LAN communication… haven’t heard anything on it for a few months. SONOS does some kind of LAN communication (UPNP I think).

Anyone have any updates?

Well, there’s a section in the docs for building LAN based devices (that supposedly support REST), but I am afraid that without any real world examples, I am at a loss to just how to go about it.

Short of this I am really digging ST, so perhaps someone here who really knows what they’re doing can show us how to setup a local device.

I have built a LAN based app that reaches out to a REST service on my local network, but I don’t know if there is an ability to have an external app talk to the SmartThing hub if that is what you are trying to do.

If you need an example of a SmartThing app -> external REST, I can help. If you need external app to SmartThing, not so much.

PM if you would like details.

PM has been sent… thanks.

Philips Hue, Belkin WeMo, and Sonos are all LAN devices. Are they available as examples on the SmartApps and Device Type pages in the IDE?

If not I can make sure they are put there as examples.

Also http://docs.smartthings.com/en/latest/cloud-and-lan-connected-device-types-developers-guide/index.html

Thanks Andrew,

There are indeed examples for the devices you mention, but I am not much of a java head so they weren’t all that help (mostly overkill I imagine).

But now that I have a modicum of experience (and have had the hardware for a couple of days), I’d like to revisit this. With an example from @bmayer01 I have half of it working very well (sending http requests to a local server)…

def sendHttp() {
def ip = "${settings.server}:8080"
def deviceNetworkId = "100012"
sendHubCommand(new physicalgraph.device.HubAction("""GET /?${settings.command} HTTP/1.1\r\nHOST: $ip\r\n\r\n""", physicalgraph.device.Protocol.LAN, "${deviceNetworkId}"))
}

So now all that’s left is being able to send commands from the server to the hub. I don’t even know if I need a device-type for that either. I discovered I could use the Endpoint Access Authorization to directly control switches and locks connected to the hub, but that is a far cry from being able to simply send a command locally to the hub, and parse its params within a single handler to decide what to do. This is what I am after. I don’t know if I can do anything more with endpoints as it seems any link I have been able to dig up regarding a tutorial leads to a 404, but it was here once upon a time.

The pieces and bits I have looked at regarding a device-type seem to invoke some kind of discovery process using upnp. If I was going to have to discover my server I’d need multicast (which the current docs say is not implemented yet). But I know the IP address of my server so I wouldn’t think any discovery is necessary.

Another thing I take away from the Lan device-type section is that local communication to the hub seems to only be supported in the way of a response to a hub originated command via registering for a callback. I have no need for this. I simply need to send a dumb event with a param or two to the hub from a Mac.

I wanted to touch on one more thing while you are being kind enough to shine a light on some of this… and that is the code snippet above:

Is sendHubCommand capable of sending a simple string via tcp to a similar local host? For example:

sendir,1:3,1,36000,3,1,128,63,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,48,16,48,16,48,16,48,16,16,16,16,16,48,16,48,16,48,16,48,16,48,16,48,16,16,16,48,16,2712\r

The above is an example of a CG iTach IR command/code. Currently I am sending these codes from my server using python with something like this:

import socket
HOST2 = '10.0.0.41'
PORT2 = 4998
s = socket.socket( socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST2, PORT2))
s.sendall("sendir,1:3,1,39000,3,1,95,23,48,23,48,23,48,23,48,23,23,23,48,23,23,23,23,23,48,23,23,23,48,23,48,23,23,23,48,23,23,23,23,23,23,23,48,23,48,23,48,512\r")
response = s.recv(24)
print "Response from send(SonyBR Off):", response

Note that the response is not necessary; it was just left in from when I started putting this stuff together.

So this is all that I am struggling with… everything else has gone “reasonably” well since I learned you don’t use “string” to define input types. (c;

Thanks for looking it over,

Scott in Pollock

2 Likes

Sorry to bump my own post but I am still looking hard for answers to this. If I can find a way to get HAM Bridge to talk to SmartThings locally, with a bit more granularity than oAuth Endpoints, I would then be able to die a happy man.

I’ll bump as well. In my case I’d like to be able to send data from my Vera to SmartThings. I’ve got the opposite direction working just fine…

Endpoints works well for me… I have pretty good reliability using LAN calls to my SmartThings Hub (and back to my server) for my DSC Alarm Integration. If you pair those calls with JSON objects it saves a lot of traffic and becomes a parsing issue.

What’s holding you up on the endpoints side that makes it an issue?