Exec binding for UDP commands

Since there is no TCP/UDP binding anymore in openHAB 3, I’m thinking about replacing it by the exec binding. I don’t use the openHAB config that much, so I’m a bit rusty right now.

I have 2 different cases I need to handle.

  • Simple ON/OFF command :
Switch	Light_GF_Corridor_Ceiling	"Gang beneden"	(gGF,LightSwitches) [ "Lighting" ]	{ ga="Light", udp=">[ON:'MAP(my.corridor.map)'] >[OFF:'MAP(my.corridor.map)']", autoupdate="false" }

This map file is quite simple, just contains the value I need to send for a ON and OFF (includes a specific ID for the light I’m trying to control)

  • Dimmer control with percentage :
Dimmer	Light_GF_Dinner_Ceiling	"Eetplaats"	<slider> (gGF,LightDimmer) [ "Lighting" ] { ga="Light", udp=">[*:'JS(dinner.js)']", autoupdate="false" }

The javascript file is a to manipulate the actual value sent to the dimmer.

(function(i) {
		return "C3001000";
    var result="S3"+i+"1000";
    return result;

That’s basically what needs to be replaced. But I don’t know where to start. :slight_smile:
I’m still running OH2 at this moment. Will perform the upgrade to 3 when I’m ready with this change.
Can somebody give me a push in the right direction please?

Maybe try

Create Thing

Thing exec:command:udp_corridor [command="/etc/openhab/scripts/udp_corridor.bash %2$s",transform="MAP(my.corridor.map)", autorun=true]


Switch	Light_GF_Corridor_Ceiling	"Gang beneden"	(gGF,LightSwitches) [ "Lighting" ]	{ ga="Light", channel="exec:command:dp_corridor:run" }

udp_corridor.bash script

/usr/bin/echo $1 > /dev/udp/

all commands need to be whitelisted.

… The dimmer item can also have on off states

Thanks for the help! I’m currently getting the following error message when I try this (with a normal light).
An exception occurred while formatting the command line with the current time and input values : ‘Format specifier ‘%2$s’’

Indeed, with my current solution, the ON/OFF states don’t always work properly for my dimmers. So if I can fix that at the sime time, it would be nice.

See also

Does that one work in the same way as the “classic” tcp/udp binding? And is that an official supported binding?

Of course not, OH1 syntax not supported in OH3, so it will follow Things and channels model.

No, you would put your faith in @J-N-K

1 Like

:rofl: Nice. But there are other contributors to that repository. And it’s also available via the JSON 3rd Party Addon-Service introduced in openHAB 3.2.0, so no need to download files from Maven Central anymore.


Is there any place where I can find documentation? Or a GitHub page?

Thanks for the help. I did some digging into the system that I have at home. Turns out it has API functionality. So my best choice would be to move everything to the HTTP binding in OH3.
Now I just need to find the time :slight_smile: