From caadd43b245af0a98cf537510bc769d995ace1e4 Mon Sep 17 00:00:00 2001 From: LeighAS Date: Mon, 12 Sep 2022 11:06:37 +0100 Subject: [PATCH 1/2] mqtt inverter serial number update for multiple inverters made serial a local variable to the function where mqtt messages where being created. Also included inverter serial as part of the mqtt data packet being sent. (not strictly necessary but helped with easy debugging) --- eversolar.pl | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/eversolar.pl b/eversolar.pl index 4cadaf6..a2fbe7f 100755 --- a/eversolar.pl +++ b/eversolar.pl @@ -1291,6 +1291,7 @@ sub get_timestamp { # pmu_log("Severity 4: $log_json"); my %mqtt_data = ( + serial => $inverters{$inverter}{'serial'}, pac => $inverters{$inverter}{'data'}{'pac'}, max_power_today => $inverters{$inverter}{'max'}{'pac'}{'watts'}, d365 => $inverters{$inverter}{'data'}{'d365'}, @@ -1312,21 +1313,27 @@ sub get_timestamp { # Subroutine for Home Assistant Device/Entity configuration sub ha_disc_config { + my $mqtt_serial_HA = $inverters{$inverter}{'serial'}; + my %config_data = ( device => { identifiers => [ - $mqtt_serial, + $mqtt_serial_HA, ], manufacturer => "Eversolar", model => $mqtt_inverter_model, name => "Solar Inverter" }, - state_topic => "$mqtt_topic_prefix/$mqtt_serial/$_[0]", - unique_id => "$mqtt_serial\_$_[0]", + state_topic => "$mqtt_topic_prefix/$mqtt_serial_HA/$_[0]", + unique_id => "$mqtt_serial_HA\_$_[0]", state_class => "measurement", ); - if ( $_[0] eq "pac" ){ + if ( $_[0] eq "serial" ){ + $config_data{'icon'} = "mdi:solar-power"; + $config_data{'name'} = "Serial number of inverter"; + + } elsif ( $_[0] eq "pac" ){ $config_data{'icon'} = "mdi:solar-power"; $config_data{'name'} = "PV Solar Power Right Now"; $config_data{'unit_of_measurement'} = "W"; From 8b779f0cabf0c36c82aa82eb19bd64ade2f815b2 Mon Sep 17 00:00:00 2001 From: LeighAS Date: Wed, 21 Sep 2022 09:31:02 +0100 Subject: [PATCH 2/2] Update eversolar.pl fixing indents, originally working on this in notepad++ and used tabs for the spacing as typically that i what i would have used in c#/c++. it wasnt obvious that the document was indented using spaces in notepad++. rededited in vscode and the issue became clear. --- eversolar.pl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/eversolar.pl b/eversolar.pl index a2fbe7f..c24bf3a 100755 --- a/eversolar.pl +++ b/eversolar.pl @@ -1291,7 +1291,7 @@ sub get_timestamp { # pmu_log("Severity 4: $log_json"); my %mqtt_data = ( - serial => $inverters{$inverter}{'serial'}, + serial => $inverters{$inverter}{'serial'}, pac => $inverters{$inverter}{'data'}{'pac'}, max_power_today => $inverters{$inverter}{'max'}{'pac'}{'watts'}, d365 => $inverters{$inverter}{'data'}{'d365'}, @@ -1313,7 +1313,7 @@ sub get_timestamp { # Subroutine for Home Assistant Device/Entity configuration sub ha_disc_config { - my $mqtt_serial_HA = $inverters{$inverter}{'serial'}; + my $mqtt_serial_HA = $inverters{$inverter}{'serial'}; my %config_data = ( device => { @@ -1329,7 +1329,7 @@ sub get_timestamp { state_class => "measurement", ); - if ( $_[0] eq "serial" ){ + if ( $_[0] eq "serial" ){ $config_data{'icon'} = "mdi:solar-power"; $config_data{'name'} = "Serial number of inverter";