I managed to directly use the OpenHAB TCP/UDP binding: a couple of configurations need to be adjusted. The UDP payload packets are written in a remote.map file. Each binary byte is preceded by \u00: for example byte C6 is written as \u00C6.
I tested it on windows 7 64bit: when trying on different platforms, the behavior of the UDP binding has to be checked: the binary digits above 7F may be truncated (I found these informations in some posts of this forum, concerning the serial binding
https://groups.google.com/forum/m/#!topic/openhab/bX-j9DKvR_A ).
The following steps are therefore necessary
- Install the TCP/UDP binding by copying the addon file in the approriate directory of your installation
- modify the following TCP/UDP binding in openhab.cfg
udp:charset=ISO-8859-1
(that’s the setting that avoids the truncation of bytes above 7F)
udp:postamble=
(leave blank: the binding won’t add \u000D\u000F(i.e. LF+CR) at the end of the packet
- define a switch item in your .item file as follows
Switch AC_Zona_Notte “Zona Notte” <air_conditioner> (Appliance) {
udp=">[ON:192.168.27.34:80:‘MAP(blackbean1.map)’],>[OFF:192.168.27.34:80:‘MAP(blackbean1.map)’]"}
(replace the Ip number with the one of your blackbean)
- create a file blackbean1.map in the configurations\transform directory with the following content
ON:\u00a5\u00c6…
OFF:\u00a5\u00c6…
Where after the colon you have to write the UDP payload that you have intercepted with wireshark. This is a bit annoying but it has to be done once. I use wireshark to copy the payload as a hex stream, then paste it to packet sender (in order to test if the packet works). By copying from packet sender I obtain a sequence of hex bytes separated by spaces(i.e. A5 00 B6 etc). By using the replace function of the windows text editor I replace spaces with \u00 and adjust manually the string. Finally I copy it to the map file. It should remain in one single line, otherwise only the bytes before the line break are sent by the UDP binding.
-
add the switch item to your sitemap file
Switch item=AC_Zona_Notte icon=“air_conditioner”
-
restart openHAB. When pushing the button on the interface the corresponding UDP packet is sent.
Notes & limitations
a) for an air conditioner, the code for ON sends the whole configuration (temperature, fan speed, operating mode, etc). The code for OFF, even if it is operated by the same physical button, is different, therefore it needs to be intercepted. Rules need to implemented in order to properly operate the other remote buttons and I have not figured out, yet how to do that.
b) for my TV or my HiFi Amp, the code for ON & OFF is identical but the Mini only executes it once. You have therefore to intercept two times the ON/OFF packets with wireshark and create an entry in the map file for each intercepted code.
c) The ON/OFF remote button acts as a toggle: there is no way to know if the TV is on or off after the command is sent.
d) In order to debug the installation it is useful to have wireshark installed on the machine where openhab is installed, so that you can immediately figure out if the packet is correctly sent or not.
This is what I have found for now, I hope it will be useful for somebody else,
LionHe