Question: I've seen quite a few security camera examples and many have options for a duty schedule that activates the camera during certain specified days/hours to set up a routine. However I have fairly dynamic schedule and would like for my security cameras to turn on when our phones are not on the WiFi network. This would be an easy shortcut to "on when we're not home" and prevents it from taking intrusive pictures when we are.

Is there a way to configure OpenCV or Motion, or to run a python script to activate a camera when our phones are off the WiFi network? I would like to take advantage of some features of the above software to email or stream footage, so I would like to avoid redesigning a system from the ground up to do this.

Any advice? Thanks!

Answer: 
You'd need to know either the MAC or IP address of the phones you want to monitor but you could just `ping` or `arping` each one in turn and if none reply start your recording otherwise stop recording. Calling something like this from `cron` might do the trick: 

```
#!/bin/bash
#
# Determine if we should be recording or not by pinging each phone in the list
# and setting the variable to "NO" if any reply. If the variable is still "YES"
# at the end we check if the recording process is running and start it if not.
#

LIST="192.168.123.25 192.168.123.56 192.168.123.13 MyPhone.local 192.168.123.78"

RECORD_CMD="RecordingCommand"

RECORD="YES"    
for HOST in $LIST; do
    ping -c1 "$HOST" &> /dev/null && RECORD="NO"
done

if [ "$RECORD" == "YES" ]; then
    # Start or continue recording?
    if [ $(pgrep -c "$RECORD_CMD") -eq 0 ]; then
        # Not currently recording so we need to start...
        "$RECORD_CMD"
    fi
else
    # Stop recording...
    killall "$RECORD_CMD"
fi

exit 0

```
Your question appears to be about ***activating*** and ***disabling*** the cameras when you are not able to connect to them directly when your phones are not on the same local subnet. So it seems to be about ***networking*** and access to control them, rather than the phones themselves that you reference. That's what I *believe* that I see here.

Since the cameras are on an RFC 1918 non-routable address, when you're away from home you can't connect to 192.168.1.1 for example as it's *not routable across the Internet*. The solution is a VPN. Many routers now have this functionality as standard and make it easy to set up a VPN connection back to your home network just by adding a username and password for the VPN account and off you go. Once you connect to your home router via that VPN connection, you can now be connect to the cameras, switch, etc on their non-public IP addresses.

With a VPN you'd just ssh into the Pi-Cam via it's local address and execute `sudo systemctl stop/start motion` and directly issue commands to control it. Further, with a VPN connection back to your home network, you will be able to view streams from the cameras directly on a web browser on your phone.