Tutorial 44: Text Message Greeter

This tutorial brings together what the past two tutorials were working up: turning your Raspberry Pi into a text messaging greeter who welcomes you home from work! In this tutorial I show you how to scan your LAN for your cellphone and then send a message to you via a text welcoming you home.

I know this isn't the biggest or most interesting project, but the concepts learned can be applied to other projects you may have in mind where you want a reaction based on whether you're home, and the ability to send SMS out from your Pi to your phone. Enjoy!

  • How to scan your LAN for your phone’s IP address.
  • How to send a text message to your phone using Twilio.
  • How to create a greeter that greets you after you’ve been away from the house for more than a couple of minutes.
You can copy / paste the code below if you’re having issues with typos or want a shortcut. However I recommend that you follow along in the tutorial to understand what is going on!

from twilio.rest import Client
import os
from time import sleep
from time import time

account_sid ="XXXXXXXXX" # Put your own Twilio account SID here.
auth_token ="XXXXXXXXX" # Put your own Twilio auth token here.

client = Client(account_sid, auth_token)

phoneIP = "" # Put your own phone's IP address here.

zanStatus = 0 # start off not at home
timeElapsed = 0 # count in seconds how much time has passed
startTime = time()
currentTime = time()

checkFrequency = 10
lonelyTime = 120 # how long I need to be gone to get a reaction

def sendText():
	print("execute the sending of a text here")
	message = client.api.account.messages.create(
		to="+############", # Put your own cellphone number here.
		from_="+#############", # Put your own Twilio number here.
		body="Welcome home Zan!")

while True:
	isZanHome = os.system("ping -c 1 " + phoneIP)

	if isZanHome == 0:
		print("Zan is home!")
		startTime = time()
		if zanStatus == 0:
			zanStatus = 1
			print("We should send a text!")
		print("Zan is not home")
		if timeElapsed > lonelyTime and zanStatus == 1:
			print("Zan is really gone.")
			zanStatus = 0
			startTime = time()
	currentTime = time()
	timeElapsed = currentTime - startTime


To be able to accomplish this tutorial you need to have a Twilio account setup. You can setup your account by following the link below: