NRCHKB / node-red-contrib-homekit-bridged

Node-RED Contribution - HomeKit Bridged : Node-RED nodes to simulate Apple HomeKit devices.
https://nrchkb.github.io
MIT License
412 stars 52 forks source link

[Help needed]: Advanced Garage door setup #478

Closed S474N closed 2 years ago

S474N commented 2 years ago

Your Current NRCHKB Plugin Version

1.4.3

Operating System

Raspbian 11 64bit, Docker

How can we help?

Have problem with Advanced Garage door setup

https://github.com/NRCHKB/node-red-contrib-homekit-bridged/wiki/Garage-Door

Door opening works perfectly, but have problem with closing. Everytime swich to "Opening" state.

I think, that "problem" will be with two MQTT nodes on the bottom left.

Who make this flow, please?

Any more details?

Shelly Plus 1 as relay with payload: command = {"payload":{"id": "0", "on": true}};

2x Aqara magnetic sensors with this logic: image

Any code or functions to add?

No response

S474N commented 2 years ago

@ptath you are author?

ptath commented 2 years ago

@ptath you are author?

my hardware setup changed, here is current one (works perfect)

[{"id":"4e08edee7b3383a8","type":"inject","z":"409a237dd343c40d","name":"на старте","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":"10","topic":"","payloadType":"date","x":100,"y":30,"wires":[["7b9bbdcfe683f7b4"]]},{"id":"2c7d6ccb1b765406","type":"wirenboard-in","z":"409a237dd343c40d","name":"","server":"81b53158.d4af98","channel":["/devices/wb-gpio/controls/EXT1_IN13","/devices/wb-gpio/controls/EXT1_IN14"],"outputAtStartup":true,"x":90,"y":90,"wires":[["49e4742512307458","c151393317a1b024"]]},{"id":"49e4742512307458","type":"function","z":"409a237dd343c40d","name":"обработка","func":"var newMsg, newpayload = {};\nvar gate = global.get(\"gate\");\n\n// ворота открыты полностью\nif ( (msg.payload[\"/devices/wb-gpio/controls/EXT1_IN13\"] == \"1\") && \n        (msg.payload[\"/devices/wb-gpio/controls/EXT1_IN14\"] == \"0\") ) {\n            gate.CurrentDoorState = 0;\n            gate.TargetDoorState = 0;\n            gate.CurrentPosition = 100;\n            gate.TargetPosition = 100;\n            global.set(\"gate\", gate);\n            return [{ \"payload\": { \"CurrentDoorState\": 0, \"TargetDoorState\": 0 } }, null];\n        }\n\n// ворота закрыты полностью\nif ((msg.payload[\"/devices/wb-gpio/controls/EXT1_IN13\"] == \"0\") &&\n        (msg.payload[\"/devices/wb-gpio/controls/EXT1_IN14\"] == \"1\")) {\n            gate.CurrentDoorState = 1;\n            gate.TargetDoorState = 1;\n            gate.CurrentPosition = 0;\n            gate.TargetPosition = 0;\n            global.set(\"gate\", gate);\n            return [{ \"payload\": { \"CurrentDoorState\": 1, \"TargetDoorState\": 1 } }, null];\n}\n\n// ворота поехали\nif ((msg.payload[\"/devices/wb-gpio/controls/EXT1_IN13\"] == \"1\") &&\n    (msg.payload[\"/devices/wb-gpio/controls/EXT1_IN14\"] == \"1\")) {\n        // если ворота были закрыты\n        if ( gate.CurrentDoorState == 1 ) {\n            gate.CurrentDoorState = 2;\n            gate.TargetDoorState = 0;\n            gate.CurrentPosition = 100;\n            gate.TargetPosition = 100;\n            global.set(\"gate\", gate);\n            return [{ \"payload\": { \"CurrentDoorState\": 2, \"TargetDoorState\": 0 } }, null];\n        }\n        // если ворота были открыты\n        if (gate.CurrentDoorState == 0 ) {\n            gate.CurrentDoorState = 3;\n            gate.TargetDoorState = 1;\n            gate.CurrentPosition = 100;\n            gate.TargetPosition = 100;\n            global.set(\"gate\", gate);\n            return [{ \"payload\": { \"CurrentDoorState\": 3, \"TargetDoorState\": 1 } }, null];\n        }\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":240,"y":90,"wires":[["f4e5c61096524d13"]]},{"id":"7b9bbdcfe683f7b4","type":"wirenboard-get","z":"409a237dd343c40d","name":"","server":"81b53158.d4af98","channel":["/devices/wb-gpio/controls/EXT1_IN13","/devices/wb-gpio/controls/EXT1_IN14"],"x":280,"y":30,"wires":[["2df81db21c14fc4d"]]},{"id":"2df81db21c14fc4d","type":"function","z":"409a237dd343c40d","name":"начальное состояние","func":"var newMsg, newpayload = {};\nvar gate = {};\n\n// ворота открыты полностью\nif ((msg.payload[\"/devices/wb-gpio/controls/EXT1_IN13\"] == \"1\") &&\n    (msg.payload[\"/devices/wb-gpio/controls/EXT1_IN14\"] == \"0\")) {\n    gate.CurrentDoorState = 0;\n    gate.TargetDoorState = 0;\n    gate.CurrentPosition = 100;\n    gate.TargetPosition = 100;\n    global.set(\"gate\", gate);\n    return [{ \"payload\": { \"CurrentDoorState\": 0, \"TargetDoorState\": 0 } }, { \"payload\": { \"CurrentPosition\": 100, \"TargetPosition\": 100 } }];\n}\n\n// ворота закрыты полностью\nif ((msg.payload[\"/devices/wb-gpio/controls/EXT1_IN13\"] == \"0\") &&\n    (msg.payload[\"/devices/wb-gpio/controls/EXT1_IN14\"] == \"1\")) {\n    gate.CurrentDoorState = 1;\n    gate.TargetDoorState = 1;\n    gate.CurrentPosition = 0;\n    gate.TargetPosition = 0;\n    global.set(\"gate\", gate);\n    return [{ \"payload\": { \"CurrentDoorState\": 1, \"TargetDoorState\": 1 } }, { \"payload\": { \"CurrentPosition\": 0, \"TargetPosition\": 0 } }];\n}\n\n// ворота в промежуточном состоянии\nif ((msg.payload[\"/devices/wb-gpio/controls/EXT1_IN13\"] == \"1\") &&\n    (msg.payload[\"/devices/wb-gpio/controls/EXT1_IN14\"] == \"1\")) {\n    gate.CurrentDoorState = 0;\n    gate.TargetDoorState = 0;\n    gate.CurrentPosition = 50;\n    gate.TargetPosition = 50;\n    global.set(\"gate\", gate);\n    return [{ \"payload\": { \"CurrentDoorState\": 4, \"TargetDoorState\": 0 } }, { \"payload\": { \"CurrentPosition\": 50, \"TargetPosition\": 50 } }];\n}\n","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":470,"y":30,"wires":[["f4e5c61096524d13"],["a74ee893abac558c"]]},{"id":"f4e5c61096524d13","type":"homekit-service","z":"409a237dd343c40d","isParent":true,"hostType":"0","bridge":"23481131.939986","accessoryId":"","parentService":"","name":"Ворота","serviceName":"GarageDoorOpener","topic":"","filter":false,"manufacturer":"Alutech","model":"RTO1000","serialNo":"0001","firmwareRev":"1.0","hardwareRev":"1.0","softwareRev":"1.0","cameraConfigVideoProcessor":"ffmpeg","cameraConfigSource":"","cameraConfigStillImageSource":"","cameraConfigMaxStreams":2,"cameraConfigMaxWidth":1280,"cameraConfigMaxHeight":720,"cameraConfigMaxFPS":10,"cameraConfigMaxBitrate":300,"cameraConfigVideoCodec":"libx264","cameraConfigAudioCodec":"libfdk_aac","cameraConfigAudio":false,"cameraConfigPacketSize":1316,"cameraConfigVerticalFlip":false,"cameraConfigHorizontalFlip":false,"cameraConfigMapVideo":"0:0","cameraConfigMapAudio":"0:1","cameraConfigVideoFilter":"scale=1280:720","cameraConfigAdditionalCommandLine":"-tune zerolatency","cameraConfigDebug":false,"cameraConfigSnapshotOutput":"disabled","cameraConfigInterfaceName":"","characteristicProperties":"{}","waitForSetupMsg":false,"outputs":2,"x":390,"y":90,"wires":[["9a1ed7edb7c72e9c"],[]]},{"id":"9a1ed7edb7c72e9c","type":"function","z":"409a237dd343c40d","name":"управление","func":"if (msg.hap.session) {\n\n    // команда на открытие\n    if (msg.payload.TargetDoorState == 0) {\n        return [{ \"payload\": 1 }, null];\n    }\n\n    // команда на закрытие\n    if (msg.payload.TargetDoorState == 1) {\n        return [null, { \"payload\": 1 }];\n    }\n\n}","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":540,"y":90,"wires":[["bb2087bdf79c037d"],["f1e92df484b3ef86"]]},{"id":"bb2087bdf79c037d","type":"trigger","z":"409a237dd343c40d","name":"","op1":"1","op2":"0","op1type":"num","op2type":"num","duration":"500","extend":false,"overrideDelay":false,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":710,"y":70,"wires":[["6ca669204547ab8f"]]},{"id":"f1e92df484b3ef86","type":"trigger","z":"409a237dd343c40d","name":"","op1":"1","op2":"0","op1type":"num","op2type":"num","duration":"500","extend":false,"overrideDelay":false,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":710,"y":110,"wires":[["52346719194cad8a"]]},{"id":"52346719194cad8a","type":"wirenboard-out","z":"409a237dd343c40d","name":"закрыть ворота","server":"81b53158.d4af98","channel":["/devices/wb-gpio/controls/EXT2_K2"],"command":"/on","commandType":"wb_cmd","payload":"payload","payloadType":"msg","rbe":false,"x":910,"y":110,"wires":[]},{"id":"6ca669204547ab8f","type":"wirenboard-out","z":"409a237dd343c40d","name":"открыть ворота","server":"81b53158.d4af98","channel":["/devices/wb-gpio/controls/EXT2_K1"],"command":"/on","commandType":"wb_cmd","payload":"payload","payloadType":"msg","rbe":false,"x":910,"y":70,"wires":[]},{"id":"81b53158.d4af98","type":"wirenboard-server","name":"WB6","host":"192.168.2.2","mqtt_port":"1883","mqtt_username":"","mqtt_password":""},{"id":"23481131.939986","type":"homekit-bridge","bridgeName":"CASTLE","pinCode":"111-11-111","port":"","advertiser":"bonjour-hap","allowInsecureRequest":false,"manufacturer":"NRCHKB","model":"1.3.6","serialNo":"000001","firmwareRev":"1.3.6","hardwareRev":"1.3.6","softwareRev":"1.3.6","customMdnsConfig":false,"mdnsMulticast":true,"mdnsInterface":"","mdnsPort":"","mdnsIp":"","mdnsTtl":"","mdnsLoopback":true,"mdnsReuseAddr":true,"allowMessagePassthrough":true}]

