-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhoneywell.pl
executable file
·136 lines (113 loc) · 3.56 KB
/
honeywell.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/perl -w
use strict;
use WWW::Mechanize;
use HTML::TreeBuilder;
use Data::Dumper;
sub trim($);
our $user;
our $pass;
require('honeywell-auth.pl');
my $agent = WWW::Mechanize->new();
$agent->get("https://rs.alarmnet.com/TotalConnectComfort/");
my $fields = {
'UserName' => $user,
'Password' => $pass,
};
print Dumper $fields;
my $r = $agent->submit_form(form_number => 1,
fields => $fields);
my @links = @{$agent->links};
my @zoneLinks;
for my $link (0..$#links) {
next unless $links[$link][0] =~ /Device\/Control/;
@zoneLinks[scalar(@zoneLinks)] = $links[$link][0];
}
my $page = HTML::TreeBuilder->new_from_content($agent->content());
my $zoneCount = 0;
my @zoneData;
foreach my $div ($page->find_by_tag_name('div')) {
my $id = $div->attr('id') || next;
if ($id eq 'zone-list') {
foreach my $tr ($div->find_by_tag_name('tr')) {
my ($name, $temp, $humidity);
foreach my $td ($tr->find_by_tag_name('td')) {
my $class = $td->attr('class') || next;
if ($class eq 'location-zone-title') {
$name = $td->as_text();
} elsif ($class eq 'zone-temperature') {
$temp = trim($td->as_text());
$temp =~ s/^(\d+).*/$1/;
} elsif ($class eq 'zone-humidity') {
$humidity = trim($td->as_text());
$humidity =~ s/^(\d+).*/$1/;
}
}
if ($name ne '') {
push @zoneData, { name => $name,
temp => $temp,
humidity => $humidity, };
}
}
}
}
foreach my $url (@zoneLinks) {
my $deviceNum = $url;
$deviceNum =~ s/\/TotalConnectComfort\/Device\/Control\/(\d+)/$1/;
$agent->follow_link(url_regex => qr/Device\/Control\/$deviceNum/);
my $outTemp = $agent->content();
$outTemp =~ m/Control.Model.Property.outdoorTemp, (\d+)/;
$outTemp = ${1};
my $outHumidity = $agent->content();
$outHumidity =~ m/Control.Model.Property.outdoorHumidity, (\d+)/;
$outHumidity = ${1};
$zoneData[$zoneCount]{'outTemp'} = $outTemp;
$zoneData[$zoneCount]{'outHumidity'} = $outHumidity;
my $zonePage = HTML::TreeBuilder->new_from_content($agent->content());
## my $outdoorTempDisplay = $zonePage->find_by_attribute("class", "OutdoorTempDisplay");
##Control.Model.Property.outdoorTemp, 50.0000
##my $foo = $zonePage;
##print Dumper $foo;
##print Dumper $outdoorTempDisplay;
# my $outsideTemp = $foo;
## $outsideTemp =~ s/^(\d+).*/$1/;
# $zoneData[$zoneCount]{'outTemp'} = $outsideTemp;
#
# my $outdoorHumidityDisplay = $zonePage->find_by_attribute("class", "OutdoorHumidityDisplay");
# my $outsideHumidity = $outdoorHumidityDisplay->as_text();
# $outsideHumidity =~ s/(\d+).*/$1/;
# $zoneData[$zoneCount]{'outHumidity'} = $outsideHumidity;
#
my $setPoint = $zonePage->find_by_attribute("id", "NonAutoModeTempControls");
foreach my $div ($setPoint->find_by_tag_name('div')) {
my $id = $div->attr('id');
if (defined($id)) {
if ($id eq 'NonAutoHeatSetpt' || $id eq 'NonAutoCoolSetpt') {
if ($div->attr('style') eq 'display: none') {
next;
} else {
my $dataDiv = $div->find_by_attribute("class", "DisplayValue");
$zoneData[$zoneCount]{setPoint} = $dataDiv->as_text();
}
}
}
}
$agent->follow_link(url_regex => qr/Zones/);
$zoneCount++;
}
$agent->follow_link(url_regex => qr/LogOff/);
$zoneCount = 1;
foreach my $zone (@zoneData) {
print "z" . $zoneCount . "t:" . $zone->{'temp'} . " ";
print "z" . $zoneCount . "h:" . $zone->{'humidity'} . " ";
print "z" . $zoneCount . "s:" . $zone->{'setPoint'} . " ";
$zoneCount++;
}
print "ot:" . $zoneData[0]->{'outTemp'} . " ";
print "oh:" . $zoneData[0]->{'outHumidity'} . "\n";
sub trim($)
{
my $string = shift;
$string =~ s/^\s+//;
$string =~ s/\s+$//;
return $string;
}