Skip to content

Commit

Permalink
Insteon_Remotelinc: Added Ability to Set Awake Time and To Request Ba…
Browse files Browse the repository at this point in the history
…ttery Status

The following likely only works for i2cs devices, I think all Remotelinc 2 devices are i2cs?  It at least works on rev 1.4.

- set_awake_time sets = sets the time in seconds that the remote will remain awake after sending a command.  The default is 4, it can be set up to 254 seconds, with 255 being always awake.

- get_extended_info = is primarily added to get the battery level.  Battery level is returned as a byte, but the number does not immediately make sense.  I will have to let the batter run down some to better understand what it means.

At the moment, I have the code set to call get_extended_info whenever the all_link_report is received.  This report represents the last message sent by the device before the awake time begins to run.  In the future, an additional function can be added to only call get_extended_info if it hasn't been called in x hours.

N.B. in order for set_awake_time to work properly, the engine version of the device must be known.

hollie#172
  • Loading branch information
krkeegan committed May 10, 2013
1 parent a9e3707 commit 43298d1
Showing 1 changed file with 61 additions and 1 deletion.
62 changes: 61 additions & 1 deletion lib/Insteon/Controller.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ use Insteon::BaseInsteon;
my %message_types = (
%Insteon::BaseDevice::message_types,
bright => 0x15,
dim => 0x16
dim => 0x16,
extended_set_get => 0x2e
);

sub new
Expand Down Expand Up @@ -49,6 +50,65 @@ sub set
return;
}

sub set_awake_time {
my ($self, $awake) = @_;
$awake = sprintf("%02x", $awake);
my $root = $self->get_root();
my $extra = '000102' . $awake . '0000000000000000000000';
$$root{_ext_set_get_action} = "set";
my $message = new Insteon::InsteonMessage('insteon_ext_send', $root, 'extended_set_get', $extra);
$root->_send_cmd($message);
return;
}

sub get_extended_info {
my ($self) = @_;
my $root = $self->get_root();
my $extra = '000100000000000000000000000000';
$$root{_ext_set_get_action} = "get";
my $message = new Insteon::InsteonMessage('insteon_ext_send', $root, 'extended_set_get', $extra);
$root->_send_cmd($message);
return;
}

sub _process_message {
my ($self,$p_setby,%msg) = @_;
my $clear_message = 0;
if ($msg{command} eq 'link_cleanup_report'){
#Queue an get_extended_info request
$self->get_extended_info();
}
if ($msg{command} eq "extended_set_get" && $msg{is_ack}){
$self->default_hop_count($msg{maxhops}-$msg{hopsleft});
#If this was a get request don't clear until data packet received
main::print_log("[Insteon::RemoteLinc] Extended Set/Get ACK Received for " . $self->get_object_name) if $main::Debug{insteon};
if ($$self{_ext_set_get_action} eq 'set'){
main::print_log("[Insteon::RemoteLinc] Clearing active message") if $main::Debug{insteon};
$clear_message = 1;
$$self{_ext_set_get_action} = undef;
$self->_process_command_stack(%msg);
}
}
elsif ($msg{command} eq "extended_set_get" && $msg{is_extended}) {
if (substr($msg{extra},0,6) eq "000001") {
$self->default_hop_count($msg{maxhops}-$msg{hopsleft});
#D10 = Battery;
main::print_log("[Insteon::RemoteLinc] The battery level ".
"for device ". $self->get_object_name . " is: ".
hex(substr($msg{extra}, 20, 2)));
$clear_message = 1;
$self->_process_command_stack(%msg);
} else {
main::print_log("[Insteon::RemoteLinc] WARN: Corrupt Extended "
."Set/Get Data Received for ". $self->get_object_name) if $main::Debug{insteon};
}
}
else {
$clear_message = $self->SUPER::_process_message($p_setby,%msg);
}
return $clear_message;
}

sub is_responder
{
return 0;
Expand Down

0 comments on commit 43298d1

Please sign in to comment.