lagunacomputer / homebridge-MotionSensor

HomeBridge HomeKit Plugin for arduino based PIR motion sensors
23 stars 14 forks source link

Interval not working #4

Open greensouth opened 7 years ago

greensouth commented 7 years ago

Hi!!

I'm watching the access logs in my apache server and I see that the motion is not refreshing within the specified interval. I have been trying using the "realtime" attribute of the base homebridge-http and it's requesting status continuously.

I'm doing something wrong? Or I don't understand how it works? Should it keep Home App continuosly refreshed in the background? (just for, -for instance-, launch a notification on movement detected).

Thanks!

peros550 commented 7 years ago

I also have the same question. If possible please clarify.

In my testing, there is considerable delay between a PIR senses a movement and when that information becomes available in Home app.

Thanks in advance for your feedback.

lagunacomputer commented 7 years ago

not sure, I didn't write the interval code. the original plugin I wrote was based on a basic temperature plugin that only updated when Homebridge polled for a sensor update, not the other way around.

Perhaps the fork comments can help, https://github.com/lagunacomputer/homebridge-MotionSensor/commit/9d20215655467d5ff56ab68f73aab27bc2b8563c

lagunacomputer commented 7 years ago

from perote2000 and metbosch:

https://github.com/lagunacomputer/homebridge-MotionSensor/pull/3

For device status there are 5 different paradigms in use with HomeKit, each with different levels of complexity and integration.

1) Fire and forget, HomeKit/homebridge plugin sends an on/off command to the device and doesn't know if it worked or not. And HomeKit doesn't know if the device is on/off, it just knows what command was last sent. This pattern is typically seen with IR blaster type devices. HomeKit would not know if the command failed.

2) Devices with distinct on/off commands, like your example with on/off urls. In this case HomeKit would know that the command worked, and what command was last sent, but homekit would not be aware if the device was controlled locally

3) Is similar to number 2, except that the device also supports status commands, and responds to periodic status requests from HomeKit with the current status, including if the device was controlled locally. When you change rooms in Home, it typically updates the device status.

4) Is similar to 3, except that the plugin polls the device on a regular interval for status, and updates any changes to HomeKit. Homebridge-hue uses this pattern, as the Philip's hub doesn't support event notifications.

5) Is similar to 2, but the device supports event notifications. And HomeKit is updated immediately with any status changes on the device. As programming this is quite intensive and requires support in the device itself, only a few plugins use this model.

I have written several plugins, and have used all these patterns, with the deciding factoring what the device API supports.

In your question, if the device has a status URL you can have a plugin track status with pattern 4, and poll the device regularly.

martin072 commented 6 years ago

Hi, I also noted the plugin does not update, so it's relatively useless if you want to fire events based on motion. Any way to fix this, so it updates according to the set interval?

martin072 commented 6 years ago

I found the issue I think.

The npm install -g homebridge-MotionSensor command installs a wrong version of the plugin. When looking at the index.js in usr/lib/node_modules/homebridge-MotionSensor, it is not the same as the one here in github. I just copied and paste the contents of the index.js from here, and now its working fine!

sorriso93 commented 6 years ago

Martin072 you are right, the github is v4 whereas the np is the v3. How can I install the v4 version?

phenotypic commented 6 years ago

As @martin072 stated above, it seems the issue is with npm installing the wrong version.

For me, I used the following command to install the repository directly from the GitHub page and now it works perfectly:

sudo npm install -g git+https://github.com/lagunacomputer/homebridge-MotionSensor.git

If you still receive permission errors after using sudo (usually on Raspberry Pis), run sudo -i to enter root shell then run the command above again.

Hope this helps!