Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve check_motion script #153

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

airdrummingfool
Copy link

This improves the check_motion script in several ways:

  • Uses -newer flag to limit modification check to files modified since last check, and includes .mp4.tmp files in find call to increase accuracy
  • Supports POSTing a JSON message to notify a local/internet server about motion status. Along with a device handler I'm working on, this will make the Yi into a motion sensor for SmartThings. Payload example:
    {
        "armed": true,
        "motion": false,
        "last_motion_check": 1490776393,
        "host": "YiCamera"
    }
    
  • JSON message includes armed property, which tells whether or not the process that check_motion relies on is running (if it's not running, check_motion will always return false for motion). This limitation exists in the current version of check_motion, but is not documented.

…to a configurable URL with motion information.
@airdrummingfool airdrummingfool changed the title Improving check_motion script Improve check_motion script Mar 29, 2017
@gl-lamhnguyen
Copy link

gl-lamhnguyen commented Apr 25, 2017

Hey @airdrummingfool, are you able to create the device handler for ST yet?

EDIT: Actually, I already have a device handler for a virtual motion detector, but I'm using RPi camera as the source, the latency is around 1 second. However for this check_motion script on Yi camera, the latency could be anywhere between 1s to 60s, which is too long. Do we know how Yi send motion alerts to its app? maybe we could intercept that process and send our custom POST in there...

@airdrummingfool
Copy link
Author

@gl-lamhnguyen Unfortunately, I haven't been able to figure out how the motion alerts are triggered and sent to the app. I have a very rough version of the device handler going, but it is not ready for public release yet and may not be for some time.

Regarding latency: as far as latency of initial motion detection, it is only 1-20 seconds, and this can be improved by changing the sleep 20 to a lower number (at the risk of increasing load on the camera). Latency of motion stop detection is significantly slower: 1-80 seconds (60 seconds to write the video file + 20 second sleep). A maximum of 80 seconds of false-positive motion is acceptable to me; I'm much more interested in the latency of initial detection.

@gl-lamhnguyen
Copy link

Hey @airdrummingfool, are you currently using this check_motion.sh of yours? It seems like the curl (line 18) is fired continuously every 20s as long as the mp4 file exists. This results in multiple alerts within the minute until that file is gone. Is it intentional? that I need to write another check login on destination server?

Also, I'm not quite clear on this parameter armed.

@airdrummingfool
Copy link
Author

I used to use it, but ended up getting a dedicated motion sensor because I was getting some false-positives from the Yi. Since then I have set up cloud access and have been able to turn down the sensitivity on the Yi, so it might work better now.

Yes, a notification is fired every 20 seconds no matter whether motion was detected previously or not. I set up my device handler to act on the transition between states, e.g. from motion: false to motion: true. If multiple motion: trues come in a row, they can be ignored until a motion: false. This would prevent multiple alerts on one motion detection.

However, if this doesn't work for you, it should be pretty easy to add a has_motion_previous property that keeps track of the previous motion check result. You could then skip notification sending if the two are equal.

armed is my way of keeping track of if the camera is actually looking for motion. I have the ability to disable the capture-on-motion functionality of the camera (by killing the mp4record process), and the armed property is a way for my system to recognize when it can trust the motion value. For example, if mp4record has been killed for some reason, then motion will always be false, even if there is motion in front of the camera.

@thib3113
Copy link

thib3113 commented Nov 5, 2018

really thank you for this code :D .

Maybe did you know a way to send a request to an https url ? ( i've tryed wget, but wget doesn't understand https scheme ) .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants