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
415 stars 51 forks source link

Window covering current state #222

Closed juhpesis closed 4 years ago

juhpesis commented 4 years ago

I added Ikea fyrtur roller blind to my zigbee2mqtt configuration and it is working nicely. I added it to homekit, but current state of blind is not working. Open and close and target position works well, but if I tell current state, nothing happens in my phone and blind starts to move. Homekit bug or NRCHKB bug or is it me doing something wrong?

Ios 13.3.1 1.0.4 I used this example and current state is not working right for me. https://github.com/NRCHKB/node-red-contrib-homekit-bridged/wiki/Example-Window-Covering

juhpesis commented 4 years ago

Sorry, current position is not working

crxporter commented 4 years ago

Are you sending both CurrentPosition and TargetPosition messages? The key on the window covering is to send both of these messages.

There are 4 cases:

  1. CurrentPosition = TargetPosition -> Home app will show how much open the window is
  2. CurrentPosition > TargetPosition -> Home app will show "Closing"
  3. CurrentPosition < TargetPosition -> Home app will show "Opening"

The message that is output from Home app is TargetPosition which is seen as the request to move. The CurrentPosition for this item should only be sent into the homekit node, shouldn't ever come back out.

For another reference point, here is my functioning Window Covering item: Screen Shot 2020-03-04 at 6 38 46 AM

Node-red code but please note I took out the homekit item because this pi uses an old version of the plugin.

[{"id":"c2faaacd.6b4db8","type":"function","z":"fb9aba5f.c9fe5","name":"Input","func":"var inState = msg.payload.state;\nvar inBright = 0;\n\nvar delay = {\"payload\": null};\n\nmsg = {\"payload\": null};\n\nif (inState === \"ON\") {\n    inBright=100;\n}\nif (inState === \"OFF\") {\n    inBright=0;\n}\nmsg.payload = {\n    \"TargetPosition\": inBright\n}\ndelay.payload = {\n    \"CurrentPosition\": inBright\n}\nreturn [msg,delay];","outputs":2,"noerr":0,"x":1930,"y":2600,"wires":[[],["3328b06a.09982"]]},{"id":"b1ac85c5.54ee8","type":"mqtt in","z":"fb9aba5f.c9fe5","name":"Window in","topic":"insteon/2c.64.08/state","qos":"1","datatype":"json","broker":"e0b73c6a.c880a","x":1780,"y":2600,"wires":[["c2faaacd.6b4db8","29bb1bea.ae08dc"]]},{"id":"3328b06a.09982","type":"delay","z":"fb9aba5f.c9fe5","name":"12s","pauseType":"delay","timeout":"12","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":2070,"y":2640,"wires":[[]]},{"id":"29bb1bea.ae08dc","type":"change","z":"fb9aba5f.c9fe5","name":"flow.Window","rules":[{"t":"move","p":"payload.state","pt":"msg","to":"Window","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":1950,"y":2560,"wires":[[]]},{"id":"23865310.8e5e3c","type":"function","z":"fb9aba5f.c9fe5","name":"Output","func":"\nif (msg.hap !== undefined && msg.hap.context !== undefined) {\n    if (msg.payload.TargetPosition >= 50) {\n        msg.payload = {\n            \"state\": \"ON\",\n            \"brightness\": 255\n        }\n    }\n    if (msg.payload.TargetPosition < 50) {\n        msg.payload = {\n            \"state\": \"OFF\",\n            \"brightness\": 0\n        }\n    }\n}\nreturn msg;\n","outputs":1,"noerr":0,"x":2370,"y":2600,"wires":[["ef7eff58.cd019"]]},{"id":"ef7eff58.cd019","type":"mqtt out","z":"fb9aba5f.c9fe5","name":"Window out","topic":"insteon/2c.64.08/level","qos":"1","retain":"false","broker":"e0b73c6a.c880a","x":2530,"y":2600,"wires":[]},{"id":"e0b73c6a.c880a","type":"mqtt-broker","z":"","name":"local","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":"","closeTopic":"","closeQos":"0","closeRetain":"false","closePayload":"","willTopic":"","willQos":"0","willRetain":"false","willPayload":""}]
crxporter commented 4 years ago

Note on my example the functions refer to the window positions as "brightness". This is because my window controller and dimmers use the same commands so I've just copied "brightness" from them. Also my output converts everything to "all the way open" or "all the way closed".

juhpesis commented 4 years ago

Ok thanks, I play with this tomorrow. But if both are needed, does this mean that if I move blind manually from build in push buttons, home kit does not know blind position? If I inject only CurrentPosition, nothing happens and iphone shows blind is open even if it closed. And I cannot use TargetPosition because command is not coming from homekit.

I have to play with this and let see what happens.

crxporter commented 4 years ago

It takes a little while to fiddle around and get it right. One "easy option" is to just always send a payload like:

{
    "TargetPosition": 45,
    "CurrentPosition": 45
}

If you send the same value (in percent open) to both always then your home app should show the correct value, in this case it's 45% open. Home app will never show "opening" or "closing" but if you don't care - that's fine.

In my example above I've found my curtain takes 12 seconds to open and close. That's the reason for the 12 second delay node - I just send target, wait 12 seconds, and send current. That way it shows opening/closing for the 12 seconds between the messages. It was easy enough but honestly I've only opened the home app to watch that a few times, otherwise it's "hey siri open the window" or schedules...


While I'm at it, here's an update that I just added to the wiki page. I've done this one with the new version of the plugin so it should copy-paste right into your setup.

Screen Shot 2020-03-04 at 9 09 19 AM

juhpesis commented 4 years ago

Ok, I played with this one, and I did some modifications to my flow and now it works. If I press blind's build in push button to close or open, HomeKit gets only CurrentState value and this is the only situation when HomeKit thinks blind is in different position and indicates Opening... or Closing... No problem, because I don't use those pushbuttons. But switch next to bed have to go to HomeKit TargetPosition, otherwise position indication gets lost if command is not coming from HomeKit service. Homekit gets position state from blind, and it comes through trigger with delay, which gives last position value to HomeKit, when blind stops. So Opening... and closing... states works also like a charm. Thanks for help!