motioneye-project / motioneye

A web frontend for the motion daemon.
GNU General Public License v3.0
3.93k stars 651 forks source link

de/activate motion detection by Script - not start/stop service #251

Open dfens-1373 opened 8 years ago

dfens-1373 commented 8 years ago

Is there a way just to de/activate motion detection by script (triggered by gpio) so that the service stays on and motioneye could be furthermore controlled by Web Interface (e.g. examine files or restart motion detection)?

And is it possibly to read from commandline/script if motion detection is enabled?

ozett commented 8 years ago

you could do something like this to "motion " itself. it has a "http-interface"/api

http://www.lavrsen.dk/foswiki/bin/view/Motion/RemoteControlHttp

ccrisan commented 8 years ago

Nope, unfortunately that won't be possible because of the working schedule management which will continuously overwrite the setting. I really must do something about this.

ozett commented 8 years ago

:+1: (i will update my motion + motioneye to the latest, to keep up on your improvments) :smile:

pantchox commented 7 years ago

@ccrisan hi! great job on motion! is there any workaround for this? . i currently don't have schedule management enabled. thanks!

sapcons commented 7 years ago

Hello, I am also very much interested in such a script. I am running CCU home automation system on my RPI. When I am at home I want to 'pause' alerting on motioneye. Recording can still go on, but I don't want to receive emails. The camera itself doesn't allow 'shutdown' or 'startup'. Thanks for all your effort!!!

SuperBFG7 commented 6 years ago

Hi, using the motion http-interface is possible as long as you don't use the woking schedule. I'm using a small script to ping our phones/tablets and when any of them is online, turn off motion detection. Works pretty good for me.

https://github.com/SuperBFG7/scripts/blob/master/pi/surveillance.sh

The script also understands pause and start command, so you could use it in a crontab to setup your own schedule. The script remembers the online state and won't interfere (only changes in only presence trigger (de)activation of motion).

PS: remember that everytime you restart motion/motioneye, detection will be on again... :)

timdonovanuk commented 6 years ago

I see this topic come up a lot, and y'all are making it really over complex. Motioneye shouldn't have any inbuilt presence detection - there is already a wonderful massive open source project called Home Assistant that will do stuff like this for you.

The easiest thing to do is to use cURL to post a command to your motioneye - the same command that happens when you toggle motion on/off in the web UI. It's a bit messy because you have to send the entire config every time but it works really well.

SuperBFG7 commented 6 years ago

I agree, I was just too lazy to install, learn and configure home assistant (yet another tool) and just made the script to activate/deactivate motioneye :)

timdonovanuk commented 6 years ago

Fair enough :) For anyone else reading I would heartily recommend Home Assistant for people looking to do presence detection, as comes with all sorts of inbuilt ways of doing this. It's also quite easy to plumb into motioneye using curl.

sfgabe commented 6 years ago

The last part of my script for motioneyeos might help. It rewrites the thread.conf to turn motion detection on or off (or whatever parameters you want to change). It does require a reboot to see the changes take effect, so it may not 100% solve your issue. I'm sure HomeAssistant would have worked, but like @SuperBFG7 I wanted to work with the setup I already had.

mario-g0 commented 6 years ago

@timdonovanuk could you please point me to some instructions on how to do that? I use HA and want to activate or deactivate motion detection based on presence detection

sfgabe commented 6 years ago

@mario-g0 - there's a bunch of ways to do presence detection through Home Assistant, it just depends on what works with your setup.

I now have home assistant using the google location option to decide if I'm home or away (state change trigger), then sending a curl to activate the motioneyeos action button (command line activity) to turn on motion detection (using a simplified version of the script mentioned above).

Bluetooth detection to your phone or other device you carry with you is probably a more reliable trigger but I couldn't get it working in my setup.

evripidis commented 6 years ago

@SuperBFG7 That seems to be extremely useful! Could you please provide a quick tip how to get it run?

