HomeKit Garage Door Opener (Raspberry Pi)

Hello, I am having trouble with GarageDoorOpener HomeKit node. I have a reed switch attached to send the status of the door (open/closed) and that going into the HomeKit node. The problem that I am running into is, when the garage door is opened by a source other than HomeKit (i.e. garage door switch), the "TargetDoorState" is going through the HomeKit node and instantly firing the relay which will cause the door to stop.

My understanding is, "TargetDoorState" comes out of the HomeKit node when triggered inside of the HomeKit app. This is what I am using to fire the relay. The trouble is the reed switch also passes "TargetDoorState" through and fires the relay as well. Is there a way to change what is coming out of the HomeKit node to use that for the relay and not allow the reed switch to fire?

Code:

[
    {
        "id": "598c56c1.d00538",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": ""
    },
    {
        "id": "3db28932.7742fe",
        "type": "rpi-gpio out",
        "z": "598c56c1.d00538",
        "name": "RELAY",
        "pin": "37",
        "set": true,
        "level": "0",
        "freq": "",
        "out": "out",
        "x": 690,
        "y": 180,
        "wires": []
    },
    {
        "id": "d0d077d2.26e568",
        "type": "rpi-gpio in",
        "z": "598c56c1.d00538",
        "name": "Reed Switch",
        "pin": "11",
        "intype": "up",
        "debounce": "25",
        "read": true,
        "x": 90,
        "y": 300,
        "wires": [
            [
                "51d4ca1c.e796a4"
            ]
        ]
    },
    {
        "id": "51d4ca1c.e796a4",
        "type": "function",
        "z": "598c56c1.d00538",
        "name": "Reed Switch Function",
        "func": "var characteristic = {};\n\nif(msg.payload === 1){\n//characteristic.ObstructionDetected = false;\ncharacteristic.TargetDoorState = false;\ncharacteristic.CurrentDoorState = false;\n}\n\nif(msg.payload === 0){\n//characteristic.ObstructionDetected = false;\ncharacteristic.TargetDoorState = true;\ncharacteristic.CurrentDoorState = true;\n}\n\nmsg.payload = characteristic;\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 320,
        "y": 300,
        "wires": [
            [
                "2df435c3.39cb22",
                "fe5d31f6.f78ca8"
            ]
        ]
    },
    {
        "id": "74703b77.f7593c",
        "type": "debug",
        "z": "598c56c1.d00538",
        "name": "HomeKit Output",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "x": 340,
        "y": 60,
        "wires": []
    },
    {
        "id": "2df435c3.39cb22",
        "type": "debug",
        "z": "598c56c1.d00538",
        "name": "Reed Switch Function Out",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "x": 600,
        "y": 300,
        "wires": []
    },
    {
        "id": "3c98ef1c.817618",
        "type": "trigger",
        "z": "598c56c1.d00538",
        "op1": "1",
        "op2": "0",
        "op1type": "str",
        "op2type": "str",
        "duration": "250",
        "extend": false,
        "units": "ms",
        "reset": "",
        "bytopic": "topic",
        "name": "",
        "x": 420,
        "y": 180,
        "wires": [
            [
                "3db28932.7742fe"
            ]
        ]
    },
    {
        "id": "fe5d31f6.f78ca8",
        "type": "homekit-service",
        "z": "598c56c1.d00538",
        "accessory": "9a78f213.b9c628",
        "name": "Garage",
        "serviceName": "GarageDoorOpener",
        "x": 140,
        "y": 180,
        "wires": [
            [
                "74703b77.f7593c",
                "3c98ef1c.817618"
            ]
        ]
    },
    {
        "id": "9a78f213.b9c628",
        "type": "homekit-accessory",
        "z": "",
        "accessoryName": "Garage Door",
        "pinCode": "111-11-111",
        "port": "",
        "manufacturer": "Default Manufacturer",
        "model": "Default Model",
        "serialNo": "Default Serial Number",
        "accessoryType": "4"
    }
]

Unfortunately your flow isn't currently importable.Please read the following post How to share code or flow json and then edit the above message.

1 Like

I was able to get it fixed by adding a function node after the HomeKit node to ignore the reed switch input and only allow the HomeKit input to fire the relay.

if (msg.hap.context !== undefined )
{
return msg;
}