2x Aqara magnetic sensors

btw

156721073-f81a20a3-509a-437e-8d26-8ee7192479ee

S474N commented 2 years ago

@ptath : so I don't have wireboard HW, can you show me msg.payloads from them?

So there must be also two magnetic sensors, right? I have sensors on wall, not on door.

ptath commented 2 years ago

example WB payload

{"/devices/wb-gpio/controls/EXT1_IN13":"0","/devices/wb-gpio/controls/EXT1_IN14":"1"}

// completely opened
if ((msg.payload["/devices/wb-gpio/controls/EXT1_IN13"] == "1") &&
    (msg.payload["/devices/wb-gpio/controls/EXT1_IN14"] == "0")) {
    gate.CurrentDoorState = 0;
    gate.TargetDoorState = 0;
    gate.CurrentPosition = 100;
    gate.TargetPosition = 100;
    global.set("gate", gate);
    return [{ "payload": { "CurrentDoorState": 0, "TargetDoorState": 0 } }, { "payload": { "CurrentPosition": 100, "TargetPosition": 100 } }];
}

// completely closed
if ((msg.payload["/devices/wb-gpio/controls/EXT1_IN13"] == "0") &&
    (msg.payload["/devices/wb-gpio/controls/EXT1_IN14"] == "1")) {
    gate.CurrentDoorState = 1;
    gate.TargetDoorState = 1;
    gate.CurrentPosition = 0;
    gate.TargetPosition = 0;
    global.set("gate", gate);
    return [{ "payload": { "CurrentDoorState": 1, "TargetDoorState": 1 } }, { "payload": { "CurrentPosition": 0, "TargetPosition": 0 } }];
}

