28 October, 2013

Home automation: second round

Some time ago I briefly mentioned here the main concepts behind the project. Nothing has changed dramatically, except that I realized that my SMSgate solution was outdated. The phone battery was seriously deteriorated and I also realized that it is not that easy to just replace the phone anymore.

Well, I had an old Android phone (HTC Wildfire) that was essentially lying unused for quite some time. There is not so much that one can do with this old phone... but it turned out it works just perfectly to send and receive SMS and much more.

If you are in the "business" of home automation and you have Android device, Tasker is a MUST HAVE! To send and receive SMS messages I use SMS Gateway (I could not find an easy way to send SMS from external device via Tasker).


Briefly: I have changed the original python code to send SMS via SMS Gateway via HTTP GET request from RPi and then I have slightly modified the example, so I can control stuff by SMS. It is very clean and simple solution.

Now, since I have web server on which I get the notifications from the SMS Gateway I can simply use the same code to handle events from Tasker! This is how I get notifications on call - piece of cake. I have added, at the end of the post, an example how to switch on/off device 2 via tdtool.

Essentially, I have replaced the old GSM SMSgate with better and open the possibilities for many more options.

In case of power failure - the Android phone can still operate, so I get an SMS that something went wrong (done in Tasker)... or ... I have hooked the charger to one of the remote switches and turn it on when the battery gets below 40% and switch it off again when the phone is fully charged.

On my current phone, I have profile in Tasker to silence my phone based on my Google calendar appointments. It is extremely easy to tune such profile to schedule events that will tun on/off or execute predefined tasks.

Alternative Internet access point - I have not done it but it is possible in principle that the phone can provide alternative connection in case of loss of the common connection.

One can use the Android phone as an "external display" or at least to show some relevant information on demand. The screen is too small and the phone too weak to run VNC client on the Wildfire.

Remote camera: Great feature but not with this phone. I have tried some monitoring software and tested it with my cat. It teaks about 2 seconds after the trigger for the phone to take a picture - needles to say the cat is already gone. With better phone this should be a breeze.

Well, for the rest of the features that one can use an Android phone, actually you do not need the Raspberry Pi, so it is irrelevant to this post. Or it starts to look that the RPi is just an interface for controlling the switches... Hm, this means that if you have the Telldus Net you might just get away without using the RPi at all...

Shake the phone, bluetooth events (well this can be easily done on RPi as well), light level, orientation of the phone, proximity sensor - all done with Tasker.

SMSgateway.php code:
<?php
//setup PHP UTF-8 stuff
setlocale(LC_CTYPE, 'en_US.UTF-8');
mb_internal_encoding("UTF-8");
mb_http_output('UTF-8');

//read parameters from HTTP Get URL
$phone =     $_GET["phone"];
$smscenter = $_GET["smscenter"];
$text_utf8 = rawurldecode($_GET["text"]);

//if parameters are not present in HTTP url, they can be also present in HTTP header
$headers = getallheaders();
if (empty($phone)) {
        $phone = $headers["phone"];
}
if (empty($smscenter)) {
        $smscenter = $headers["smscenter"];
}
if (empty($text_utf8)) {
        $text_utf8 = rawurldecode($headers["text"]);
}//write reply to HTTP header

$reply_header = rawurlencode($reply_utf8);
header('Content-Type: text/html; charset=utf-8');

if($phone=="xxxxxxxxxxx" && $text_utf8=="D_on:2")   { exec('tdtool -n 2&');};
if($phone=="xxxxxxxxxxx" && $text_utf8=="D_off:2")  { exec('tdtool -f 2&');};
?>

No comments: