Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Toggle motion detection on/off via API or else #800

Open
rafik24 opened this issue Feb 20, 2018 · 24 comments
Open

Feature Request: Toggle motion detection on/off via API or else #800

rafik24 opened this issue Feb 20, 2018 · 24 comments

Comments

@rafik24
Copy link

rafik24 commented Feb 20, 2018

Hi Ccrisan,

I use motion eye and i would like to enable motion detection and recording only when i arm my home alarm and would need a way to do this in motioneye.

I guess i could stop the service and shuffle files around but i want to make sure i am not too intrusive.

Thanks,
Rafik

@formula0ne
Copy link

I second this, could not find any way to do this! Or is there a way?

@jasaw
Copy link
Contributor

jasaw commented Mar 15, 2018

A more elegant way is to implement a REST API in motion software to support this. Try convincing motion developers to implement this.

@janpascal
Copy link

janpascal commented Jun 4, 2018

There is a way - motioneye runs motion, which has a web control port (you can find the port number in the motion.conf configuration file, usually located in /etc/motioneye/motion.conf). I use it from my home alarm system to only run motion detection when the alarm system is armed, like the thread starter suggests.

To start motion detection, run a command like

wget -O- "http://192.168.1.14:7999/1/detection/start" >/dev/null

The '1' is for the camera number.

To stop (pause) motion detection, run something like

wget -O- "http://192.168.1.14:7999/1/detection/pause" >/dev/null

You can use a web browser pointed at http://192.168.1.14:7999 to interactively control the motion instance used by motioneye.

@schneivo77
Copy link

There is a way - motioneye runs motion, which has a web control port (you can find the port number in the motion.conf configuration file, usually located in /etc/motioneye/motion.conf). I use it from my home alarm system to only run motion detection when the alarm system is armed, like the thread starter suggests.

To start motion detection, run a command like

wget -O- "http://192.168.1.14:7999/1/detection/start" >/dev/null

The '1' is for the camera number.

To stop (pause) motion detection, run something like

wget -O- "http://192.168.1.14:7999/1/detection/pause" >/dev/null

You can use a web browser pointed at http://192.168.1.14:7999 to interactively control the motion instance used by motioneye.

This doesn't work for me.
I tried it with CURL and Postman and it seems that there is no server running on that port. I used the IP from the Raspberry Pi on which MotionEyeOS is running and the port which I found in the file /data/etc/motion.conf.

Am I missing anything?

@kabadisha
Copy link

kabadisha commented Jan 11, 2019

This doesn't work for me.
I tried it with CURL and Postman and it seems that there is no server running on that port. I used the IP from the Raspberry Pi on which MotionEyeOS is running and the port which I found in the file /data/etc/motion.conf.

Am I missing anything?

@schneivo77,
I had the same issue. It seems that by default the web control port is only accessible, literally from localhost which is literally the machine motioneyeos is running on (a raspberry pi in my case).

To enable access to that port from other machines, you have to ssh onto the device and edit /data/etc/motion.conf
Change webcontrol_localhost on to webcontrol_localhost off and then reboot the camera.

After that, you should be able to access the URLs :-)

It's a bit confusing in my opinion. I think it would be more clear if the property was called something like webcontrol_restrict_to_localhost.

@kabadisha
Copy link

I have created a script that runs on my router and can detect if my phone is connected to the wifi network. If it is, it disables motion detection using the web control method above.

You can find the code here: https://gist.github.com/kabadisha/a87e50311d3ed4589f17a6e37c574a44

@tobiaslohr
Copy link

Hi @ccrisan,
I'm sure the topic is not new to you. Are there any thoughts about adding an API to MotionEye to unlock integrations into (open) Home Automation systems?

@schneivo77
Copy link

@schneivo77,
I had the same issue. It seems that by default the web control port is only accessible, literally from localhost which is literally the machine motioneyeos is running on (a raspberry pi in my case).

To enable access to that port from other machines, you have to ssh onto the device and edit /data/etc/motion.conf
Change webcontrol_localhost on to webcontrol_localhost off and then reboot the camera.

After that, you should be able to access the URLs :-)

It's a bit confusing in my opinion. I think it would be more clear if the property was called something like webcontrol_restrict_to_localhost.

Now it works! Nice! Thanks a lot! :)

@hamiltont
Copy link

