Skip to content
Lieven Hollevoet edited this page Sep 22, 2014 · 1 revision

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 <[email protected]></[email protected]>//**
    • //# Changed by Nico Lembrechts for use with voipbuster.com <[email protected]></[email protected]> 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 integrate//**
    • //# 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></username>, <password></password>, <from_telephone_number></from_telephone_number>, <to_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://**
    • //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;//**
    • //}//**
Clone this wiki locally