From 1c9eb6f30fa01af62ba896900efaf7ceac8c955d Mon Sep 17 00:00:00 2001 From: hplato Date: Wed, 17 Feb 2021 16:15:40 -0700 Subject: [PATCH] added tasmota options to read_table_A, revised RRD support --- lib/Tasmota_HTTP_Item.pm | 41 +++++++++++++++++++++++++--------------- lib/read_table_A.pl | 26 ++++++++++++++++--------- 2 files changed, 43 insertions(+), 24 deletions(-) diff --git a/lib/Tasmota_HTTP_Item.pm b/lib/Tasmota_HTTP_Item.pm index 19490c953..ec845a84e 100755 --- a/lib/Tasmota_HTTP_Item.pm +++ b/lib/Tasmota_HTTP_Item.pm @@ -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}) { @@ -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'); + } } } @@ -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 } @@ -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}); diff --git a/lib/read_table_A.pl b/lib/read_table_A.pl index 5f486f997..b9e2f6c38 100644 --- a/lib/read_table_A.pl +++ b/lib/read_table_A.pl @@ -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";