Require password to wake computer by specific condition

You can use ControlPlane:

  1. Add a context named home from the contexts tab.
  2. Enable the nearby WiFi network evidence source from the evidence sources tab.
  3. Go to the rules tab and add a nearby WiFi network rule that sets the context to home.
  4. Add two screen saver password actions from the actions tab:

Another option is to add a line like this to crontab:

* * * * * system_profiler SPAirPortDataType|grep -q 'network name'&&x=false||x=true;osascript -e 'tell application "System Events" to tell security preferences to set require password to wake to '$x