TCP&UDP Binding -

Running openHABian 1.5 on RaspberryPi 2.
I have a (semi-)domotica system at home, basically some relays with IP-adres and 24 exits to put some lights on/off. The relay listen so a simple telegram send with UDP-protocol.

I have TCP/UDP binding, Map transform binding installed. I also created an udp.cfg file with only “udp:updatewithresponse=true” and udp:port:1001 in it.

To send an ON/OFF command for a Switch item, I have the following configs (just some examples):

.items file:

Switch  GF_Berging_Licht  "Licht Berging"   <light> (Home, GF, GF_Berging) [ "Lighting" ] {udp=">[ON:10.10.1.20:1001:'MAP(GF_Berging_Licht.map)'] >[OFF:10.10.1.20:1001:'MAP(GF_Berging_Licht.map)']"}
Switch  GF_Terras_Licht  "Licht Terras"  <light> (Home, OUT, GF_Terras)  [ "Lighting" ]  {udp=">[ON:10.10.1.20:1001:'MAP(GF_Terras_Licht.map)'] >[OFF:10.10.1.20:1001:'MAP(GF_Terras_Licht.map)']"}
Switch  GF_Wasruimte_Licht "Licht Wasruimte" <light> (Home, GF, GF_Wasruimte) [ "Lighting" ] {udp=">[ON:10.10.1.20:1001:'MAP(GF_Wasruimte_Licht.map)'] >[OFF:10.10.1.20:1001:'MAP(GF_Wasruimte_Licht.map)']"} 

GF_Berging_Licht.map:

ON=S0000
OFF=C0000

As you can see, I have to send following telegram: Sxy00 to put the lights ON. Cxy00 to put the lights OFF where xy is the relais exit (00 till 23).

Now, I also have some dimmer relais, where I have to send following command to set the dimmer: S0bc1001, where bc is the DIM percentage.

I basically don’t know how to put the percentage value in the command tot send it to my relay.
Can someone get me started in this one please?

Thx!

Think I’d use a javascript transform to format the supplied number into 2? digits, and insert in output string.

That should also allow to intercept commands ON and OFF and convert to numeric

Thx for the reply @rossko57!
Is it perhaps possible to give some more details on this one? :wink:

Thank you!

example of a javascript that takes a number, well, a numeric string really, and produces a string output around it. Your need should be much simpler, but all the techniques you need are there.

1 Like

Thank you @rossko57!

I managed to do it like this:

Item file:

Dimmer  GF_Living_Zitplaats_Licht   "Zitplaats Licht"   <sofa>    (Home, GF, GF_Living)  [ "Lighting" ] { udp=">[*:10.10.1.22:1001:'JS(GF_Living_Zitplaats_Licht.js)']" }

Transform file “GF_Living_Zitplaats_Licht.js”: (according to the documentation I have to send 99 when 100 )

(function(i) {
	if(i==100)
		i=99;
	
	if(i<10)
		i="0"+i;
    var result="S3"+i+"1001";
    return result;
})(input)

Since I get an update from the relay for every string I send, I now get some warnings in the logs:

09:17:17.583 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'GF_Living_Zitplaats_Licht' received command 18
09:17:17.605 [INFO ] [smarthome.event.ItemStateChangedEvent] - GF_Living_Zitplaats_Licht changed from 32 to 18
09:17:18.015 [WARN ] [ding.tcp.protocol.internal.UDPBinding] - Cannot parse input I0142318 to match command * on item GF_Living_Zitplaats_Licht

It cannot parse the input “I0142318”: This is always the same string I get back, where the last two values match the dim percentage I send. I should match it to my item GF_Living_Zitplaats_Licht because there are other ways to set the lights (like actual switch).
So the first thing I suppose is to capture the string in an item and then parse is with some rule?

I created an item to capture the string:

String  Incoming_UDP     "Imcoming UDP[%s]"              { udp="<[10.10.1.22:*:'REGEX((.*))']" }

The problem is now that I can not seem to put the value received (I0142318) into the String item above.
Am I doing something wrong here?

Thx!

If it is trying to stuff this message into your original Item, I guess the binding is treating it as a response to your command, I don’t know.
It looks like you just need to configure a < binding on your original Item to capture it, then play with the inbound transform to isolate the numeric