Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MQTT ha discovery is incomplete with multiple inverters due to nonunique ids #63 #64

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions eversolar.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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'},
Expand All @@ -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'};

LeighAS marked this conversation as resolved.
Show resolved Hide resolved
my %config_data = (
device => {
identifiers => [
$mqtt_serial,
$mqtt_serial_HA,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why change the variable name?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$mqtt_serial_HA is not a name change as such, its an entirely new local variable to ensure that this one was being used (and correctly assigned) and not the original $mqtt_serial.

I'm still not 100% on whether this is the best way to do this, we shouldn't really need 2 serial variables, this works and it preserved the fidelity of the mqtt publish commands which I didn't want to change.

],
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";
Expand Down