// not opened nor closed
if ((msg.payload["/devices/wb-gpio/controls/EXT1_IN13"] == "1") &&
    (msg.payload["/devices/wb-gpio/controls/EXT1_IN14"] == "1")) {
    gate.CurrentDoorState = 0;
    gate.TargetDoorState = 0;
    gate.CurrentPosition = 50;
    gate.TargetPosition = 50;
    global.set("gate", gate);
    return [{ "payload": { "CurrentDoorState": 4, "TargetDoorState": 0 } }, { "payload": { "CurrentPosition": 50, "TargetPosition": 50 } }];
}

So there must be also two magnetic sensors, right? I have sensors on wall, not on door.

I'm using internal sensors from gate motor connected to WB hardware but there's no difference

ptath commented 2 years ago

"обработка" node

var newMsg, newpayload = {};
var gate = global.get("gate");

// opened
if ( (msg.payload["/devices/wb-gpio/controls/EXT1_IN13"] == "1") && 
        (msg.payload["/devices/wb-gpio/controls/EXT1_IN14"] == "0") ) {
            gate.CurrentDoorState = 0;
            gate.TargetDoorState = 0;
            gate.CurrentPosition = 100;
            gate.TargetPosition = 100;
            global.set("gate", gate);
            return [{ "payload": { "CurrentDoorState": 0, "TargetDoorState": 0 } }, null];
        }

