How I automatically notify my family that I am close to home (most likely parking the car)

Introduction

For many reasons I find it very useful to let my family know that I am getting very close to the house. Mainly because my wife would be able to unlock the door (if she is close by and knows that I will be coming up stairs carrying a lot of grocery bags)

So I thought about a way to do that and I came up with this plan:

  1. Have something running on the Raspberry Pi at home listing to a trigger of some kind to play a sound when I get close.
  2. Use Tasker app to trigger a call to the server based on my phone location

Raspberry Pi Server

On the raspberry pi I have a simple server listening to the http requests on a certain port.

The code is as follows:

#!/usr/bin/env python
"""
Very simple HTTP server in python.

Usage::
    ./dummy-web-server.py [<port>]

Send a GET request::
    curl http://localhost

Send a HEAD request::
    curl -I http://localhost

Send a POST request::
    curl -d "foo=bar&bin=baz" http://localhost

"""
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
import SocketServer
from subprocess import call

class S(BaseHTTPRequestHandler):
    def _set_headers(self):
        self.send_response(200)
        self.send_header('Content-type', 'text/html')
        self.end_headers()

    def do_GET(self):
        self._set_headers()
        self.wfile.write("<html><body><h1>hi!</h1></body></html>")

    def do_HEAD(self):
        self._set_headers()
        
    def do_POST(self):
        # Doesn't do anything with posted data
        self._set_headers()
        self.wfile.write("<html><body><h1>POST!</h1></body></html>")
        length = int(self.headers['Content-length'])
        data = self.rfile.read(length)
        if '<SOME STRING TO MAKE SURE NO ONE ELSE IS REQUESTING THIS>' in data:
            call(["omxplayer", "bell.mp3"])

def run(server_class=HTTPServer, handler_class=S, port=80):
    server_address = ('', port)
    httpd = server_class(server_address, handler_class)
    print 'Starting httpd...'
    httpd.serve_forever()

if __name__ == "__main__":
    from sys import argv

    if len(argv) == 2:
        run(port=int(argv[1]))
    else:
        run()

This server runs at boot with a cronjob in the crontab

# Runs the Iam Here server to listen to input from the phone runs at boot
@reboot /usr/bin/python /home/pi/iamhere/server.py <PORT NUMBER> &>/dev/null

If the request is made to that port and the security string matches, then I user omxplayer to play an mp3 bell sound.

I have this small speaker attached to the raspberry pi

Hype-HY-525-BT-Portable-Mini-Bluetooth-v2-0-Speaker-Pepper-Black__41HvHlcVmGL

Phone Trigger Using Tasker

In tasker I have a profile that detects when I am close to the house. I do not use GPS or Wifi location because I have those off most of the time. I use GSM cell tower location since that is always on and does not drain the battery (extra battery consumption)

Here is how my profile looks:

profile1

 

I use that profile to also turn on and off wifi when I get close/away from home, so I combined all the actions in two tasks and enter task called “NEAR HOME” and an exit task called “AWAY FROM HOME”

NEAR HOME

nearhome

This task performs a collection of other tasks, such as turning wifi on, and sending the trigger to the raspberry pi to play the bell sound.

AWAY FROM HOME

awayfromhome

This simply turns off wifi when I leave home.

Problems with GSM location detection while in call

When starting a phone call, the GSM location detection does not work. I am not sure if the phone switches to a different cell tower when a call is active. I did notice the signal changing from LTE during calls.

This problem causes the NEAR HOME task to be performed even when I am at home once the call is completed and back to normal

I tried scanning for the GSM tower while on a call to include that tower in the profile, but that did not work.

The solution was to add a Stop task action if the wifi matches my home wifi SSID’s. So if I am connected to my home wifi, then I do not perform the NEAR home (or AWAY FROM HOME) task since I am already at home.

4 thoughts on “How I automatically notify my family that I am close to home (most likely parking the car)”

Leave a Reply