Monthly Archives: March 2016

Auto turn on electric devices using RF sockets and raspberry pi

Yesterday I wrote a small script to turn on electric heater in my room when temperature is less than 18C.

Below is the bash script :

#!/bin/bash
temp=`node -pe ‘JSON.parse(process.argv[1]).main.temp’ “$(curl -s http://api.openweathermap.org/data/2.5/weather?id=2158177\&APPID=XXXXXXXXXXXXXXXXXXXX\&units=metric)”`
echo “Current temperature “$temp
if [ $(echo “$temp < 18” | bc -l ) -gt 0 ];then
echo “Switching on Heater”
codesend XXXXXXXX
fi;

codesend is the binary which uses GPIO pins on raspberry pi to send RF signal through connected RF transmitter.  I copied source code from RFutils project and tweaked a bit as per my requirements.