// closed
if ((msg.payload["/devices/wb-gpio/controls/EXT1_IN13"] == "0") &&
        (msg.payload["/devices/wb-gpio/controls/EXT1_IN14"] == "1")) {
            gate.CurrentDoorState = 1;
            gate.TargetDoorState = 1;
            gate.CurrentPosition = 0;
            gate.TargetPosition = 0;
            global.set("gate", gate);
            return [{ "payload": { "CurrentDoorState": 1, "TargetDoorState": 1 } }, null];
}

// start moving
if ((msg.payload["/devices/wb-gpio/controls/EXT1_IN13"] == "1") &&
    (msg.payload["/devices/wb-gpio/controls/EXT1_IN14"] == "1")) {
        // if closed
        if ( gate.CurrentDoorState == 1 ) {
            gate.CurrentDoorState = 2;
            gate.TargetDoorState = 0;
            gate.CurrentPosition = 100;
            gate.TargetPosition = 100;
            global.set("gate", gate);
            return [{ "payload": { "CurrentDoorState": 2, "TargetDoorState": 0 } }, null];
        }
        // if opened
        if (gate.CurrentDoorState == 0 ) {
            gate.CurrentDoorState = 3;
            gate.TargetDoorState = 1;
            gate.CurrentPosition = 100;
            gate.TargetPosition = 100;
            global.set("gate", gate);
            return [{ "payload": { "CurrentDoorState": 3, "TargetDoorState": 1 } }, null];
        }
}
S474N commented 2 years ago

So, used join node and it works perfectly.

But have two questions: 1 - looking for idea for initialize // SOLVED with deconz get node. 2 - for what are two right outputs? // SOLVED - you have another HW, I have same payload for opening/closing.

image

So, everything works perfectly! Thank you for cooperation!