Note from Motion documentation (https://motion-project.github.io/motion_config.html#Options_Stream_Webcontrol). I plan to use this feature, but wanted to share this in case anyone else was curious about the security risks of turning webcontrol_localhost to off

ALERT! Security Warning! This feature also means you have to pay attention to the following.
Anyone with access to the remote control port (http) can alter the values of options and save files anywhere on your server with the same privileges as the user running Motion. They can execute any command on your computer with the same privileges as the user running Motion. Anyone can access your control port if you have not either limited access to localhost or limited access using firewalls in the server. You should always have a router between a machine running Motion with remote control enabled and the Internet and make sure the Motion control port is not accessible from the outside. Also make sure to adjust the webcontrol_parms to the lowest level possible.
If you limit control port to localhost you still need to take care of any user logging into the server with any kind of terminal session.
Run Motion as a harmless user. DO NOT RUN AS ROOT!!

@ccrisan
Copy link
Collaborator

ccrisan commented Jun 9, 2019

@hamiltont indeed that setting is off by default in motionEye and should probably be left that way unless the unit runs in a local network where access is properly controlled.

@kabadisha
Copy link

Good call @hamiltont and @ccrisan. I do run my cameras on a private local network, so no issue. I would be surprised if anyone was running their camera directly connected to the internet, but I guess statistics says that someone somewhere will...

@pietje666
Copy link

I have created a script that runs on my router and can detect if my phone is connected to the wifi network. If it is, it disables motion detection using the web control method above.

You can find the code here: https://gist.github.com/kabadisha/a87e50311d3ed4589f17a6e37c574a44

Hi i would like to use your script, do you have installation guide lines somewhere?
Because how do i run scripts on a router? Right now i have TP-link archer c7 with stock firmware. Do i need to flash DD-WRT firmware on it in order to run the script? And where should i put the script then? (was looking overhere https://wiki.dd-wrt.com/wiki/index.php/Script_Execution) But i do not see any logical place i would think it should run after any devices makes a connection?

@pietje666
Copy link

@kabadisha not sure if you get notifications if i quote you so tagging you as well

@kabadisha
Copy link

kabadisha commented Jul 25, 2019

@pietje666 This is not a simple answer and will be quite a learning rabbit hole for you by the sounds of it, but I'll try and point you in the right direction :-)

In order for the script to work, you need the following things:

  • Ability to put the script somewhere on non-volatile (so it sticks around between reboots) storage somewhere on your router and ability to make it executable with command chmod +x
  • Ability to install the script in the router's crontab in order to schedule it's execution every few mins.
  • A router who's firmware supports the wl -i eth1 assoclist command or has something similar that you can change the script to use instead. I have no idea if DD-WRT supports that command, but there is a decent chance. You might want to ask someone on the DD-WRT forum. I use the Merlin firmware on an Asus router.

All of the above are probably not available on any stock firmware, so something like DD-WRT or Tomato is your best bet. The wiki and forums for those are the best place to find out how to install them and how to do the above once you have.

The above will also be fiddly to learn how to do, especially for someone who is not mega familiar with Unix and the command line, so Google and patience are your friends.

Hope that points you in the right direction :-)

@pietje666
Copy link

@kabadisha thanks for the explanation. I got it working now using dd-wrt and cron job had to alter your script a bit since my router did not work with wl command had to use wl_atheros instead.

@piachuPL
Copy link

I make python script to make ON/OFF motion detection by button i think that can help somebody
https://github.com/piachuPL/Motionoffon/

@rafik24
Copy link
Author

rafik24 commented Sep 13, 2019 via email

@divemasterjm
Copy link

i use hassOS on a virtualbox, can you please tell me where to find /data/etc/motion.conf ?

@MYeager1967
Copy link

I know this is probably a long shot, but can a still picture be taken by webcontrol?

@xraywinedrinker
Copy link

xraywinedrinker commented Sep 11, 2020

There is a way - motioneye runs motion, which has a web control port (you can find the port number in the motion.conf configuration file, usually located in /etc/motioneye/motion.conf). I use it from my home alarm system to only run motion detection when the alarm system is armed, like the thread starter suggests.

To start motion detection, run a command like

wget -O- "http://192.168.1.14:7999/1/detection/start" >/dev/null

The '1' is for the camera number.

To stop (pause) motion detection, run something like

wget -O- "http://192.168.1.14:7999/1/detection/pause" >/dev/null

You can use a web browser pointed at http://192.168.1.14:7999 to interactively control the motion instance used by motioneye.

I would like to turn motion detection on/off via webcore when my location mode in smartthings is away. Can this command be sent via webcore and if so, do you know the proper web request format?

Edit: Once I set web control to off I was able to send a GET request with the http info from webcore to start and stop motion detection running on my local machine.

@shooftie
Copy link

shooftie commented Oct 4, 2020

Is it just me or does the status of motion detection not update in the MotionEye UI? I understand that we are sidestepping MotionEye by fondling Motion directly but it would be helpful to see this represented in the MotionEye UI.

My assumption was that MotionEye was simply depicting the underlying Motion config but this would seem not to be the case.

@MYeager1967
Copy link

There are many things that don't change in motionEye when you change them in motion via webcontrol. They get out of sync when you manipulate motion directly...

@jbaragry
Copy link

jbaragry commented Jan 18, 2021

I can start and pause detection through the API successfully but I notice notifications aren't sent when motion is started from the API rather than motioneye. (webhook notification)
I guess this is part of motioneye rather than motion. Anyone know how to notifications could be enabled through an API?

@Dan1jel
Copy link

Dan1jel commented Feb 3, 2023

Just a hint for them like me who tried to find this solution and this took a while for me to get it to work, first, create the file inside /data/etc/ , (not /etc/xxx) with touch /data/etc/alarm_off_1 and insde that file /data/etc/alarm_off_1 add the following below:

#!/usr/bin/bash
curl http://localhost:8080/0/detection/pause

and for /data/etc/alarm_on_1 add the following below:

#!/usr/bin/bash
curl http://localhost:8080/0/detection/start

remember to change localhost (could work with IP adress) and the port (8080 in this example) and camera id (0 in this example) to your configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests