Motion-Project / motion

Motion, a software motion detector. Home page: https://motion-project.github.io/
GNU General Public License v2.0
3.59k stars 544 forks source link

Feature request: support for GPIO (PIR motion sensor) #596

Closed sparvata closed 2 years ago

sparvata commented 6 years ago

I would really appreciate if you provide any support for a PIR motion sensor integrated into the software. Something like a callback function for every sensor trigger. The use case is that I could use this more accurately to capture night camera motion using an IR sensor, IR LED illuminator and an IR camera. Thanks.

Mr-Dave commented 6 years ago

I don't have one of these so it would be difficult to code/test but but can you describe further what is desired? e.g. Would Motion be monitoring the state of the GPIO and then taking actions upon changes (take a picture, make a movie, call a on_ function) or would Motion be revising the states and causing actions to occur on the devices connected to the GPIO (move a servo, trigger a lightswitch?) Or would it be something completely different?

sparvata commented 6 years ago

Hi Dave,

It is what you have described. Nothing that Motion is not doing today. Just the input to detect motion would change. The input being a trigger of the PIR sensor. Your second part (move servo, turn on lightswitch, etc.) which Motion reacts to the motion is also fine. It would be an extension of the first part and also useful maybe. Thanks.

dezral commented 6 years ago

Hi,

I too would like this addition to motion or motioneye(im not sure where it is best implemented)..

but also some kinder http/JSON api could do it too ..where one could tricker the recording/action on or off.. if you have an RPI i would love to buy/send you an pir motion sensor you can test with, they do not cost much ;-) $2 maybe..

This could be use for other stuff as well like other sensors..sound, accelerometer, contact/door sensor or the likes of other with just on/off switches... the sensor part is pretty easy.. its the implementation in motion that is hard i have looked at the code(its old ;-)) and have not been made for RPI GPIO or other external input.

Mr-Dave commented 6 years ago

Motion does have (untested by me) the ability to take snapshots and start movies via the http action interface or signals already.

I view the hard part on this request to be finding a way to get a general configuration option that would work with what you referred to as the "other stuff".

There could be 100's if not 1000's of potential devices users would expect to hook up and have just work. And each device could potentially interact with the GPIO differently.

dezral commented 6 years ago

Well on the GPIO not really that much.. GPIO sensor goes High or Low(On or OFF).. rpi have no analog pins... pretty simpel

I see the code as being the hard to do.. but an API could solve that.. and make other or one self make the solution...

The API is what im hopping for ;-)..

Mr-Dave commented 6 years ago

True. It is just high or low...but there are 32 of them and the action desired would need to be specified by the user for any combination of the 32 binary variables.

For example, device 1 uses pins 3,5,11 vs device 2 using 2,6,8 and device 3 needs Motion to do something when pins 13, 14 toggle between high/low but only when pin 16 is set to high etc. This is then coupled with the situation that the user wants to trigger a snapshot on device 1 vs device 3 they want to tell the application that motion is occurring "now", etc

Motion can already invoke actions to start detection/make movies/take snapshots from an external process. What is missing is the monitoring of the state of the 32 pins(and possibly how they have changed) to invoke the current functionality and avoid the need for an external process.

So the hard part I was referring to was how to set up one or more Motion configuration parameters in such a way as to allow the user to specify all these combinations. This challenge would seem to exist whether it is part of a API or in a configuration parameter.

alligitor commented 6 years ago

bump up with a comment/suggestion. i started looking at exactly the same thing for integration on Raspberry Pi, running motion. first, here's an example of PIR. https://www.amazon.com/DIYmall-HC-SR501-Motion-Infrared-Arduino/dp/B012ZZ4LPM/ref=sr_1_3/135-2012532-8475435?ie=UTF8&qid=1525921882&sr=8-3&keywords=pir+motion+sensor

it uses IR to detect motion. Very low power, simple interface by a single pin output to indicate motion detection.

I found that motion already, seem to have, a mechanism for having an external process signaling events. https://rawgit.com/Motion-Project/motion/master/motion_config.html#Signals_Sent

So another program could be written to detect changes in the GPIO and issuing a kill -USR1

I tested this a bit but couldn't figure out if it is working reliably. My expectation was for motion to start recording a movie when the signal was sent, for x-seconds. however, the start wasn't immediate and length wasn't constant.

Question for maintains of Motion: Is signal USR1 the right way of doing this? Is the expectation of having the mpg file starting right after receiving USR1 correct? How long should/will the mpg file be recorded for?

tosiara commented 3 years ago

One more example of an external sensor would be camera-integrated PIR (example, Logitech Brio Ultra HD Pro Webcam), which could be controlled through V4L2 interface or some custom protocol using vendor-provided SDK