KNXの視覚化サーバーbOSにはRPC (Remote Procedure Call protocol) という機能があり、外部からKNX機器を操作する場合にはこのAPIを使って操作することができます。
Comfortclick KNX視覚&自動化サーバー(bOSプラットフォーム)
設定は
1. ETSを使ってKNXデバイスの設定
2.bOSサーバーにETSデータをインポートして設定
3.RPCの設定
ここまで行い、あとはNode-REDから操作する方法を紹介します。
ETSを使ってKNXデバイスの設定
今回使用したKNXデバイスと制御は
ー スイッチアクチュエーターでLED_A(赤)とLED_B(緑)のOn/Off制御
ー ユニバーサルディマーを使ってLAMPを位相制御
です。
KNXのグループアドレスは上記の様に作成。
bOSサーバーにETSデータをインポートして設定
bOS側でKNXのデバイスはこのようにインポート。
bOSの操作画面はこのようにつくりました。
RPCの設定
次にbOS側でRPCの設定を行います。
General > API > RPCをクリック
Enableを True
Username : RPC
Password : RPC
とします。
Node-REDからの操作
Node-REDからはhttp requestノードをつかってPostで操作します。
事前に必要な情報を確認します。
RPC用のKNXデバイスのPath
RPCでKNXデバイスを操作するときは、infoからPathを確認します。
ランプ: Devices¥KNX¥LAMP
LEDA(赤) : Devices¥KNX¥LEDA
LEDB(緑) : Devices¥KNX¥LEDB
スペースや記号がある場合はなるべく文字列だけにします。
Node-REDのフロー
フローはこちらのとおり。
[{"id":"772812ab3a02b86b","type":"template","z":"de16c5a1c842773b","name":"LAMP","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\"objectName\":\"Devices\\\\KNX\\\\LAMP\",\"valueName\":\"Value\",\"value\":\"{{payload}}\"}\n","output":"str","x":330,"y":400,"wires":[["b281826c1e55fbc4"]]},{"id":"6c1be3dfb18f1cde","type":"debug","z":"de16c5a1c842773b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":670,"y":380,"wires":[]},{"id":"20530fc6e84e66c5","type":"inject","z":"de16c5a1c842773b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"100","payloadType":"num","x":150,"y":380,"wires":[["772812ab3a02b86b"]]},{"id":"b281826c1e55fbc4","type":"http request","z":"de16c5a1c842773b","name":"","method":"POST","ret":"txt","paytoqs":"ignore","url":"http://RPC:RPC@192.168.1.14/API/RPC/SetValue","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"credentials":{},"x":590,"y":280,"wires":[["6c1be3dfb18f1cde"]]},{"id":"07cfd35e0da7cdc9","type":"inject","z":"de16c5a1c842773b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":150,"y":460,"wires":[["772812ab3a02b86b"]]},{"id":"22fa4568b8555960","type":"inject","z":"de16c5a1c842773b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":150,"y":120,"wires":[["566b370c9db41410"]]},{"id":"566b370c9db41410","type":"template","z":"de16c5a1c842773b","name":"LEDA","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\"objectName\":\"Devices\\\\KNX\\\\LEDA\",\"valueName\":\"Value\",\"value\":\"{{payload}}\"}\n","output":"str","x":330,"y":140,"wires":[["b281826c1e55fbc4"]]},{"id":"6d98c7f9011cc55c","type":"inject","z":"de16c5a1c842773b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":150,"y":160,"wires":[["566b370c9db41410"]]},{"id":"15a311f2518515a7","type":"comment","z":"de16c5a1c842773b","name":"LEDA(赤)","info":"","x":140,"y":80,"wires":[]},{"id":"ee1d907d91fad7d9","type":"inject","z":"de16c5a1c842773b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":150,"y":260,"wires":[["0568c4a6dc3568e7"]]},{"id":"0568c4a6dc3568e7","type":"template","z":"de16c5a1c842773b","name":"LEDB","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\"objectName\":\"Devices\\\\KNX\\\\LEDB\",\"valueName\":\"Value\",\"value\":\"{{payload}}\"}\n","output":"str","x":330,"y":280,"wires":[["b281826c1e55fbc4"]]},{"id":"8e0f823c0526394e","type":"inject","z":"de16c5a1c842773b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":150,"y":300,"wires":[["0568c4a6dc3568e7"]]},{"id":"6f3f370b5bee61e9","type":"comment","z":"de16c5a1c842773b","name":"LEDB(緑)","info":"","x":140,"y":220,"wires":[]},{"id":"332011014a266c88","type":"comment","z":"de16c5a1c842773b","name":"LAMP","info":"","x":130,"y":340,"wires":[]},{"id":"6296f23826e601ae","type":"inject","z":"de16c5a1c842773b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"50","payloadType":"num","x":150,"y":420,"wires":[["772812ab3a02b86b"]]}]
Injectノードでは、LEDは1bitデータなのでtrueかfalse、LAMPは0〜100までの値をおくります。
Templateノードには先程のPathをいれます。
{"objectName":"Devices\\KNX\\LEDA","valueName":"Value","value":"{{payload}}"}
{"objectName":"Devices\\KNX\\LAMP","valueName":"Value","value":"{{payload}}"}
http requestには、POSTで
URLは
http://RPC:RPC@192.168.1.14/API/RPC/SetValue
このようにします。
ちなみに、bOSはオプションで外部からアクセスできるゲートウェイを利用することができるので、その場合は
192.168.1.14
ここをゲートウェイのURLにすることで、外のネットワークからもアクセスすることができます。
テスト
Node-RED側のInjectノードを押すことでKNXデバイスの操作がおこなわれ、
成功するとhttp requestのレスポンスとしてこのように戻ってきます。
また、操作結果はbOSのスマートフォンアプリに反映されています。
まとめ
以上、外部からbOSのRPC機能をつかってKNXデバイスを操作する方法を紹介しました。
次回はbOS側からAPIを叩いて外部機器を操作する方法をご紹介します。