TCP Binding in OH2 and Items/Sitemap/Rules/Transforms Setup Help

Hey all,

I’m working on trying to control some devices with OpenHAB2 that can be addressed via telnet/tcp commands. I initially thought about writing my own binding but found that it was going to be too much work for devices that probably noone else would use. See here: https://community.openhab.org/t/bindings-to-send-telnet-commands-av-switcher-and-amx-netlinx-controllers/

So now i’m trying to work out the TCP binding, and am having some difficulty in getting it set up, due to my inexperience with OpenHAB and the lack of documentation available (I know its a work in progress).

Correct my if i’m wrong, but this is what I need to set up to get a binding working in OH2:

/etc/openhab2/services/tcp.cfg = tcp binding configuration file
/etc/openhab2/items/ = define items to control a device
/etc/openhab2/sitemaps/ = define the ‘controls’ that show up in OH, referencing the items that are setup
/etc/openhab2/rules/ = define rules that are used
/etc/openhab2/transform/ = define any mappings

Right?

So for the TCP binding, I need to have the config file set up, then set up an item that has the TCP command (with the syntax shown in the wiki, either in a map/transform or as a string), then reference that item in the site map (with the syntax shown in the wiki)?

Secondly, when the devices are issued a command, they respond with a string to say that the command was received and completed. There are also a number of error strings. How do I go about setting up the TCP binding to handle this? As far as I can figure out there is nothing native in the binding? The only way I thought about doing it was to have a rule that says when an item was switched on or off, to set the tcp binding to receive mode and then update the switch that was activated based on the response received?

How do I go about setting up the binding to check the status of the controls? I can send a status command to the device and it will respond with a code to say what status it is in for that control, do I set that up in a rule as well?

Then, in terms of the items.

For the switcher, I have 12x inputs and 8x outputs. I can go through and have 8 on/off switches for each input (input 1 -> output 1 on/off, input 1 > output 2 on/off etc), but i would end up with pages and pages of switches. Or I could have a multi value switch for each of the 8 outputs to say which input is going to it (ie output 1 is either input 1/2/3/4 etc). I can’t see any mention of a way to do multi value switch? The best way I can find to do this is to have items set up as a Number type for the inputs (1->12), and then in the sitemap have 8 switches for each output that has 12 values per switch? May need to have a map or rule so that it sends the right command?

Then I also have some volume sliders, and the command that sends a value from 1 to 64, so I would just use a rule/transform to convert the openhab dimmer type switch value to a 1 to 64 value and send that as a command?

Any help would be greatly appreciated! :slight_smile:

Cheers,

Alex

Correct. Those are the files/folders you need for end to end control and display.

I would bind the TCP connection to a String Item and a collection of one or more Proxy Items.

Text sent to the String Item get sent to the device. Text received from the device trigger a rule to process the acks and errors.

Use a Number Item and either a Selection or a Switch with Mappings on the sitemap.

Yes.

Alright cool, thanks for that :slight_smile: i’ll have a crack at it and see how I go.

Curious if you have any update on your project to use the TCP Binding to send/receive commands to AMX devices in OH2?

Im Running a AMX DAS Audio Amp/Matrix and ive used for a couple years “irule” to communicate with it via a TCP2Serial Gateway sending the various ASCII commands and listening for Replies and status updates.

I have been able to have the binding listen but i am unable to send it commands.

I have been able to get the binding to listen with this in the items folder:

ITEM
String AMX “AMX DAS [%s]” { tcp="<[10.100.100.31:2102:‘REGEX((.*))’]" }
String AMX_Status "AMX DAS Status [%s]"
Switch AMX_PWR "Master Power"
Number AMX_Z1_Input "Spare 1 Input"
Dimmer AMX_Z1_Volume "Spare 1 Volume [%03d %%]"
Switch AMX_Z1_Mute "Spare 1 Mute"
Number AMX_Z2_Input "Spare 2 Input"
Dimmer AMX_Z2_Volume "Spare 2 Volume [%03d %%]"
Switch AMX_Z2_Mute “Spare 2 Mute”

This is what the logs show, when i issue a command via irule and i see it updates the sitemap.
13:09:02.404 [INFO ] [marthome.event.ItemStateChangedEvent] - AMX changed from NULL to MVL5,51

SITEMAP
Text label=“Matrix” icon=“firstfloor” {
Text item=AMX
Text item=AMX_Status
Switch item=AMX_PWR
Selection item=AMX_Z1_Input mappings=[0=Off, 1=Input1, 2=Input2, 3=Input3]
Switch item=AMX_Z1_Mute
Slider item=AMX_Z1_Volume
}
Rules
import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
import java.util.regex.Matcher
import java.util.regex.Pattern

var Number volume_z1 = 0
var Number volume_z2 = 0

rule "AMX Power"
when
Item AMX_PWR received command
then
if(receivedCommand==ON){
sendCommand(AMX, “MSSC5,3;”)
logInfo(“AMX”, “Zone 5 Power ON”)
}
else if(receivedCommand==OFF){
sendCommand(AMX, “MSAO;”)
logInfo(“AMX”, “Power OFF”)
}
Thread::sleep(1000)
postUpdate(AMX_Status, AMX.state.toString.trim)
end