Camera motion detection on after leaving home

Hello all,

I have added my cheap Chinese IP camera in the MotionEye addon for HA (rtsp URL).
I’ve been looking a lot for a script that fits my needs but haven’t found one so I thought I should ask you!

What I want to achieve is that when my mobile devices leave the house, is that the MotionEye motion detection is being turned on.
Also when certain lamps are being turned off after a certain time that the motion detection is being turned on.

Can this be done and if so, how would I do that?

Thanks in advance!

2 Likes

For anyone who is trying to achieve this, I ended up configuring it like this.

First, in the motionEye addon change motion_webcontrol from false to true:
After that restart the motionEye addon.

{
  "motion_webcontrol": true,
  "ssl": true,
  "certfile": "fullchain.pem",
  "keyfile": "privkey.pem"
}

In my configuration.yaml I added below code and restarted the server.

shell_command:
  turn_on_motion: 'wget -O- "http://192.168.60.9:7999/1/detection/start" >/dev/null'
  turn_off_motion: 'wget -O- "http://192.168.60.9:7999/1/detection/pause" >/dev/null'

Via the HA GUI I added an automation for turning on and one for turning off motion detection, that created below in the file automations.yaml.

- id: '1578051707162'
  alias: Turn on motion
  description: ''
  trigger:
  - entity_id: device_tracker.cris_s9
    platform: state
    to: not_home
  - entity_id: device_tracker.cris_s9
    platform: state
    to: Work
  condition: []
  action:
  - service: shell_command.turn_on_motion
- id: '1578051857141'
  alias: Turn off motion
  description: ''
  trigger:
  - entity_id: device_tracker.cris_s9
    platform: state
    to: home
  condition: []
  action:
  - service: shell_command.turn_off_motion

(Please let me know if you see something I didn’t configure correctly)

11 Likes

Beautiful and thanks for sharing!
So is this working in a good way you think? No drawbacks that I need to know?

Can you also setup to use the cameras motion detections but only record if the turn_on_motion is activated? Meaning that the MotionEye is completely idle not processing anything until a camera triggers on motion and sends the stream to MotionEye that then records depending on the calue of turn_on_motion?

That is a part of MotionEye meaning you don’t need any HA automation etc to control this :slight_smile:

1 Like

Aha, so that setting means that it only records when the camera itself detects motion? I thought it was the motion handling n MotionEye it referred to.

Hello,

No I have this running for quite a while now and it works like a charm!
What @TheStigh said about the motion triggering is correct, that’s the same as I have it!

1 Like

So (sorry for repeating myself, just want to be 100% sure​:blush:) when you leave your home you enable this setting in MotionEye. MotionEye is then completely idle and doesn’t use any system resources until one of your cameras detect motion. The camera then sends the RTSP stream to MotionEye that does it’s magic and notify you about motion? Sounds awesome :slight_smile:

No, if you want the motion detection to be turned on when you leave your house you will have to create an automation that turns on the motion detection as shown in my previous post.

- id: '1578051707162'
  alias: Turn on motion
  description: ''
  trigger:
  - entity_id: device_tracker.cris_s9
    platform: state
    to: not_home
  - entity_id: device_tracker.cris_s9
    platform: state
    to: Work
  condition: []
  action:
  - service: shell_command.turn_on_motion
- id: '1578051857141'
  alias: Turn off motion
  description: ''
  trigger:
  - entity_id: device_tracker.cris_s9
    platform: state
    to: home
  condition: []
  action:
  - service: shell_command.turn_off_motion

These automations refer to below shell commands:

shell_command:
  turn_on_motion: 'wget -O- "http://192.168.60.9:7999/1/detection/start" >/dev/null'
  turn_off_motion: 'wget -O- "http://192.168.60.9:7999/1/detection/pause" >/dev/null'

Note that in those URLs you see /1/, this refers to the camera channel.

The notification to your phone is being done by MotionEye’s Run a command and Run an end command, these can be found in Motion Detection > Motion Notification.
Remember to turn Motion Detection off in MotionEye after you’ve edited those command since the automations will turn motion detection on/off.

