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
420 stars 52 forks source link

LockTargetState / LockMechanism #429

Closed Typ1er closed 3 years ago

Typ1er commented 3 years ago

I have a problem with the LockMechanism,

I have a lock that I turn on for 3 seconds every time I turn it on. After that it goes off automatically.

In my case the input and output node is the same. The HomeKit Node with the LockMechanism, passes the input from the LockTargetState directly to the output. How can I prevent this? The HomeKit Node delivers exactly the same payload for switching.

A second question about the LockMechanism.

When switching on via Nodered, the HomeKit Node is always "door open" I was it after a Deploy or Restart of the system like to immediately deactivate h aben, otherwise there is always a push message, lock was closed.

Shaquu commented 3 years ago

First of all, you need to disable “ allow message pass through” in bridge. Second I am calling our locksmith @crxporter

crxporter commented 3 years ago

It seems like your lock is like "buzzing in" type lock, is this correct?

The HomeKit Node with the LockMechanism, passes the input from the LockTargetState directly to the output

Shaquu answered this part.

When switching on via Nodered, the HomeKit Node is always "door open" I was it after a Deploy or Restart of the system

We should be able to get things working. Can you share the flow you have already? Or at least examples of the payloads which your lock hardware is sending and expecting?

More info: The lock service will send payloads like:

{"LockTargetState":0}

And it will need to receive payloads from your device like:

{"LockTargetState":0, "LockCurrentState":0}

Current state can be: 0: Unlocked 1: Locked 2: Jammed 3: Unknown

Target state can be: 0: Unlocked 1: Locked

If you have a mismatch between "Current" and "Target" then Home app will show "Unlocking" or "Locking" ... some examples:

Current 0, Target 1 -> home app shows "locking" Current 1, Target 0 -> home app shows "unlocking" Current 0, Target 0 -> home app shows "unlocked"

Ok, enough with the background about how homekit works. On to your question about startup.

You will probably assume the lock is "locked" at startup. Simply have a message from inject node about 5 seconds after startup. Use a message like {"LockTargetState":1, "LockCurrentState":1}

When you trigger an "unlock" event from home app, you will see this message come "out" of the homekit node: {"LockTargetState":0} ... at this point you will want to trigger the 3-seconds unlock time and send a message like {"LockTargetState":0, "LockCurrentState":0}

Once the 3 seconds have passed, the lock will be in "locked" state again so just send {"LockTargetState":1, "LockCurrentState":1} into the homekit node.

I hope that makes sense. @Shaquu how do I edit the new wiki? Give me a crash-course and we'll want to get this added as an example, since nothing is written there for locks yet.

Typ1er commented 3 years ago

Thank you both.

It long at the setting of the pass through.

I know the 4 states from Target and CurrentState. I use only two, open and close (true/false)

As a beginner you don't have the examples to understand it.

Input Node and Output Node are from ioBroker, this switch a relay on a ESP8266 (Tasmota)

