added tempurature
This commit is contained in:
parent
25428cf5ed
commit
7f68ca2a7a
49
huectl.pl
49
huectl.pl
|
@ -20,13 +20,15 @@ GetOptions(
|
||||||
"id=i" => \(my $RESOURCE_ID),
|
"id=i" => \(my $RESOURCE_ID),
|
||||||
"sensor=i" => \(my $SENSOR_ID),
|
"sensor=i" => \(my $SENSOR_ID),
|
||||||
"battery=i" => \(my $BATTERY),
|
"battery=i" => \(my $BATTERY),
|
||||||
|
"heat" => \(my $HEAT),
|
||||||
"action=s" => \(my $ACTION = "state"),
|
"action=s" => \(my $ACTION = "state"),
|
||||||
"verbose" => \(my $VERBOSE),
|
"verbose" => \(my $VERBOSE),
|
||||||
"debug" => \(my $DEBUG),
|
"debug" => \(my $DEBUG),
|
||||||
|
"pretty" => \(my $PRETTY),
|
||||||
);
|
);
|
||||||
|
|
||||||
my $USAGE = <<"END_USAGE";
|
my $USAGE = <<"END_USAGE";
|
||||||
Usage: $0 bridge-name [-t type] [-i id] [-s sensor] [-b percent] [-a action] [-v] [-d]
|
Usage: $0 bridge-name [-t type] [-i id] [-s sensor] [-b percent] [-a action] [-v] [-d] [-p]
|
||||||
Options:
|
Options:
|
||||||
bridge-name as defined in [HOME]./hue.conf or [HOME]./.hue.conf or /etc/hue.conf
|
bridge-name as defined in [HOME]./hue.conf or [HOME]./.hue.conf or /etc/hue.conf
|
||||||
-t | --type [ lights | sensors | groups | all | trigger ] (default: lights)
|
-t | --type [ lights | sensors | groups | all | trigger ] (default: lights)
|
||||||
|
@ -34,8 +36,9 @@ bridge-name as defined in [HOME]./hue.conf or [HOME]./.hue.conf or /etc/hue.c
|
||||||
-s | --sensor sensor-id
|
-s | --sensor sensor-id
|
||||||
-b | --battery percent of battery level to report on, only relevant with sensors
|
-b | --battery percent of battery level to report on, only relevant with sensors
|
||||||
-a | --action [ on | off | state | bright | relax | morning | dimmed | evening | nightlight ] (default: state)
|
-a | --action [ on | off | state | bright | relax | morning | dimmed | evening | nightlight ] (default: state)
|
||||||
-v | --verbose JSON output
|
-v | --verbose
|
||||||
-d | --debug pretty JSON output
|
-d | --debug JSON output
|
||||||
|
-p | --pretty pretty JSON output (can be a lot)
|
||||||
|
|
||||||
Command examples:
|
Command examples:
|
||||||
$0 bridge1
|
$0 bridge1
|
||||||
|
@ -97,10 +100,11 @@ sub _return_error_with {
|
||||||
|
|
||||||
sub _verify_response {
|
sub _verify_response {
|
||||||
my ($status, $content, $uri) = @_;
|
my ($status, $content, $uri) = @_;
|
||||||
if ($status =~ /^2/ && $VERBOSE) {
|
if ($status =~ /^2/) {
|
||||||
print "URI: $uri\nHTTP RESPONSE: $status\nCONTENT: \n$content\n";
|
print "URI: $uri\nHTTP RESPONSE: $status\n" if ($VERBOSE || $DEBUG);
|
||||||
|
print "CONTENT: \n$content\n" if $DEBUG;
|
||||||
}
|
}
|
||||||
say $json->ascii->pretty->encode(decode_json join '', $content) if $DEBUG;
|
say $json->ascii->pretty->encode(decode_json join '', $content) if $PRETTY;
|
||||||
if ($status !~ /^2/ || $content =~ /error/) {
|
if ($status !~ /^2/ || $content =~ /error/) {
|
||||||
_return_error_with("URI: $uri\nHTTP RESPONSE: $status\nCONTENT: \n$content");
|
_return_error_with("URI: $uri\nHTTP RESPONSE: $status\nCONTENT: \n$content");
|
||||||
}
|
}
|
||||||
|
@ -191,6 +195,8 @@ sub sensors {
|
||||||
my ($resource) = @_;
|
my ($resource) = @_;
|
||||||
my $sensor_objects = _get_json_for($resource);
|
my $sensor_objects = _get_json_for($resource);
|
||||||
my %sensor;
|
my %sensor;
|
||||||
|
my $name;
|
||||||
|
my $temperature;
|
||||||
UNIQUEID:
|
UNIQUEID:
|
||||||
for my $key (keys (%{$sensor_objects})) {
|
for my $key (keys (%{$sensor_objects})) {
|
||||||
if ($sensor_objects->{$key}->{'uniqueid'} && ($sensor_objects->{$key}->{'uniqueid'} =~ /([a-fA-F0-9]{2}:?){8}/)) {
|
if ($sensor_objects->{$key}->{'uniqueid'} && ($sensor_objects->{$key}->{'uniqueid'} =~ /([a-fA-F0-9]{2}:?){8}/)) {
|
||||||
|
@ -200,24 +206,39 @@ sub sensors {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $BATTERY) {
|
if (! $BATTERY && ! $HEAT) {
|
||||||
printf "%4s %-34s %-8s %s (%s)\n", "ID", "Name", "State", "Type", $TYPE;
|
printf "%4s %-34s %-8s %s (%s)\n", "ID", "Name", "State", "Type", $TYPE;
|
||||||
print "################################################################################\n";
|
print "################################################################################\n";
|
||||||
}
|
}
|
||||||
for my $uniqueid (sort keys %sensor) {
|
for my $uniqueid (sort keys %sensor) {
|
||||||
for my $key (sort { $a <=> $b } @{$sensor{$uniqueid}}) {
|
for my $key (sort { $a <=> $b } @{$sensor{$uniqueid}}) {
|
||||||
if (! $BATTERY) {
|
if ($BATTERY) {
|
||||||
if ($sensor_objects->{$key}->{'type'} =~ /ZLLSwitch|ZLLPresence/) {
|
|
||||||
printf "%-39s (%s%%)\n", $sensor_objects->{$key}->{'name'}, $sensor_objects->{$key}->{'config'}->{'battery'};
|
|
||||||
}
|
|
||||||
printf "%4d %-43s %s\n", $key, $sensor_objects->{$key}->{'productname'}, $sensor_objects->{$key}->{'type'};
|
|
||||||
} else {
|
|
||||||
if ($sensor_objects->{$key}->{'type'} =~ /ZLLSwitch|ZLLPresence/) {
|
if ($sensor_objects->{$key}->{'type'} =~ /ZLLSwitch|ZLLPresence/) {
|
||||||
if ($sensor_objects->{$key}->{'config'}->{'battery'} < $BATTERY) {
|
if ($sensor_objects->{$key}->{'config'}->{'battery'} < $BATTERY) {
|
||||||
printf "%-32s battery level %s%%\n", $sensor_objects->{$key}->{'name'}, $sensor_objects->{$key}->{'config'}->{'battery'};
|
printf "%-32s battery level %s%%\n", $sensor_objects->{$key}->{'name'}, $sensor_objects->{$key}->{'config'}->{'battery'};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
elsif ($HEAT) {
|
||||||
|
if ($sensor_objects->{$key}->{'type'} =~ /ZLLPresence/) {
|
||||||
|
$name = $sensor_objects->{$key}->{'name'};
|
||||||
|
}
|
||||||
|
if ($sensor_objects->{$key}->{'type'} =~ /ZLLTemperature/) {
|
||||||
|
if ($sensor_objects->{$key}->{'state'}->{'temperature'}) {
|
||||||
|
$temperature = ($sensor_objects->{$key}->{'state'}->{'temperature'} / 100);
|
||||||
|
printf "%-32s - %.1fC", $name, $temperature;
|
||||||
|
print " (updated: " . unpack('@11 A8', $sensor_objects->{$key}->{'state'}->{'lastupdated'}) . " UTC)";
|
||||||
|
print " - sensor $key" if $VERBOSE;
|
||||||
|
say "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if ($sensor_objects->{$key}->{'type'} =~ /ZLLSwitch|ZLLPresence/) {
|
||||||
|
printf "%-39s (%s%%)\n", $sensor_objects->{$key}->{'name'}, $sensor_objects->{$key}->{'config'}->{'battery'};
|
||||||
|
}
|
||||||
|
printf "%4d %-43s %s\n", $key, $sensor_objects->{$key}->{'productname'}, $sensor_objects->{$key}->{'type'};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -238,6 +259,8 @@ sub groups {
|
||||||
sub daylight_trigger {
|
sub daylight_trigger {
|
||||||
my $light = _get_state_for("lights", $RESOURCE_ID);
|
my $light = _get_state_for("lights", $RESOURCE_ID);
|
||||||
my $sensor = _get_state_for("sensors", $SENSOR_ID);
|
my $sensor = _get_state_for("sensors", $SENSOR_ID);
|
||||||
|
say "Dark: $sensor->{'dark'}, Daylight: $sensor->{'daylight'}, Light On: $light->{'on'}" if ($VERBOSE || $DEBUG);
|
||||||
|
#print (f"Dark: {sensor_state['dark']}, Daylight: {sensor_state['daylight']}, Light On: {sensor_state['daylight']}")
|
||||||
if ($sensor->{'dark'} && ! $light->{'on'}) {
|
if ($sensor->{'dark'} && ! $light->{'on'}) {
|
||||||
_change_state_for("lights", $RESOURCE_ID, $ACTION);
|
_change_state_for("lights", $RESOURCE_ID, $ACTION);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue