Venstar Status Perl Program

The Venstar thermostat has a little-known API (application programming interface) that one can use to control and query it.  This Perl program gets the current status of the Venstar and reports it to HCA.

use LWP::UserAgent;
# use Data::Dumper;
# set initial values for hca flag values
my $heattemp = “0”;
my $cooltemp = “0”;
my $spacetemp = “0”;
my $venmode = “0”;
my $venstate = “0”;
my $venstatus = “0”; # use to report status of inquiry
# set up xfer file
my $outfile = “venreport.txt”;  #picked up by hca
my $outln = “”;
# create user agent and request for venstar
my $ua = new LWP::UserAgent;
my $req = new HTTP::Request ‘GET’,’http://192.168.2.148/query/info’;
# fetch info from venstar
my $resp = $ua -> request($req);
# see if it ended ok
if ($resp->is_success) {
my $message = $resp->decoded_content;
#    print “Received reply: $message\n”;
# remove quotes and brackets from venstar decoded response
$message =~ tr/”//d;
$message =~ tr/{//d;
$message =~ tr/}//d;
#    print “tempmsg: $message\n”;
# create a hash out of the remaining string
my %venhash = split /[,:]/, $message;
# pull out values of interest from hash
$heattemp = $venhash{“heattemp”};
$cooltemp = $venhash{“cooltemp”};
$spacetemp = $venhash{“spacetemp”};
$venmode = $venhash{“mode”};
$venstate = $venhash{“state”};
#    print Dumper \%venhash;
#    print “heattemp: $heattemp\n”;
$venstatus = “0”;  # indicate success to hca
$thisline = “venheatset=” . $heattemp . “\n”;
$outln = $outln . $thisline;
$thisline = “vencoolset=” . $cooltemp . “\n”;
$outln = $outln . $thisline;
$thisline = “vencurrtemp=” . $spacetemp . “\n”;
$outln = $outln . $thisline;
$thisline = “venmode=” . $venmode . “\n”;
$outln = $outln . $thisline;
$thisline = “venstate=” . $venstate . “\n”;
$outln = $outln . $thisline;
$thisline = “venqstatus=” . $venstatus . “\n”;
$outln = $outln . $thisline;
}
else {
#    print “HTTP POST error code: “, $resp->code, “\n”;
#    print “HTTP POST error message: “, $resp->message, “\n”;
$venstatus = “1”;  # indicate failure to hca
$outln = “venqstatus=” . $venstatus . “\n”;
}
# either good or not, build hca file
open OUTPUT, “> $outfile” or die “Output file open error: $!”;
print OUTPUT $outln;
close OUTPUT;

Arduino, Venstar, Wemos, HCA, etc.