bryan-bartow / homebridge-alarm.com

Alarm.com plugin for Homebridge
ISC License
43 stars 11 forks source link

HomeKit/iCloud door lock state does not update after manual change #28

Closed pmiller189 closed 7 years ago

pmiller189 commented 8 years ago

Hi, First, THANK YOU for homebridge. This is truly a great project and because of its success I have launched into my first weeks of home automation.

Question: Does the alarm.com plugin periodically query the alarm.com device status and push the state to iCloud, or is it basically on demand when iCloud/HomeKit asks for the state?

Why I'm asking: (and I apologize for the lengthy explanation but I wanted to provide as much detail as possible).

When I manually lock or unlock the door, it seems the updated state isn't automatically making it back to iCloud because my triggers don't fire.

However, if I open a HomeKit enabled app to check the state of the door lock, it will do a refresh of the lock and after it discovers the new state, the trigger fires within seconds. The trigger won't fire until I open the Home app on my phone. At this point I'm pretty sure my phone is controlling all of the automation, even though I have an AppleTV, and here's why.

(I have an AppleTV in the house and Siri commands work over LTE when not connected to WiFi, so I know HomeKit is working on it. I expected that the AppleTV and the magic of iCloud would manage the triggers without needing my phone to provide the automation of the triggers. Unfortunately, with my phone completely powered off, this is not the case and the trigger never fires until my phone is powered back on. So at this point I'm sure that the AppleTV is just the means to get the device status to/from my phone where the triggers are stored and executed.)

Now, to the part where I'm wondering if something is missing with the alarm.com plugin or homebridge itself. I have a Hue bridge at home to control the lighting. To examine the difference between a trigger initiated by a light vs. initiated by a door lock I created two triggers, on fires when the light turns off, and another fires when the door is unlocked. Each time I turn the hue light off, the trigger fires within a couple of seconds. When I lock the door (manually), the lock trigger does not fire until I launch the HomeKit enabled app and it refreshes the state of the door lock.

One difference is that the light turning "off" is via a smart switch that talks to the Hue hub, so I assume the hub is pushing an update to iCloud/HomeKit that is pushed to my phone for the trigger to fire. Again, if my phone is powered off, nothing happens, so I assume this has something to do with the state of the bulb being pushed to my phone for to execute the trigger. When my phone is powered on, it fires every time. When I change the door lock, no trigger unless I open the Home app on my phone and it refreshes the lock state.

One thought I had was that the alarm.com site wasn't updating, so I logged in and it always shows the correct door lock state, so the website has the update, but still no trigger fires.

So based on this testing, it seems like there is no periodic polling of the alarm.com device states. Is this correct? Have I been driving myself crazy trying to make something work when it's actually just not a feature that is implemented (polling)?

amitgandhinz commented 8 years ago

I've noticed a periodic poll occurs. So occasionally when i set the alarm, i will get a home kit notification that it was armed/disarmed. This notification varies from happening within seconds or a couple of minutes, to sometimes happening after about an hour.

Im not sure what triggers the polling. It may be an issue with my panel itself not maintaining a constant connection to alarm.com to update its state.

pmiller189 commented 8 years ago

That's what I thought too, that maybe the update wasn't making it to alarm.com website, but it is updating on the alarm.com website within a few seconds. I even get the notification from alarm.com and I can see it on the website. But iCloud isn't updated.

I too have noticed strange polling intervals. When I'm at work sometimes the Home app will notify me that the alarm system was armed, hours after it was armed. I'm wondering if that is some polling from iCloud back to homebridge periodically, then homebridge checks the state on the alarm.com website.

I can only assume this is what is happening based on observing the behavior. I really have no idea. It might be helpful if I can figure out how to enable additional logging somehow so it will log every time it accesses the alarm.com website. Do you know how to do that?

amitgandhinz commented 8 years ago

If you run homebridge with systemctl then you can run journalctl to watch the logs.

Details here - near the bottom

https://github.com/nfarina/homebridge/wiki/Running-HomeBridge-on-a-Raspberry-Pi

The logs shows whenever an accessory is accessed. On Tue, Sep 27, 2016 at 3:06 PM pmiller189 notifications@github.com wrote:

That's what I thought too, that maybe the update wasn't making it to alarm.com website, but it is updating on the alarm.com website within a few seconds. I even get the notification from alarm.com and I can see it on the website. But iCloud isn't updated.

I too have noticed strange polling intervals. When I'm at work sometimes the Home app will notify me that the alarm system was armed, hours after it was armed. I'm wondering if that is some polling from iCloud back to homebridge periodically, then homebridge checks the state on the alarm.com website.

I can only assume this is what is happening based on observing the behavior. I really have no idea. It might be helpful if I can figure out how to enable additional logging somehow so it will log every time it accesses the alarm.com website. Do you know how to do that?

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/bryanbartow/homebridge-alarm.com/issues/28#issuecomment-249965755, or mute the thread https://github.com/notifications/unsubscribe-auth/ABU8k57rT6zT8iyPeoe0R0LkTeOSwW81ks5quWkkgaJpZM4KHRyx .

bryanbartow commented 8 years ago

First, I have no idea about the issues with your triggers only happening when your iPhone is powered on. That seems beyond the scope of my plugin, unless I'm vastly misunderstanding your explanation.

In terms of the plugin, I can't fully answer the question about polling because I haven't looked at the internals of Homebridge itself. What I do know is that Homebridge plugins have callback methods for device state changes. In my experience, those callbacks get called by Homebridge and those results forwarded on to HomeKit at the time of device state change or when manually triggered by a HomeKit enabled app. Whether or not there is any polling happening in between is something you should probably ask on the Homebridge site.

In my experience, the plugin has worked as expected on both 3rd party HomeKit apps on iOS 9 and the Home app on iOS 10. I have changed the state of my alarm system manually, through Siri and with both location and time based triggers. None of them have not worked as expected. It is also important to note that I only have an alarm system I'm using with this plugin. I have not used lights nor door locks with it.

amitgandhinz commented 8 years ago

Yeh the question is how HomeKit gets notified of state changes that happen outside of home kit (e.g. Arming manually in the alarm panel or via alarm.com). Notifications happen but seems irregular. On Tue, Sep 27, 2016 at 6:31 PM Bryan Bartow notifications@github.com wrote:

First, I have no idea about the issues with your triggers only happening when your iPhone is powered on. That seems beyond the scope of my plugin, unless I'm vastly misunderstanding your explanation.

In terms of the plugin, I can't fully answer the question about polling because I haven't looked at the internals of Homebridge itself. What I do know is that Homebridge plugins have callback methods for device state changes. In my experience, those callbacks get called by Homebridge and those results forwarded on to HomeKit at the time of device state change or when manually triggered by a HomeKit enabled app. Whether or not there is any polling happening in between is something you should probably ask on the Homebridge site.

In my experience, the plugin has worked as expected on both 3rd party HomeKit apps on iOS 9 and the Home app on iOS 10. I have changed the state of my alarm system manually, through Siri and with both location and time based triggers. None of them have not worked as expected. It is also important to note that I only have an alarm system I'm using with this plugin. I have not used lights nor door locks with it.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/bryanbartow/homebridge-alarm.com/issues/28#issuecomment-250018453, or mute the thread https://github.com/notifications/unsubscribe-auth/ABU8k1KxntsYxw5Wb8yYdSymE6s7fTi9ks5quZlDgaJpZM4KHRyx .

bryanbartow commented 8 years ago

Just looked at HAP-NodeJS, which is HomeKit accessory server that Homebridge is built on top of. According to the documentation, it looks like each accessory is supposed to implement a "server" that HomeKit can call into. Additionally, it looks like they keep the socket open so the device can send a packet to notify the iOS device of a state change. HAP-NodeJS is trying to do a keep-alive every minute.

Here's my guess as to why notifications seem sporadic when manually changing device state: When you change the device state through HomeKit and, by extension, Homebridge, the plugin has a callback once its done with its work that will cause HAP-NodeJS to send the aforementioned packet to the iOS device to notify if of an update. When you manually change the state of your device, the Homebridge plugin is never invoked and the callback obviously never gets called. Thus, it can't notify HomeKit of any update. My guess is the iOS device periodically polls its accessories in the background using the same background update mechanisms available to iOS apps through the SDKs. These update times can vary and are never guaranteed (I know this from experience of developing my own iOS apps).

I wonder if it would be possible/feasible to add a timer in the plugin itself, which would invoke the update callback method, which would in turn cause HAP-NodeJS to update the iOS device.

amitgandhinz commented 8 years ago

here is an example from the home bridge myq plugin that might help for refreshing state

https://github.com/rainlake/homebridge-platform-myq/blob/master/index.js#L312

They added a timer to the plugin that refreshes based on refreshInterval to get the current state.

bryanbartow commented 8 years ago

@amitgandhinz If you, or anyone else, wants to implement it and submit a pull request I'll look at it. I'm swamped at work right now, so the chances of me getting to it are very slim.

bryanbartow commented 7 years ago

I'm going to close this for now as I don't think it's an issue, per se. If anything, it seems to be an inherent limitation of the homebridge platform. If anyone wants to create an enhancement request for forced state update, feel free.