KNX and Domoticz

THis flow will connect DOmoticz to the KNX bus. You can activate switches form virtual switch in domoticz to a Group Address in KNX you can activate a switch over the KNX bus and have DOmoticz reflect the state (upon event) you can use a KNX event to do somethin in domoticz

You need to configure as follow:

SET_PHYSICAL_ADDRESS node should configured with the source address (one availble from you IPTunnel.. see instruction of your IP interface)

KNX_TO_DOMOTICZ node should be configured with the reference between the KNX group and the DOmoticz Switch ID (see example in the node)

DPT5 -Blinds % and Venetian EU node is used for Datapoint type 5 (0..100% on a 255 basis) configure the references as per the example in the node

DPT1 - Switches and Others the same as above for Datapoint 1 (o/1, On Off etc etc)

all communications runs between KNX node and MQTT (over domoticz/in-out topics)

This is NOT perfect... status are not referenced periodically, but ONLY under event, but for Dmoticz is almost more than you can get :P

Hope you enjoy it!

[{"id":"a397f9dd.f08e78","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"bc92b0da.d2a11","type":"function","z":"a397f9dd.f08e78","name":"KNX to Domoticz","func":"\nvar dzMap = {\n    // Light\n    '0/1/0' : {\"topic\":\"knx2dz\", \"payload\":{\"command\": \"switchlight\", \"idx\": 1877, \"switchcmd\": setOnOff(parseInt(msg.payload.value),false) } },\n};\n\nif (msg.topic == 'knx:event') {\n    if (msg.payload.dstgad in dzMap) {\n        //node.warn(\"FOUND ==> \" + msg.payload.dstgad );\n        var dzTelegram = dzMap[msg.payload.dstgad];\n        return dzTelegram;\n    }\n}\n\nfunction setOnOff(curValue, invert) {\n    switch (curValue) {\n        case 0:\n            if (invert === false) {\n                return \"Off\"\n            } else {\n                return \"On\";\n            }\n            break;\n        case 1:\n            if (invert === false) {\n                return \"On\"\n            } else {\n                return \"Off\";\n            }\n            break;\n    }\n}\n","outputs":1,"noerr":0,"x":342,"y":152.98960876464844,"wires":[["6a90bdf1.225d14"]],"icon":"node-red/hash.png"},{"id":"5568a67d.4fb5f8","type":"switch","z":"a397f9dd.f08e78","name":"data type and exceptions","property":"payload.switchType","propertyType":"msg","rules":[{"t":"eq","v":"Blinds Percentage","vt":"str"},{"t":"eq","v":"Venetian Blinds EU","vt":"str"},{"t":"else"}],"checkall":"false","repair":true,"outputs":3,"x":476.74991607666016,"y":277.4896125793457,"wires":[["ff60d5a7.93bea8"],["ff60d5a7.93bea8"],["e5260eeb.98102"]],"inputLabels":["Tapparelle "]},{"id":"a2553e27.f1925","type":"switch","z":"a397f9dd.f08e78","name":"Debug Specific ID","property":"payload.idx","propertyType":"msg","rules":[{"t":"eq","v":"1875","vt":"num"},{"t":"else"}],"checkall":"false","repair":true,"outputs":2,"x":458.74993896484375,"y":320.48965549468994,"wires":[[],[]],"inputLabels":["Tapparelle "]},{"id":"ff60d5a7.93bea8","type":"function","z":"a397f9dd.f08e78","name":"DPT5 -Blinds % and Venetian EU","func":"/* MAP FUNCTION FOR KNX BLINDS PERCENTAGE FROM DOMOTICZ COMMAND VIRTUAL SWITCH\n\nFIELDS LIST:\ndzIDX : { UP-DN GROUP (1), STOP GROUP (1), LEVEL GROUP (5)\n*/\n\nvar knxTelegram = {};\nknxTelegram.topic = 'knx:write';\nknxTelegram.payload = {};\nknxTelegram.payload.srcphy = '1.1.2';\n\nvar map = {\n    1877 : { 'updn':'0/1/0', 'stop':'0/1/1', 'level':'1/1/1', \"invert\":false }           // Tapparella Cameretta\n};\n\nif (msg.payload.idx in map) {\n    switch (msg.payload.nvalue) {\n        case 17:             // Send SLAT/STOP Command\n            knxTelegram.payload.dstgad = map[msg.payload.idx].stop;\n            knxTelegram.payload.dpt = \"1\";\n            knxTelegram.payload.value = 0;\n            return  knxTelegram;\n\n        case 2:             //set LEVEL\n            knxTelegram.payload.dstgad = map[msg.payload.idx].level;\n            knxTelegram.payload.dpt = \"5\";\n            knxTelegram.payload.value = Math.round(parseInt(msg.payload.svalue1) * 2.55);\n            return  knxTelegram;\n            \n        case 1:             // Send FULL DOWN\n            knxTelegram.payload.dstgad = map[msg.payload.idx].updn;\n            knxTelegram.payload.dpt = \"1\";\n            if (map[msg.payload.idx].invert === true) {\n                knxTelegram.payload.value = 0;\n            } else {\n                knxTelegram.payload.value = 1;\n                \n            }\n            return knxTelegram;\n\n        case 0:             // Send FULL UP \n            knxTelegram.payload.dstgad = map[msg.payload.idx]['updn'];\n            knxTelegram.payload.dpt = \"1\";\n            if (map[msg.payload.idx]['invert'] === true) {\n                knxTelegram.payload.value = 1;\n            } else {\n                knxTelegram.payload.value = 0;\n                \n            }\n            return knxTelegram;\n    }\n}\nreturn ;","outputs":1,"noerr":0,"x":819.7499008178711,"y":267.4896717071533,"wires":[["4ab23155.5f48c"]]},{"id":"e5260eeb.98102","type":"function","z":"a397f9dd.f08e78","name":"DPT1 - Switches and Others","func":"var srcphy = flow.get('srcphy');\n\nvar map = {\n    1872 : {\"description\":\"Light\", \"knxTelegram\" : {\"topic\": \"knx:write\", \"payload\": {\"srcphy\" : srcphy, \"dpt\":\"DPT1\", \"dstgad\":\"0/0/1\", \"value\": dataPoints(msg.payload.nvalue, 1, false) } } },\n}\n\nif (msg.payload.idx in map) {\n    return map[msg.payload.idx].knxTelegram;\n}\n\nfunction dataPoints(valore, dpt, invert) {\n    switch(dpt) {\n        case 1:     // Datapoint 1 - 0..1 On/Off\n            if (invert === false) {\n                return valore;\n            } else {\n                return parseInt(1-valore);\n            }\n            break;\n        case 5:     // Datapoint 5 - 0..255 values must be converted from base10 to base255\n            return parseInt(valore * 2.55);\n    }\n}","outputs":1,"noerr":0,"x":799.749870300293,"y":306.48966217041016,"wires":[["4ab23155.5f48c"]],"icon":"node-red/hash.png"},{"id":"9f217f76.c918","type":"comment","z":"a397f9dd.f08e78","name":"From Domoticz to KNX","info":"","x":400.0172424316406,"y":227.00003814697266,"wires":[]},{"id":"ea41239a.293ac","type":"comment","z":"a397f9dd.f08e78","name":"Da KNX a Domoticz (per attuatori e cambio stati)","info":"","x":254.0172576904297,"y":111,"wires":[]},{"id":"b14ec127.810e8","type":"catch","z":"a397f9dd.f08e78","name":"","scope":null,"x":697.999870300293,"y":93.98958778381348,"wires":[["503a6e9e.94d15"]]},{"id":"503a6e9e.94d15","type":"debug","z":"a397f9dd.f08e78","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":708.9998779296875,"y":188.98963928222656,"wires":[]},{"id":"6a90bdf1.225d14","type":"mqtt out","z":"a397f9dd.f08e78","name":"","topic":"domoticz/in","qos":"","retain":"","broker":"5643db66.dd9264","x":524.0172729492188,"y":153.00000762939453,"wires":[]},{"id":"114bdfa6.9ed8","type":"mqtt in","z":"a397f9dd.f08e78","name":"","topic":"domoticz/out","qos":"2","broker":"5643db66.dd9264","x":135.01724243164062,"y":298.00002098083496,"wires":[["521ff84b.9014e8"]]},{"id":"521ff84b.9014e8","type":"json","z":"a397f9dd.f08e78","name":"","property":"payload","action":"obj","pretty":false,"x":277.6270179748535,"y":298.39581775665283,"wires":[["5568a67d.4fb5f8","a2553e27.f1925"]]},{"id":"cdfa15d8.981e28","type":"knx-in","z":"a397f9dd.f08e78","name":"KNX","controller":"","x":155.0762710571289,"y":187.42709159851074,"wires":[["bc92b0da.d2a11","503a6e9e.94d15"]]},{"id":"4ab23155.5f48c","type":"knx-out","z":"a397f9dd.f08e78","name":"KNX","controller":"","x":1042.0763244628906,"y":320.0416889190674,"wires":[]},{"id":"8eeec3e3.223aa","type":"function","z":"a397f9dd.f08e78","name":"set physical address","func":"flow.set('srcphy','1.1.2');\nreturn null;","outputs":1,"noerr":0,"x":363.0762939453125,"y":366.94793701171875,"wires":[[]]},{"id":"28d34245.f085be","type":"inject","z":"a397f9dd.f08e78","name":"","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":179.07281494140625,"y":362.94793701171875,"wires":[["8eeec3e3.223aa"]]},{"id":"5643db66.dd9264","type":"mqtt-broker","z":"","name":"","broker":"127.0.0.1","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

Flow Info

Created 6 years, 11 months ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • catch (x1)
  • comment (x2)
  • debug (x1)
  • function (x4)
  • inject (x1)
  • json (x1)
  • mqtt in (x1)
  • mqtt out (x1)
  • mqtt-broker (x1)
  • switch (x2)
Other
  • knx-in (x1)
  • knx-out (x1)
  • tab (x1)

Tags

  • KNX
  • DOMOTICZ
  • MQTT
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option