Introduction: Monitoring Your Kids' Online Electronics Usage With SmartThings and a Raspberry Pi

This is an idea that I have about using the Raspberry Pi to act as a constant checker of what electronic devices are registered on the home wifi network, and then update the home automation hub accordingly (in this case SmartThings).

The home automation hub can then action upon the information provided by the Raspberry Pi, be it immediate notifications that the TV or tablet is switched on, or post-reports generated from the hub's event logs, showing when and what device was switched on.

Pardon the rudimentary bash scripting!

Step 1: Write a Fping Bash Script That Would Ping All Ip Addresses in the Network

The following command does a ping of all devices on the network, then pipes the output to a csv file:

/usr/bin/fping -a -r 0 -g -d 192.168.1.0/24 | grep -v 'ICMP' &> /home/pi/hosts.csv

Step 2: Read the Contents of the Fping to Determine Which Device Is Currently Switched On.

The electronic devices in my house have a static IP address. Eg the TV is always 192.168.1.67, etc. Hence I'm able to write custom IF statements like below:

ARRAY=($(</home/pi/hosts.csv))

for each in "${ARRAY[@]}"

do

if [ $each == "192.168.1.67" ] then echo "TV Found!"

Step 3: Use Curl Commands to Control the on or Off of a SmartThings Virtual Device

For SmartThings, we are able to make virtual devices, then expose the devices as REST endpoints. I won't be going into those areas as they have nothing to do with the Raspberry Pi, but the above screenshot shows a TV virtual device that is switched on. The following command in the bash script is what is used to turn on this device: (where X is the personal authorization and device details)

curl -H "Authorization: Bearer X" "https://graph.api.smartthings.com/api/smartapps/installations/X/switches/X/off"

Step 4: Schedule the Bash Script in a Cron Job to Run Every Minute.

The last step would be to install Cron on the Raspberry Pi, then schedule the written script to run every minute.

sudo apt-get install gnome-schedule

crontab -e

Step 5: Leave the Raspberry Pi On, and Let It Flag Your Electronice Devices As Up or Down.

So the end result is that the Raspberry Pi will check every minute about which device is on, and update SmartThings accordingly, acting as your very own electronics monitor for your kids!

For more home automation related articles, do take a look at my blog:

http://www.smarterhomes.com.sg/ha-news

Thanks!