Use misterhouse to send SMS messages to your mobile on events.

I am using misterhouse to drive my home automation system in my house. One of the things I like is to receive alerts on certain events. For example when it starts raining and one of the windows is left open I like to know.  A good way to receive alerts is via SMS messages on my mobile phone.  I started coding so that misterhouse can sent SMS alerts.  In the misterhouse code there was already some code to use a service at www.smsboy.com Because I am using voipbuster for my VOIP needs I changed the code for that. Below is the code that creates an Item to use for sending SMS messages .

use strict;
# -----------------------------------------------------------------------
# SMS module for Misterhouse
# Uses your voipbuster account http://voipbuster.com to send an SMS message to your mobile.
# Originally written by Stuart Grimshaw <stuart@smgsystems.co.uk>
# Changed by Nico Lembrechts for use with voipbuster.com <nicoatyow@gmail.com> http://yow.be
#
# (17/04/2009)
#
# It's trivially simple to use, just add the .pm file to either your code
# directory, or the Misterhouse lib directory. Until the module is integrated
# into the next release (and until you upgrade to it) you need to add the
# line:
#
#       use voipbuster_SMS_Item;
#
# somewhere in your code.
#
# To create the object use:
#
#       new voipbuster_SMS_Item(<username>, <password>, <from_telephone_number>, <to_telephone_number>);
#
#       $SMS_voipbuster = new voipbuster_SMS_Item("username", "password", "+32161234567", "+324961234567");
#
# and to send a message use the line:
#
#       $SMS_voipbuster->send("Window left open and it is raining now.");
#
# -----------------------------------------------------------------------
package voipbuster_SMS_Item;
use LWP::UserAgent;
my $smsurl = "https://myaccount.voipbuster.com/clx/sendsms.php?";
sub new {
my($class)=shift(@_);
my($self) = {};
$$self{username} = shift(@_);
$$self{password} = shift(@_);
$$self{from} = shift(@_);
$$self{to} = shift(@_);
bless $self, $class;
return $self;
}
sub send {
my($self, $message) = @_;
my $ua = new LWP::UserAgent;
my $req = $smsurl.("username=$$self{username}&password=$$self{password}&from=$$self{from}&to=$$self{to}&text=$message -- ");
my $res = $ua->get($req);
die "Error at $req\n ", $res->status_line, "\n Aborting"
unless $res->is_success;
}
sub set {
my($self, $voip_user, $voip_pass, $voip_from, $voip_to) = @_;
$$self{username}=$voip_user;
$$self{password}=$voip_pass;
$$self{from}=$voip_from;
$$self{to}=$voip_from;
}

This code is doing the actual work.

In the following code I create an Item

use voipbuster_SMS_Item;
# To create the object use:
#
$SMS_Nico = new voipbuster_SMS_Item("nicoatyow", "********", "+32496*********", "+324**********");
# and to send a message use the line:
#
#$SMS_Nico->send("Mum called your home at 13:15") if $New_Minute;

Once the item is created you can use it in all your misterhouse code files. For example with my rain detector :

if ($state = state_changed $rainsensor){
print_log "Rainsensor is now $state";
$SMS_Nico->send("ALARM !! It's raining and a window left open. ") if ($state eq ON) and state $window_open eq ON;
}

Tags:

One Response to “Use misterhouse to send SMS messages to your mobile on events.”

  1. Bazyestaday Says:

    Phat blogpost, amazing looking weblog, added it to my favs!

Leave a Reply