6
7
Currently I've got my user cron starting Motion on a timer when I typically leave for work, and then killing it when I typically get home, so I can watch my cat/burglars/etc:
0 9 * * * killall motion ; motion
30 18 * * * killall motion
The config file used is ~/.motion/motion.conf
and has daemon on
.
But it would be better if it could detect when I'm actually home and disable the webcam during those times, and enable it at other times. I was thinking my presence could be detected by my Android phone joining the LAN. So something like
- A script that checks every few minutes whether my phone's hostname or MAC address is currently on the LAN
- A Tasker script on my phone that contacts the home computer in some way (simple web server?) when it joins a certain SSID
- A combination of the above
- ...
Any better ideas or advice about how to implement one of these? Tasker is easy to use, but costs $6, so a solution that doesn't depend on it would be useful by a wider audience.
My first attempt at the arp-scan solution doesn't work very well. It creates multiple instances of motion
and doesn't detect the phone reliably, causing the camera to turn on and off sporadically. So maybe it should be more like "check every minute if the phone is present. only turn the camera on if the phone has not been seen for 15 minutes".
Ok, I wrote a python script to do an arp-scan once per minute, and it detects the phone perfectly:
2012-11-27 18:29:10.551552 No
2012-11-27 18:30:22.295997 No
2012-11-27 18:31:34.077431 No
2012-11-27 18:32:45.804675 No
2012-11-27 18:33:57.545211 No
2012-11-27 18:35:09.261680 No
2012-11-27 18:36:20.974378 Yes
2012-11-27 18:37:21.901076 Yes
2012-11-27 18:38:22.417423 Yes
2012-11-27 18:39:22.836101 Yes
2012-11-27 18:40:23.463507 Yes
2012-11-27 18:41:23.876693 Yes
So there's something wrong with cron or the way I'm starting motion or something.
I tried to run /etc/init.d/motion start
instead of running it and killing it as a user, but that method doesn't work:
* Not starting motion daemon, disabled via /etc/default/motion
So I edited /etc/default/motion
to say start_motion_daemon=yes
and tried again:
~> /etc/init.d/motion start
mkdir: cannot create directory `/var/run/motion': Permission denied
I don't even know what that means.
seems like
sudo arp-scan -I eth0 -r 10 android
is faster. when I try to run/etc/init.d/motion start
as root, though, I get* Not starting motion daemon, disabled via /etc/default/motion
. Normally I just run it asmotion
by my non-root user, which uses my settings in~/.motion/motion.conf
– endolith – 2012-10-29T19:18:48.1471I strongly recommend using the daemon. If you still want to run as a user though; you have two options: (a) Replace
/etc/init.d/motion start
withsu -c 'motion' username'. (b) Allow your user to run
motion` with no password in /etc/sudoers (if you use that) and add the entry to the user's crontab with the init.d file's PID checks (best to make a small script that will have the same functionality as the init.d file and call that script from your crontab instead). – dset0x – 2012-10-29T21:13:24.007That seems to create multiple instances of motion every minute. I had been starting the daemon by running
motion
as the user. Is there a way to use theinit.d start
method, but still have it use the config file in my user home directory and still write the files to my user home directory with the user's permissions? – endolith – 2012-11-21T04:38:08.273/etc/init.d/motion stop
kills all the instances if I run it on the command line, but it doesn't do anything inside crontab – endolith – 2012-11-21T05:36:48.183You can open the
/etc/init.d/motion
script and copy the process checking/killing functionality from there into a script of yours. It should work inside crontab by the way (must be in root's crontab if running as root); check your cron logs. – dset0x – 2012-11-21T13:51:56.137