Hardware Reference
In-Depth Information
You could now create a separate recipe for switching the light off again, and it would be as simple as you'd expect.
However, for improved flexibility, I'll show how to run a separate script that looks also at the body of the e-mail and
processes the message as a whole so that you can include commands to dim or raise the light level. Begin by passing
the subject as an argument 6 and e-mail content (header and body) into STDIN, which is launched from a new recipe:
:0
* ^From - steev.*
* ^Subject: light
|~steev/lightcontrol $SUBJECT
You then use the lightcontrol script to concatenate the body into one long string, separated by spaces, instead
of newlines:
#!/usr/bin/perl
# Skip the header, i.e. any non-empty line
while(<STDIN>) {
last if /^\s*$/;
}
my $body = "";
my $separator = "";
# Begin the message with the subject line, if it exists
if (defined $ARGV[0]) {
$body = $ARGV[0];
$separator = " ";
}
# Then concatenate all other lines
while(<STDIN>) {
chomp;
if ($_ !~/^\s*$/) {
$body .= $separator;
$body .= $_;
$separator = " ";
}
}
You can then process the $body to control the lights themselves, with either straight comparisons (meaning the
text must include the command and only the command) or simple regular expressions to allow it to appear anywhere,
as with the “dim” example.
if ($body eq "light on") {
system("heyu turn e3 on");
} elseif ($body eq "light off") {
system("heyu turn e3 off");
} elseif ($body =~ /light dim (\d+)/) {
system("heyu dimb e3 $1");
}
!LTHOUGH)COULDPARSEITFROMTHEHEADERWHILEINTHEMAINSCRIPT)DOITBYWAYOFADEMONSTRATION
Search WWH ::




Custom Search