Basically it’s nothing complicated, just paste the code in function nodes and connect them.
I made a basic flow here with a openhab-node in, function - homekit - function - openhab out.
The nodes have to be configured of course so you have to put an RGB-item on the in and out-node.
[
{
"id": "64bead44.4144c4",
"type": "function",
"z": "215cec59.1d50f4",
"name": "HSB2Homekit",
"func": "var results = msg.payload.split(',');\nif (results[2] < 1) {\n OnOff = false;\n} else {\n OnOff = true;\n}\nmsg.payload = {\n \"Brightness\": results[2],\n \"Hue\": results[0],\n \"Saturation\": results[1],\n \"On\": OnOff\n };\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 360,
"y": 140,
"wires": [
[
"b74e9a11.69c4f8"
]
]
},
{
"id": "7d241b5a.e66f94",
"type": "function",
"z": "215cec59.1d50f4",
"name": "HomeKit2HSB",
"func": "var h = context.get('h')||0;\nvar s = context.get('s')||0;\nvar b = context.get('b')||0;\n\nif(msg.payload.On === false){\n h = 0;\n context.set('h',h)\n s = 0;\n context.set('s',s)\n b = 0;\n context.set('b',b)\n}\nif(msg.payload.Hue){\n h = msg.payload.Hue;\n context.set('h',h)\n}\nif(msg.payload.Saturation){\n s = msg.payload.Saturation;\n context.set('s',s)\n}\nif(msg.payload.Brightness){\n b = msg.payload.Brightness;\n context.set('b',b)\n}\nmsg.payload = h+\",\"+s+\",\"+b;\nif (msg.hap.context !== undefined )\n{\nreturn msg;\n}",
"outputs": 1,
"noerr": 0,
"x": 740,
"y": 140,
"wires": [
[
"1acbeeaa.01d6d1"
]
]
},
{
"id": "eef9c664.019a38",
"type": "openhab2-in",
"z": "215cec59.1d50f4",
"name": "",
"controller": "",
"itemname": "",
"x": 140,
"y": 140,
"wires": [
[
"64bead44.4144c4"
],
[]
]
},
{
"id": "1acbeeaa.01d6d1",
"type": "openhab2-out",
"z": "215cec59.1d50f4",
"name": "",
"controller": "",
"itemname": "",
"topic": "",
"payload": "",
"x": 980,
"y": 140,
"wires": []
},
{
"id": "b74e9a11.69c4f8",
"type": "homekit-service",
"z": "215cec59.1d50f4",
"accessory": "",
"name": "",
"serviceName": "",
"x": 540,
"y": 140,
"wires": [
[
"7d241b5a.e66f94"
]
]
}
]
Try it out if it works!