Bildschirmfoto 2021-08-09 um 22 17 50
Here is my flow ```json [ { "id": "1612300.062e6d", "type": "change", "z": "a273f937.f43b08", "name": "Numbers to 0/1", "rules": [ { "t": "change", "p": "payload.LockTargetState", "pt": "msg", "from": "0", "fromt": "num", "to": "true", "tot": "bool" }, { "t": "change", "p": "payload.LockTargetState", "pt": "msg", "from": "1", "fromt": "num", "to": "false", "tot": "bool" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 1340, "y": 260, "wires": [ [ "14bdaf30.f97b69", "1df4afe7.d5cc7" ] ] }, { "id": "14bdaf30.f97b69", "type": "ioBroker out", "z": "a273f937.f43b08", "name": "Klingel_476256 POWER3", "topic": "sonoff.0.Klingel_476256.POWER3", "ack": "false", "autoCreate": "false", "stateName": "", "role": "", "payloadType": "", "readonly": "", "stateUnit": "", "stateMin": "", "stateMax": "", "x": 1590, "y": 260, "wires": [] }, { "id": "f199dda4.dfb0a", "type": "switch", "z": "a273f937.f43b08", "name": "Numbers only", "property": "payload.LockTargetState", "propertyType": "msg", "rules": [ { "t": "istype", "v": "number", "vt": "number" } ], "checkall": "true", "repair": false, "outputs": 1, "x": 1140, "y": 260, "wires": [ [ "1612300.062e6d" ] ] }, { "id": "5e8378a5.cc30f", "type": "change", "z": "a273f937.f43b08", "name": "CurrentState", "rules": [ { "t": "move", "p": "payload", "pt": "msg", "to": "payload.LockCurrentState", "tot": "msg" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 390, "y": 260, "wires": [ [ "46ac039e.f2130c" ] ] }, { "id": "83ae514f.01862", "type": "ioBroker in", "z": "a273f937.f43b08", "name": "Klingel_476256 POWER3", "topic": "sonoff.0.Klingel_476256.POWER3", "payloadType": "value", "onlyack": "", "func": "rbe", "gap": "", "fireOnStart": "true", "x": 150, "y": 260, "wires": [ [ "5e8378a5.cc30f", "b80afdc5.ae7dc8" ] ] }, { "id": "bdd37bbe.ed7e38", "type": "homekit-service", "z": "a273f937.f43b08", "isParent": true, "hostType": "0", "bridge": "bb104aaa.9190f", "accessoryId": "", "parentService": "", "name": "Gartentor", "serviceName": "LockMechanism", "topic": "", "filter": false, "manufacturer": "NRCHKB", "model": "0.140.4", "serialNo": "Default Serial Number", "firmwareRev": "0.140.4", "hardwareRev": "0.140.4", "softwareRev": "0.140.4", "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": "{\"LockCurrentState\":{\"validValues\":[0,1]},\"LockTargetState\":{\"validValues\":[0,1]}}", "waitForSetupMsg": false, "outputs": 2, "x": 960, "y": 260, "wires": [ [ "50199659.568578", "f199dda4.dfb0a" ], [] ] }, { "id": "b80afdc5.ae7dc8", "type": "change", "z": "a273f937.f43b08", "name": "TargetState", "rules": [ { "t": "move", "p": "payload", "pt": "msg", "to": "payload.LockTargetState", "tot": "msg" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 390, "y": 320, "wires": [ [ "866c3f9d.3e2f8" ] ] }, { "id": "46ac039e.f2130c", "type": "delay", "z": "a273f937.f43b08", "name": "500ms", "pauseType": "delay", "timeout": "500", "timeoutUnits": "milliseconds", "rate": "1", "nbRateUnits": "1", "rateUnits": "second", "randomFirst": "1", "randomLast": "5", "randomUnits": "seconds", "drop": false, "x": 530, "y": 260, "wires": [ [ "866c3f9d.3e2f8" ] ] }, { "id": "866c3f9d.3e2f8", "type": "change", "z": "a273f937.f43b08", "name": "true/false to number 0/1", "rules": [ { "t": "change", "p": "payload.LockCurrentState", "pt": "msg", "from": "true", "fromt": "bool", "to": "0", "tot": "num" }, { "t": "change", "p": "payload.LockCurrentState", "pt": "msg", "from": "false", "fromt": "bool", "to": "1", "tot": "num" }, { "t": "change", "p": "payload.LockTargetState", "pt": "msg", "from": "true", "fromt": "bool", "to": "0", "tot": "num" }, { "t": "change", "p": "payload.LockTargetState", "pt": "msg", "from": "false", "fromt": "bool", "to": "1", "tot": "num" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 750, "y": 260, "wires": [ [ "bdd37bbe.ed7e38" ] ] }, { "id": "50199659.568578", "type": "debug", "z": "a273f937.f43b08", "name": "", "active": false, "tosidebar": false, "console": false, "tostatus": true, "complete": "payload", "targetType": "msg", "statusVal": "payload", "statusType": "auto", "x": 1070, "y": 200, "wires": [] }, { "id": "1df4afe7.d5cc7", "type": "debug", "z": "a273f937.f43b08", "name": "", "active": false, "tosidebar": false, "console": false, "tostatus": true, "complete": "payload", "targetType": "msg", "statusVal": "payload", "statusType": "auto", "x": 1510, "y": 200, "wires": [] }, { "id": "bb104aaa.9190f", "type": "homekit-bridge", "bridgeName": "Node-RED", "pinCode": "123-45-678", "port": "", "advertiser": "bonjour-hap", "allowInsecureRequest": false, "manufacturer": "NRCHKB", "model": "0.140.4", "serialNo": "Default Serial Number", "firmwareRev": "0.140.4", "hardwareRev": "0.140.4", "softwareRev": "0.140.4", "customMdnsConfig": false, "mdnsMulticast": true, "mdnsInterface": "", "mdnsPort": "", "mdnsIp": "", "mdnsTtl": "", "mdnsLoopback": true, "mdnsReuseAddr": true, "allowMessagePassthrough": false } ] ```
Shaquu commented 3 years ago

@Typ1er is there any more help required?

crxporter commented 3 years ago

I'm the cleanup bot guy doing my rounds. Closing for now. Please re-open if you need more help.