SuperBFG7 commented 6 years ago

@evripidis sure:

  1. in your WiFi router config: assign fixed IPs to the devices you want to track; I'm using my and my wifes mobilephone
  2. put the script https://github.com/SuperBFG7/scripts/blob/master/pi/surveillance.sh in /usr/local/bin or anywhere you like and can execute it
  3. replace the dummy IPs on line 6 with the fixed IPs of your devices
  4. replace the dummy motioneye URL on line 8 with your motioneye installations host/port
  5. call the script manually to test:
    1. surveillance.sh status to get the current status
    2. surveillance.sh pause to stop motion detection
    3. surveillance.sh status to start motion detection
  6. call it without arguments to use the presence detection
  7. create a cron job to run the script every couple of minutes
evripidis commented 6 years ago

@SuperBFG7 Thank you very much for your quick response! The thing is that I've messed up a little bit of motioneye and motioneyeos and now I am trying to setup a motioneyeos from scratch. Unfortunately I think this script is not working on motioneyeos, or at least I am not doing it right. I'll keep your tips if I have to go back to my previous motioneye setup. Thanks!

PS. I couldn't find a way to add the file.sh into the motioneye. Everything I've tried always had the same result "permission denied".

kabadisha commented 5 years ago

@SuperBFG7 FYI, I did something similar but found that pinging my phone was quite unreliable. If my phone was asleep, it often wouldn't respond to pings. I found that I could get my router to output the wireless association list on the command line, so I used that instead. It seems WAAAY more reliable.

Gist here: https://gist.github.com/kabadisha/a87e50311d3ed4589f17a6e37c574a44

SuperBFG7 commented 5 years ago

Yes, it is not very reliable. Thanks for sharing your solution! Unfortunately I can’t execute scripts on my router. :( My script uses an extra loop, retrying the ping 30s later again, to mitigate this. Not very elegant, but I found it improved the reliability to a usable level. Querying for more than one device (i.e. phone, tablet, laptop, ...) also helps. The probability that no device is reached is very low then. Of course you should not forget to turn the devices off or take them with you when you leave. :) Am 12. Jan. 2019, 00:52 +0100 schrieb Charles Wilkinson notifications@github.com:

@SuperBFG7 FYI, I did something similar but found that pinging my phone was quite unreliable. If my phone was asleep, it often wouldn't respond to pings. I found that I could get my router to output the wireless association list on the command line, so I used that instead. It seems WAAAY more reliable. Gist here: https://gist.github.com/kabadisha/a87e50311d3ed4589f17a6e37c574a44 — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

pantchox commented 5 years ago

I am using pushbullet and node-red to apply activate on/of the motion detection, i use node-red to change the motion eye config, kill it and restart it - takes from 10 - 20 seconds. Also when there is a motion i get notification on my phone with pushbullet since every motion calls node-red REST endpoint that sends a message to pushbullet.

I will post a blog post in the following weeks.

On Mon, Jan 14, 2019 at 2:10 PM Daniel Schregenberger < notifications@github.com> wrote:

Yes, it is not very reliable. Thanks for sharing your solution! Unfortunately I can’t execute scripts on my router. :( My script uses an extra loop, retrying the ping 30s later again, to mitigate this. Not very elegant, but I found it improved the reliability to a usable level. Querying for more than one device (i.e. phone, tablet, laptop, ...) also helps. The probability that no device is reached is very low then. Of course you should not forget to turn the devices off or take them with you when you leave. :) Am 12. Jan. 2019, 00:52 +0100 schrieb Charles Wilkinson < notifications@github.com>:

@SuperBFG7 FYI, I did something similar but found that pinging my phone was quite unreliable. If my phone was asleep, it often wouldn't respond to pings. I found that I could get my router to output the wireless association list on the command line, so I used that instead. It seems WAAAY more reliable. Gist here: https://gist.github.com/kabadisha/a87e50311d3ed4589f17a6e37c574a44 — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ccrisan/motioneye/issues/251#issuecomment-453984349, or mute the thread https://github.com/notifications/unsubscribe-auth/AGr9FNeQes026pBJlJPt639Ki1-8KJRSks5vDHPLgaJpZM4JN9ib .

