4

I've just discovered Motion and it works like a charm.. My only problem is that I'd like it to be active only during night-time, but there's no parameter for scheduling..

I think I could write a program that would control Motion via its "HTTP API", but I was wondering if someone had already done that, or if there's an alternative solution.

Thanks in advance :)

fixer1234
  • 27,064
  • 61
  • 75
  • 116
Joril
  • 2,020
  • 1
  • 26
  • 33

2 Answers2

6

For this simple task, Motion's HTTP API can be used directly with wget or similar..
Straight from the FAQ:

0 9 * * * root /usr/bin/lwp-request http://localhost:8080/0/detection/start > /dev/null 
0 18 * * * root /usr/bin/lwp-request http://localhost:8080/0/detection/pause > /dev/null 
endolith
  • 7,507
  • 25
  • 84
  • 121
Joril
  • 2,020
  • 1
  • 26
  • 33
  • 1
    Note that this pauses the motion capture, but does not turn off the camera or the live feed. Killing motion turns off the camera. – endolith Nov 26 '12 at 16:12
2

Use cron:

crontab -e

then put in it:

DISPLAY=:0.0
0 0 * * * /usr/bin/motion 
0 8 * * * /usr/bin/killall motion

I'm assuming that you want to open "motion" at midnight everyday, and that motion path is /usr/bin/motion: custom this crontab to your needs and it'll do the trick.

endolith
  • 7,507
  • 25
  • 84
  • 121
dag729
  • 1,944
  • 3
  • 21
  • 35
  • 1
    You'll also need to add an entry to stop motion during the day. 0 8 * * * killall motion – Chris Nava Jul 30 '10 at 03:45
  • @Chris Nava: Oops...you're right! But instead of "killall" the full path must be used. Usually /usr/bin/killall – dag729 Jul 30 '10 at 11:06
  • Well that's quite "brutal" but I'll try it out, thanks :) – Joril Jul 30 '10 at 12:01
  • I take that back, Motion handles SIGTERMs nicely :) – Joril Jul 30 '10 at 14:24
  • I didn't get it: it works? – dag729 Jul 30 '10 at 15:12
  • @dag279: yes it works :) Although there's another method too, I'll add it as another answer for completeness... – Joril Jul 30 '10 at 15:43
  • 1
    @Joril: of course the method you posted as an answer is better suited for this situation. My answer is a generic way to do almost...everything! ("Ehy mama, can you please wake me up at 6 a.m.?" "Of course" "crontab -e : 0 6 * * * /usr/bin/wake_up_son") – dag729 Jul 30 '10 at 17:56
  • 1
    If this were a production system I would avoid killall and instead log the process ID of motion and kill just that. If it's a home machine I doubt you'll run another process named motion unknowingly. – Chris Nava Jul 30 '10 at 19:43