API / Interface to disable motion/camera

1,889 views
Skip to first unread message

Luke Sheldrick

unread,
Jul 28, 2017, 1:12:33 PM7/28/17
to motioneye
Hi,

Currently reimplementing the home CCTV, and someone recommended this project.

At the moment, when my alarm is activated, it calls an API on the Synology running Survaliance station and enables the camera. 

I'd actually like to keep them enabled all the time, but to enable the motion detect in the movie section, i.e. now start to record when you see movement. 

Is that possible? can either be by web / API / SSH..etc

Thanks,
Luke

Carl Draper

unread,
Aug 3, 2017, 1:59:32 PM8/3/17
to motioneye
+1 here. I have nearly the same requirement. I would like to keep the cameras running but to have an API at best or failing that to understand the location of a config file to edit to enable/disable motion detection.

I cannot seem to locate the config for specific cameras on the OS? Where does motion OS keeps its per camera config files please?

Carl Draper

unread,
Aug 3, 2017, 2:40:22 PM8/3/17
to motioneye
So I found a half decent solution for myself and I hope it might help Luke +others.

I have an Rpi3 with a cam direct to the board. Just one at the moment as this the system is still prototype for me. I have a Linux server running samba that acts like a NAS and is my home automation server inc. motioneye that will concentrate the rest of the camera nodes as I set them up.

The WebUI and my home automation box will trigger a script to use ssh and public keys.

Copy the public key from machine you want to control the MotionEyeOS node from (my home automation box in this case)

[root@homeauto ~]# cat ~/.ssh/id_rsa.pub

Copy this text and manually ssh to the MontionEyeOS node. Create ssh_authrozed_keys and copy the public key from the previous step. I then rebooted for good measure.



[root@bar-cam ~]# echo "ssh-rsa AAAAB3NzaC1yc2ELIFGLUFGLJDGCKLJHnLW6dusIv52ZoY9yIKHdRlkSZ/gBLY0<--snip-->uuB2R6ngaAmsjn4i0GLErZSRtKdTuG3qfBtSe6SQE8Kw4PijQp7PCejDVlWc7VRH8lk6YhiVr0G5rAr root@homeauto" > /data/etc/ssh_authorized_keys
[root@bar-cam ~]# reboot

Now the home automation box can login to MotionEyeOS with no interaction from the user and issue commands. In this case we want to change the config of a camera I have configured called "Bar" (This camera will protect my booze!! :)

[root@homeauto ~]# ssh root@bar-cam
The authenticity of host 'bar-cam (192.168.1.114)' can't be established.
ECDSA key fingerprint is 04:60:84:53:6f:91:f7:3e:62:fc:61:e1:65:7c:a9:25.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'bar-cam' (ECDSA) to the list of known hosts.
Welcome to bar-cam.j4ck3l.net!
[root@bar-cam ~]#


I found the camera config file under /data/etc/thread-1.conf. For those interested in how and as I only had one camera to find this might be useful for people with more but going to assume they are thread-2.conf etc, anyway:



[root@bar-cam ~]# grep -lir "bar" /data/etc/*

/data/etc/hostname
/data/etc/thread-1.conf

From here it was easy to narrow down.

I'll assume that motion detection is currently enabled for recordings so go ahead and make a copy of this file called <cam-name>.on


[root@bar-cam ~]# cp /data/etc/thread-1.conf bar-cam-conf.on

Go to the UI turn OFF motion detection and apply changes. Copy the updated config to bar-cam-conf.off.


[root@bar-cam ~]# cp /data/etc/thread-1.conf bar-cam-conf.off


We can use diff to see the difference:

[root@bar-cam ~]# diff bar-cam-conf.on bar-cam-conf.off

--- bar-cam-conf.on
+++ bar-cam-conf.off
@@ -26,7 +26,7 @@
 # @working_schedule


-ffmpeg_output_movies on
+ffmpeg_output_movies off
 height 1080
 stream_quality 85
 threshold 64800
 
 
 Now to turn motion detection (or any other config change using the same principal) we can just copy our specific config copy tot he running and restart MotionEyeOS.
 
 cp /data/etc/bar-cam-conf.off /data/etc/thread-1.conf && /etc/init.d/S85motioneye restart
 
 Return to the UI and check this worked.
 
 For completeness here is the script I run from my homeautomation box (again triggered from a webUI/voice command)
 
[root@bar-cam ~]# nano bar-cam-motion-on.sh
  
#!/bin/bash
ssh admin@bar-cam << EOF
cp /data/etc/bar-cam-conf.on /data/etc/thread-1.conf && /etc/init.d/S85motioneye restart
EOF


[root@bar-cam ~]# chmod +x bar-cam-motion-on.sh

[root@bar-cam ~]# ./bar-cam-motion-on.sh


API would be sweet but I guess this is a good alternative. Great project, great work. Thanks for everyone involved and I hope this post helps someone.

Carl Draper

unread,
Aug 3, 2017, 6:58:48 PM8/3/17
to motioneye
OK so it was real easy in the end :)

Barney Craggs

unread,
Aug 31, 2017, 9:25:10 AM8/31/17
to motioneye
Nice.  Any thoughts on how to invoke those calls from say.. an IFTTT trigger?

Neil O

unread,
Apr 25, 2018, 6:24:01 AM4/25/18
to motioneye


On Thursday, August 31, 2017 at 2:25:10 PM UTC+1, Barney Craggs wrote:
Nice.  Any thoughts on how to invoke those calls from say.. an IFTTT trigger?


I'd really like to know this too.  Ideally a geofence app that turns off the cameras when I'm home and turns them on when I leave.

I've absolutely no idea how to go about this though.  There's an IFTTT App I think - would it be difficult to hook this to the system? 

Mario G.

unread,
Jun 12, 2018, 2:58:56 PM6/12/18
to motioneye
Awesome, I will implement this in Home Assistant using a REST command, I hope it works

M B

unread,
Jun 12, 2019, 3:49:26 AM6/12/19
to motioneye
Hey Guys,

I use these commends too but after a few seconds the status changes again to ACTIVE and the detection is recording again.

Any idea how to fix that?

If i "pause" the detection i get an prompt: Camera 1 Detection paused.

If i "status" i get the answer: Camera 1 Detection status PAUSE

BUT some seconds later "status" again: Camera 1 Detection status ACTIVE

Thx 4 the Help


Dimitri Becue

unread,
Jul 30, 2019, 8:15:40 AM7/30/19
to motioneye
Hello,

Can we imagine the same process to stop / start broadcasting the camera on motioneyeOS? I will need help finding the process / service. an idea?

Best.

dim

Skalma ESSID

unread,
Aug 2, 2019, 2:08:38 PM8/2/19
to motioneye
Hi,

I have the exact same problem...

motionEye Version 0.40
Motion Version 4.2.2
OS Version motionEyeOS 20190427 (on raspberrypi 2)

Does anyone know why motion detection is automatically restarted ?

Thanks.
Reply all
Reply to author
Forward
0 new messages