TCP Help

I have read over everything i can find about the TCP binding. I cant figure it out. Since Im running oh2, i know i have to make a tcp.cfg in the services folder. What goes in the file? what other steps need to be done?

I don’t use the TCP binding nor do I use the OH 2 yet but what I’m about to say should still be true.

You put the same information into the tcp.cfg as you would for OH1’s openhab.cfg file as documented in the Configuration Parameters section of the wiki page. As it says there, all these parameters are optional so you may not need to do anything at all. You may not need the tcp.cfg file at all unless you want to set any of the parameters from their defaults. The wiki page lists all the supported parameters that would go in the tcp.cfg file.

Then you need to define an Item and bind the Item to the TCP binding. The Generic Item Binding Config documents the format of that binding and there are two examples at the bottom.

First of all, I appreciate the help. The examples for items and some apps at the bottom of the binding configuration page are not there

Copy and paste from the wiki page:

tcp=">[ON:'MAP(')], >[OFF:'MAP(']" // for a Switch Item where values are converted using the
tcp="<['REGEX((.*))']" // for a String Item that captures some state of a remote device that connects to openHAB

A lot of these binding pages assumes you understand the basic concepts of openHAB. Per the Items wiki page you would create a Switch Item using the example above with:

Switch MyTCPSwitch "label" <icon> {tcp=">[ON:'MAP(')], >[OFF:'MAP(']"}

I recommend downloading the Demo and experimenting with it to learn some of the basics.

I do understand a bit of the basics, but openhab 2 act differently than
openhab one. I’m starting to understand more about this, but there is still
a learning curve considering I’ve never used the TCP binding

Thank you,

Branden Smale
Electrical Craftsmanship, Inc. (ECI)
(352) 494-4033

Ok, so this is what I have in my items file:

`// Groups

Group gAll "All Lights"
Group gLR “Living Room”

// Lamps

Dimmer LR_Lamp “Lamp” (gLR, gAll)[“homekit:DimmableLightbulb”]


Switch screenDown “Screen Down” [“homekit:Switch”] {tcp:=">[ON:‘MAP(’], >[OFF:‘MAP(’]"}
Switch screenUp “Screen Up” [“homekit:Switch”] {tcp:=">[ON:‘MAP(’], >[OFF:‘MAP(’]"}

And my sitemap file:

sitemap _default label=“Home”

Slider item=LR_Lamp
Switch item=screenDown
Switch item=screenUp

Map files of, and located in transform folder. Both have

tcp.conf located in services folder. Only thing in that file is

My switches dont show on the sitemap, nor can I control them via the homekit addon. I have a lamp that works fine with homekit, so I know this is not an issue. All help is appreciated.

Actually, let me recant…I should restart openhab and pull the logs first.

I don’t know if the syntax changed in OH2 for Items but the ["homekit:Switch"] part is invalid Item syntax for an OH 1 Item.

it works for a lamp i have (homekit:DimmableLightbulb)


so it was my doing, not restarting openhab…

next question though: do we have to use ON & OFF?

Id like to use UP & DOWN, but my current mapping defines an ascii to send over tcp. basically, i use the homekit for amazon echo. id like to say “alexa, screen down (up)”, instead of screen down on (up off). can i map multiple things in an item? basically map down or up to on or off, then on or off to the required ascii characters.

having a problem. logs say there is no channel that services my item.

That is what transforms are for. You can have a MAPPING transform that maps “UP” to “ON” and “DOWN” to “OFF” but a Switch can only be ON/OFF. But that raises a different problem. In order for that to make sense when you command it OH would really need to know what state the screen is in. For this you are probably best to use a String Item and a rule to look at what the State is and do the appropriate action based on the screen’s current state.

I can’t help with OH 2 specific problems.

i have mapped that, but the issue is can i use multiple maps for the same item, or like tou said, use a rule, in which case i could map down to on, then in the rule, send the ascii over tcp depending on which state its in. im going to have to use a rule anyways because i actually have to turn each relay on then off (momentary). if i set a variable to hold the state, does it save in memory to be called later?

ok, read up on strings a bit…so i could call down, then map that to the actual ascii i need to send. i take it i would have to define 2 items for down, 1 to close relay 1, which is 1 ascii code, another to open it back up, which is another ascii code. then use the rule to open relay 1 after a couple seconds after it has closed. But in the sitemap, only have a “down” button, not one to start, and one to stop…does this make sense?

If you declare it as a global (i.e. before your rules) it will stay in memory until OH restarts or you modify the rules file which will cause OH to reload it the variable will keep its state.

If you declare it inside a rule it only lives while the rule is executing.

Yes, this is often referred to as a proxy Item. A proxy Item is one that isn’t bound to anything that you put on your sitremap or send commands to which triggers a rule that does some extra processing such as transforming the command, checking flags to see whether it is allowed to trigger, or triggering lots of items.

If you are sending these strings to the same address and port, you can use a String Item and send the different ASCI text to the one Item.

thanks for your help, rich. i may have more questions, so please bear with me.

actually, i do have a question. is there a way to save the variable in a database, that way it can be called even if oh restarts? this device allows a call to it to check the relay state, but if im using it as a momentary, that does me no good.

kinda thinking at this point to just get an esp8266 and relay board for $15 and use mqtt. i cant get my current board to accept progrming to my network

This is what persistence is for. Set up persistence for your Items you want to be restored on startup by using the restoreOnStartup strategy.

But this does mean you have to put your value into an Item. You cannot persist vals or vars.

so i would create an item say named status rhat i only use for persistent data?