Newbie - Simple (I think) SendHubAction to iTach Relay Device

I’m a very new user of SmartThings. I purchased an iTach Ethernet to 3-relay device that I thought would be a piece of cake to setup with SmartThings. It takes input over TCP on a specific port and then responds by closing or opening a contact closure. I can telnet to the port and paste in the very simple command “setstate,1:1,1” and it will set the state (1 or closed) of module 1, relay output 1 (1:1). To open it I simply change the state to 0 “setstate,1:1,0”. To pick another relay, you simply change the second number (1 to 3). “setstate,1:3,1” closes the contacts on relay 3.

What I want to do, is write a very simple (or 3 very simple for now) apps that I can command with Alexa. Each relay will be installed in parallel with a garage door switch. I want to be able to say “Alexa, Garage Door 1” and SmartThings will send a closure request (state 1), wait 500ms and then send an open request (state 0) to port 1:1. If I say “Alexa, Garage Door 2”, then…

This seems really easy in theory, and for now I’m thinking to get started I could create three apps, each controlled by a separate Alexa command (not really sure how to pass in the port argument via one app). Another nice option would be a “3-button remote” app that does the same thing using the same commands. I’m not sure how deep I have to go to make this happen. Started looking through the docs, but I must admit I’m a bit in over my head. Is this simple to do? Is there sample code I could reference that would be similar? The device is on my LAN using a static IP and port 4998.

If the devices are Lan-connected TCP, then there is no official support with SmartThings. For TCP, many have developed an always-on bridge running node.js with a HTTP link to SmartThings and TCP to the device.

Some have tried direct TCP comms, but few (if any) have succeeded.

Thanks Dave. That’s what I was gathering from the various threads, although it looked like some have succeeded using the “HubAction” method to accomplish it. I’ll keep digging/trying. I have an ISY994i on the network too and I think from there I may be able to do it. Thanks again!

Dave, one more question. Do you know if I can mess around with a simple code sample just using the HubAction or do I need a lot of other stuff around it (the “from form” option is adding a bunch of sections but I would like to just experiment with essentially running that one command to see if I can get it to work).

See code below for a Device Handler. It will have a single tile to press. You will need to install and add IP / Port for the unit under test then play with the hub action near the end to get a TCP stream.

> /*
>  */
> metadata {
> 	definition (name: "TP-Link Plug-Swich (XOR ver)", namespace: "V1.0", author: "Dave Gutheinz") {
> 		capability "Switch"
> 	}
> 	tiles {
> //-- Switch (on/off) Tile - off: white, on: blue, turning on/off: yellow, offine: red -----
> 		multiAttributeTile(name:"switch", type: "lighting", width: 6, height: 4, canChangeIcon: true){
> 			tileAttribute ("device.switch", key: "PRIMARY_CONTROL") {
> 				attributeState "on", label:'${name}', action:"switch.off", icon:"st.switches.light.on", backgroundColor:"#00a0dc", nextState:"off"
> 				attributeState "off", label:'${name}', action:"switch.on", icon:"st.switches.light.off", backgroundColor:"#ffffff", nextState:"on"
> 			}
> 	}
> 		main("switch")
> 		details(["switch"])
>     }
> }
> preferences {
> 	input("deviceIP", "text", title: "Device IP", required: true, displayDuringSetup: true)
> 	input("devicePort", "text", title: "Device Port", required: true, displayDuringSetup: true)
> }
> 
> def on() {
> //	TYPE YOUR COMMAND BELOW
> 	sendCmdtoServer('COMMAND YOU ARE SENDING', "response")
> }
> 
> //-- iF YOU GET A RESPONSE, YOU CAN USE THIS TO PARSE.---
> def response(response){
> 	log.debug response
> 	}
> }
> 
> //-- BELOW IS AN HTTP EXAMPLE.  THIS IS WHERE YOU PLAY.
> 
> private sendCmdtoServer(command, action){
> 	sendHubCommand(
> 		new physicalgraph.device.HubAction([
>         	body: encrCmd,
>         	headers: [
>             	HOST: "$deviceIP:devicePort",
 >         	]],
>  			device.deviceNetworkId,
> 			[callback: action]
> 		)
> 	)
> }

I’m glad you obviously know what you’re doing! :slight_smile: I think I’d spend all weekend getting to this point. Thanks again!