SuperBFG7 commented 5 years ago

For notification I am using IFTTT triggered by images uploaded to Google cloud.

SdeGeata commented 5 years ago

@SuperBFG7:

How do i get this to work? I put the script where suggested, chmoded to make it exectuable and set the crontab. I try to run it in the command line and get this feedback:

surveillance.sh status \/usr/local/bin/surveillance.sh: line 3: /usr/local/bin/includes.sh: No such file or directory

SuperBFG7 commented 5 years ago

Hi @SdeGeata

the script is part of my collection of scripts and uses a common function. I've pushed a new version, which should remove the dependency and allow it to be used standalone.

Just change the IPs to check (your phones, tablets, ...) and the URL where motion(eye) is running.

Hope this helps.

Daniel

On Tue, Jul 23, 2019 at 12:04 AM SdeGeata notifications@github.com wrote:

@SuperBFG7 https://github.com/SuperBFG7:

How do i get this to work? I put the script where suggested, chmoded to make it exectuable and set the crontab. I try to run it in the command line and get this feedback:

surveillance.sh status \/usr/local/bin/surveillance.sh: line 3: /usr/local/bin/includes.sh: No such file or directory

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ccrisan/motioneye/issues/251?email_source=notifications&email_token=ADNKR3UH7AC7GVJRJ77XL3TQAYVFNA5CNFSM4CJX3CN2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD2RJSFY#issuecomment-513972503, or mute the thread https://github.com/notifications/unsubscribe-auth/ADNKR3VSMJJ4SBDNQIG4XM3QAYVFNANCNFSM4CJX3CNQ .

SdeGeata commented 5 years ago

@SuperBFG7 Thanks! I'll give it a try!

SdeGeata commented 5 years ago

@SuperBFG7 Thanks again for your help. It turns out that even once I got the thing to work (crontab execution permission issues...) it was still having a hard time detecting my iPhone properly. Gonna explore other options - perhaps buy an SSH friendly router would be a start?

piachuPL commented 5 years ago

i think that helps: https://github.com/piachuPL/Motionoffon

Toon-nooT commented 5 years ago

@SuperBFG7 I looked at that script. Is it possible to work only with inputting MAC addresses instead of IPs? This would remove the need to assign fixed IPs. I see you're already looking at the arp cache...

SuperBFG7 commented 5 years ago

You can skip the ping and only grep for the MAC in the arp cache, but unless you run this on your router, I think it will work considerably worse. The arp cache will probably only contain the MAC if there has been a communication with the device (i.e. phone) recently.

On Tue, Sep 17, 2019 at 10:56 AM Toon-nooT notifications@github.com wrote:

@SuperBFG7 https://github.com/SuperBFG7 I looked at that script. Is it possible to work only with inputting MAC addresses instead of IPs? This would remove the need to assign fixed IPs. I see you're already looking at the arp cache...

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ccrisan/motioneye/issues/251?email_source=notifications&email_token=ADNKR3X6FHQ4CPQAUA7MZNDQKCLT7A5CNFSM4CJX3CN2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD632F6Q#issuecomment-532128506, or mute the thread https://github.com/notifications/unsubscribe-auth/ADNKR3RAXCPFUDZ6Z5HWUMTQKCLT7ANCNFSM4CJX3CNQ .

markptrueman commented 4 years ago

Nope, unfortunately that won't be possible because of the working schedule management which will continuously overwrite the setting. I really must do something about this.

Have you been able to do anything about this? Would love to be able to turn off motion detection with motioneye running. Every time i tell motion to stop motion detection, motioneye continues to detect motion.

Thanks

Mark