That’s how I was thinking in my head but I was a bit unclear when I wrote it. Thanks for your help! :smiley:

No problem, if you have any further questions just let me know!

Actually, I have one more.
Did you have to do this in order to get it to work from this post?

I’m running HassOS directly on my NUC so I don’t have access to the file system in the same way and can’t access those files.

Hmmm not sure how that works, I’m running Hassio as a VM on my Hyper-V server and I don’t have the motion.conf file on it.
The only config for MotionEye I changed can be found in the MotionEye addon in the Supervisor section of HA.

I do want to point out an obvious thing but just to be sure: Did you change the IP address in the shell command I gave you?

shell_command:
  turn_on_motion: 'wget -O- "http://192.168.60.9:7999/1/detection/start" >/dev/null'
  turn_off_motion: 'wget -O- "http://192.168.60.9:7999/1/detection/pause" >/dev/null'

No I haven’t even gotten started yet :see_no_evil:
Doing a ton of reading just to make sure what I want to do is doable. So if you didn’t change it hopefully I won’t either. Thanks again and I’ll leave you alone now :wink:

What do you want to achieve?
Well I did change it because 192.168.60.9 is the IP for my Home Assistant VM, so you should edit that so it matches the IP address for your HassOS machine (I think you should also be able to use http://localhost:7999 and the rest of the URL).

What I have in my setup (I didn’t mention all of it here):

  • Automation to create a custom sensor every time HA boots
  • The above custom sensor turns on when motion is detected (and off when motion detection ended), this is done via the Run a command and Run an end command in the MotionEye addon
    image
  • Automation to turn motion detection on when I leave the house (shown in my posts above)
  • Automation to turn motion detection off when I get home (shown in my posts above)
  • Automation to turn motion detection on at a specific time in the evening
  • Automation to turn motion detection off at a specific time in the morning
1 Like

So I would basically like to do what you have done.

  • Only recording/processing video streams when I’m not home = my house is armed
  • Use the built in motion detection in the cameras itself instead of using the motion handling in MotionEye, maybe try it if processor usage stays ok

I’m basically trying to find a way to minimize the workload for my NUC and also make me and my guests feel comfortable knowing that no one is being recorded.

What you wrote and your example code was spot on but if I need to edit the file mentioned in my post above I’m out of luck.

Well your first point is being done by the automations to turn motion on/off when you leave your house or get back home.
The second point I cannot help you with since I do use the motion handling from MotionEye (not sure if it can be done with what you want, using motion detection from the camera itself).

And I really don’t know if you need to edit the file you mentioned because we are running different instances and I don’t even have that file.

1 Like

What @criskolkman says is the correct answer, but depending on what you want to achieve;

If you want to record on motion detection when you are away from home - then his reply are totally correct, you need to ‘connect’ MotionEye to HA by webhook and create a routine for this.

On the other hand, if you only need record on ANY motion, even if you’re home - my solution are enough.

Hope that was understandable :upside_down_face:

Perfectly clear, thank you! But I only want to record when I’m away (my alarm is armed). So I’ll keep looking for the ultimate way of achieving this. My dream scenario would be to toggle the cameras power based on a HA sensor, or toggle motion detection in the camera itself based on the same sensor. That way I could make sure that the cameras would only be active when I’m not at home.

Cutting the power to the cameras is one way, and since I will be using POE I could cut the power to my POE switch, but I’m afraid doing so will risk damaging them in the long run and or my NUC or NVR if I take that route instead.

Sorry for the late reply, but when you only want to record when you’re not at home then you could do that with my solution :slight_smile:

1 Like

I’m actually looking to do this same thing! I’m a little confused on what the 7999 port is and just this entire line: turn_on_motion: ‘wget -O- “http://192.168.60.9:7999/1/detection/start” >/dev/null’

I know you mentioned the IP is your HA host but that port… is that just the port your specified in the addon I assume under the Network portion?

also that /1/ where do you get that info from?

Thanks!