Camera motion detection on after leaving home

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!

Hello @snipes040,

Most of it is explained in post #2.

In the Supervisor > MotionEye > Configuration you need to set motion_webcontrol to true.
Once you have done that it will open port 7999 on you HA IP (go to http://YOUR_HA_IP:7999 in your browser (do NOT open this port from the internet to your server)).

The 1 in /1/ is just the camera ID MotionEye gives your camera:
image

This is the same ID as being used in http://YOUR_HA_IP:7999

And the whole line:

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

This is a shell_command as explained in Camera motion detection on after leaving home

Awesome thanks @criskolkman for the explanation, I guess I was just confused because it doesn’t seem to work for me. When I run the shell command it returns code: 1. I also can’t browse to my HA IP with port 7999 but it is probably something to do with my setup since I’m using traefik in docker for my HA SSL setup.

Thanks!

@snipes040 Don’t really know about that one.
Did you set motion_webcontrol to true in your MotionEye config and restart the addon after that?

I’ve been trying to get it going for days, but somehow everything doesn’t work … what should I do first? does the shell variant still work? I ask for help … I’ve been trying to get it going for days, but somehow it doesn’t work … what should I do first? does the shell variant still work? I use a Raspberry 4 HA + Motioneye addon. which settings do I have to make so that communication works?

Did you edit the IP address in the shell command to point to your own HA server?