Skip to content

Commit

Permalink
added tasmota options to read_table_A, revised RRD support
Browse files Browse the repository at this point in the history
  • Loading branch information
hplato committed Feb 17, 2021
1 parent 0402015 commit 1c9eb6f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 24 deletions.
41 changes: 26 additions & 15 deletions lib/Tasmota_HTTP_Item.pm
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,19 @@ sub new {
}
$self->{ack} = 0;
$self->{last_http_status};

$self->{heartbeat_timestamp} = 0;
$self->{heartbeat_timer} = new Timer;
$self->{heartbeat_timer}->set(60);

if (( $options =~ m/nohb/i ) or ( $options =~ m/noheartbeatb/i )) {
$self->{heartbeat_enable} = 0;
&main::print_log("[Tasmota_HTTP::Item] " . $self->{address} . " heartbeat check DISABLED" );

} else {
$self->{heartbeat_enable} = 1;
$self->{heartbeat_timestamp} = 0;
$self->{heartbeat_timer} = new Timer;
$self->{heartbeat_timer}->set(60);
&main::print_log("[Tasmota_HTTP::Item] " . $self->{address} . " heartbeat check enabled with 60 second timeout" );

}
my $mode = "synchronous get";

if ($self->{async}) {
Expand Down Expand Up @@ -338,10 +347,12 @@ sub process_check {
$self->{cmd_process}->start();
}
}

if ($self->{heartbeat_timer}->expired()) {
&main::print_log("[Tasmota_HTTP::Item] $self->{address} WARNING. Lost heartbeat. Device might be offline");
$self->SUPER::set( 'unknown', 'heartbeat');
if ($self->{heartbeat_enable}) {

if ($self->{heartbeat_timer}->expired()) {
&main::print_log("[Tasmota_HTTP::Item] $self->{address} WARNING. Lost heartbeat. Device might be offline");
$self->SUPER::set( 'unknown', 'heartbeat');
}
}
}

Expand Down Expand Up @@ -474,14 +485,14 @@ sub new {
"1" => "on",
};

$self->{RRD} = 1;
$self->{RRD} =1 if ( $options =~ m/rrd/i );
$self->{RRD} = 0;
$self->{RRD} = 1 if ( $options =~ m/rrd/i );

if ($self->{RRD}) {
$self->{RRD_filename} = $::config_parms{data_dir} . "/rrd/" . $self->{address} . ".rrd";
unless ( -e $self->{RRD_filename}) {
&main::print_log("[Tasmota_HTTP::Switch_PowerMon] $self->{address} Creating RRD file $self->{RRD_filename} for power usage");
create_rrd($self->{RRD_filename});
$self->set_rrd($::config_parms{data_dir} . "/rrd/" . $self->{address} . ".rrd","power,current");
unless ( -e $self->get_rrd()) {
&main::print_log("[Tasmota_HTTP::Switch_PowerMon] $self->{address} Creating RRD file " . $self->get_rrd() . " for power usage");
create_rrd($self->get_rrd());
}
&::MainLoop_post_add_hook( \&Tasmota_HTTP::Switch_PowerMon::update_rrd, 0, $self ); #check for $New_Minute and the update the RRD with the maximum value during the last minute
}
Expand Down Expand Up @@ -525,7 +536,7 @@ sub reset_power_state {
sub update_rrd {
my ($self) = @_;
if ($main::New_Minute) {
my $rrd = RRD::Simple->new( file => $self->{RRD_filename} );
my $rrd = RRD::Simple->new( file => $self->get_rrd() );
#Use maximum values in the minute to avoid the loss of any power spikes in that minute
&main::print_log("[Tasmota_HTTP::PowerMon] $self->{address} Writing to RRD: power=" . $self->{monitor}->{maxpower} . " current=" . $self->{monitor}->{maxcurrent}) if ($self->{debug});

Expand Down
26 changes: 17 additions & 9 deletions lib/read_table_A.pl
Original file line number Diff line number Diff line change
Expand Up @@ -1973,21 +1973,29 @@ sub read_table_A {
}
elsif ( $type eq "TASMOTA_HTTP_SWITCH" ) {
require Tasmota_HTTP_Item;
my ( $output, $options );
( $address, $name, $output, $grouplist, $options ) = @item_info;
$object = "Tasmota_HTTP::Switch('$address', '$output', '$options')";
my ( $output );
( $address, $name, $output, $grouplist, @other ) = @item_info;
$other = join ',', @other ; # Quote data
$other =~ s/^[\'\"]//; #strip out quotes in case they are included
$other =~ s/[\'\"]$//;
$object = "Tasmota_HTTP::Switch('$address', '$output', '$other')";
}
elsif ( $type eq "TASMOTA_HTTP_SWITCH_POWERMON" ) {
require Tasmota_HTTP_Item;
my ( $output, $options );
( $address, $name, $output, $grouplist, $options ) = @item_info;
$object = "Tasmota_HTTP::Switch_PowerMon('$address', '$output', '$options')";
my ( $output );
( $address, $name, $output, $grouplist, @other ) = @item_info;
$other = join ',', @other; # Quote data
$other =~ s/^[\'\"]//; #strip out quotes in case they are included
$other =~ s/[\'\"]$//;
$object = "Tasmota_HTTP::Switch_PowerMon('$address', '$output', '$other')";
}
elsif ( $type eq "TASMOTA_HTTP_FAN" ) {
require Tasmota_HTTP_Item;
my ( $options );
( $address, $name, $grouplist, $options ) = @item_info;
$object = "Tasmota_HTTP::Fan('$address', '$options')";
( $address, $name, $grouplist, @other ) = @item_info;
$other = join ',', @other ; # Quote data
$other =~ s/^[\'\"]//; #strip out quotes in case they are included
$other =~ s/[\'\"]$//;
$object = "Tasmota_HTTP::Fan('$address', '$other')";
}
else {
print "\nUnrecognized .mht entry: $record\n";
Expand Down

0 comments on commit 1c9eb6f

Please sign in to comment.