Unable to get TCP binding working correctly

I’m currently trying to make Openhab work with Hyperion lights and came across this post: Color item TCP binding

I followed the guidance in the thread there and tried to use the TCP binding to control the lights.
However nothing happens when openhab sends the command.
I can echo the same command I have in my rule to netcat and it turns the light on…

I can’t figure out why it’s not working as expected!

I’ve pretty much copied the commands exactly like the thread;

Rules;
rule “Set RGB value"
when
Item clHyperion received command
then
val HSBType hsb = receivedCommand as HSBType
val String json = String::format(”{“color”:[%1$d,%2$d,%3$d],“command”:“color”,“priority”:100}",hsb.red.intValue, hsb.green.intValue, hsb.blue.intValue)
logDebug(json)
clHyperion_Tcp.sendCommand(json)
end

Items;
String clHyperion_Tcp {tcp=">[192.168.1.8:19444]"}
Color clHyperion (Bedroom)

Anyone have any tips?

So I’ve done a bit more digging on this and the binding isn’t actually sending anything out…

I ran netcat on another box in listen mode, repointed the IP to that so that I could see what openhab sent when I set the light colour and nothing came through!

I’m using openhab2 at the moment but it was exactly the same using openhab 1.8 too.

Is there some dependency or special permission (using Ubuntu) to make the TCP binding work?

The openhab logs show that the light colour is set and the log prints the correct command that should be sent.

Still stuck with this :frowning2:

I’ve now got the TCP binding sending a string OK when attached to a switch, but the same binding configuration doesn’t do anything when attached to the string item (which i believe should be fired by the rule setting the string value)

Firstly, I noticed there was an error in the log when I edited my items file - the TCP binding seems to regex the item binding config looking for CMD:IP:PORT:TRANSFORM (it complains there should be at least 4 parameters) - but the example i’ve been using only has the IP:Port (see first post)
I’ve changed my TCP binding config to {tcp=">[ON:192.168.1.104:19444:‘0’]"}

When attached to the switch item this sends the string ON to 192.168.1.104 when the switch is turned on.
The same binding config on the clHyperion_TCP item does nothing when the rule fires… even though I see the following in the logs;

12:23:51.986 [INFO ] [marthome.event.ItemStateChangedEvent] - clHyperion_TCP changed from {“color”:[11,50,11],“command”:“color”,“priority”:100} to {“color”:[45,50,15],“command”:“color”,“priority”:100}

What am I missing here? - as far as I can tell I should be able to have tcp=">[192.168.1.104:19444]" as the binding config is it should use the string value for the command… either way, I’d have assumed copying the ‘ON’ binding from the switch would also send the string ‘ON’ whenever the color picker changed (just as a test!) - but clearly that doesn’t seem to be the case.

I think you would want * instead of ON in the binding config, meaning “when any command is received” instead of “only when the ON command is received.”

Also, please consider trying the 1.9.0-SNAPSHOT version of the TCP binding (linked below) to supply the word default in place of where you currently have '0'.

Many thanks watou, I now have it working after your suggestion and making a configuration change for the binding.
I had to disable the update item with response option in the TCP binding config.

Do you know how I can use the Up/Down arrows that appear either side of the color picker to switch the brightness? somehow map it to the slider that is below the color picker?

I have the following in my rule, but nothing happens (or is logged) when I press the Up/Down arrows - as a test I was hoping it would just disable the lights;

rule sendRGB
when
Item clHyperion received command
then
 if (receivedCommand instanceof HSBType) {
  val HSBType hsb = receivedCommand as HSBType
val String json = String::format("{\"color\":[%1$d,%2$d,%3$d],\"command\":\"color\",\"priority\":1}",hsb.red.intValue, hsb.green.intValue, hsb.blue.intValue)
  clHyperion_TCP.sendCommand(json)
 } else {
 val String json = String::format("{\"color\":[0,0,0],\"command\":\"color\",\"priority\":1}")
 clHyperion_TCP.sendCommand(json)
 }
end

Also, is it possible to make the lightbulb icon show if the light is on/off - currently it always shows on, regardless of the light state.

What happens if you add a

else if (receivedCommand instanceof PercentType) { ... }

section for brightness? Also, could you clarify if you tested the 1.9.0-SNAPSHOT version of the binding linked in the topic above? Thanks!

Hi watou,

Sorry I should have been clear, I am using the latest 1.9.0 JAR linked above.

I’ve added ;
import org.openhab.core.library.types.PercentType
to the rules file and modified else to;
} else if (receivedCommand instanceof PercentType) { val String json = String::format("{\"color\":[0,0,0],\"command\":\"color\",\"priority\":1}") clHyperion_TCP.sendCommand(json) } end

But I don’t see any action in the logs when clicking up/down - with the colour picker I can see the item received a command from the picker, then I see the command from the rule.
I assumed the ‘else’ (rather than else if) would just do a catch all, but even that doesn’t log any command received to the item.

It’s odd that you don’t see any commands when pressing the up/down buttons on your Color item. The Color widget ought to generate OnOff, IncreaseDecrease, Percent, and HSB type commands.

Yes, I assumed that would be the case.

I’m guessing there isn’t anything else I need to configure on the item side to get percent working too?

Currently I just have the following defined;

Color MyColorLEDs "Nightlight" <slider> (Lighting)

Not that I’m aware of. Items ought to work the same as they do under openHAB 1.x runtime. See the wiki for more information on item types and which commands and states they accept.

Hello, I have the same issue, but I am on OpenHAB 2.
I got so far that I do not get any errors in the log files, but hyperion does not react at all.
(hyperion app and command line do work)

I am using the same rule as in this topic and the line in the log look fine.

So it may be an issue of the item or binding configuration:

String 	hyperionDevice 	"Ambilight Device" 		<television>  					{tcp=">[*:192.168.178.77:19444:default]"}
Color 	hyperion_color	"Ambilight Color"		<television>	(gWohnzimmer)	

How does the tcp.cfg should look like?