Computer and IT knowledge - things to know
deye 600 or 800w microinverter (for example for balkonkraftwerk), how to read out data using a script? in my case a perl script?
##########################################################################################
# >> here is a solution: getDeyePowergenerationData.pl
##########################################################################################
cat getDeyePowergenerationData.pl
#!/usr/bin/perl
use LWP::UserAgent;
use HTTP::Request::Common;
use Getopt::Long;
use strict;
##########################################################################
#
# getDeyePowergenerationData.pl
#
# get some data from a deye inverter like the current power, firmware, serial...
#
# use the parameter --checkmk if you want to get the output in checkmk output format,
# then you can use the script as an individual script in checkmk!
# (Individual program call instead of agent access)
#
# usage:
# ./getDeyePowergenerationData.pl [--checkmk] [--debug] <ip_address> <name> <username> <password>
#
# (c) sys4com 2023
#
##########################################################################
my $version='s4c-2023-04-20';
my ($ip_address, $name, $checkmk, $debug, $username, $password);
# Parse command line options
GetOptions(
'checkmk' => \$checkmk,
'debug' => \$debug
) or die "Usage: $0 [--checkmk] [--debug] <ip_address> <name> <username> <password>\n";
# Get the IP address and name from remaining command line arguments
($ip_address, $name, $username, $password) = @ARGV;
# Check if arguments were provided
unless (defined $ip_address && defined $name && defined $username && defined $password) {
print "Usage: $0 [--checkmk] [--debug] <ip_address> <name> <username> <password>\n";
exit;
}
# Set the URL of the page to fetch
my $url = "http://$ip_address/status.html";
my $current_power=0;
my $yield_today=0;
my $yield_total=0;
my $serial_device='';
my $serial_inverter='';
my $firmware='';
my $control=0;
# Create a new LWP::UserAgent object
my $ua = LWP::UserAgent->new();
# Create a new HTTP::Request object with authentication credentials
my $request = GET $url;
$request->authorization_basic($username, $password);
# Make the HTTP request and get the response
my $response = $ua->request($request);
# Check if the request was successful
if ($response->is_success) {
my $content = $response->content;
my @carray = split /\n/,$content;
my $i=0;
foreach my $line (@carray){
$i++;
print "$i: $line\n" if $debug;
if ($line=~ /var webdata_now_p.*\"(.*)\"/) { $current_power = $1; $control++; }
if ($line=~ /var webdata_today_e .*\"(.*)\"/) { $yield_today = $1; $control++; }
if ($line=~ /var webdata_total_e .*\"(.*)\"/) { $yield_total = $1; $control++; }
if ($line=~ /var webdata_sn.*\"(.*)\"/) { $serial_inverter = $1; $control++; $serial_inverter=~s/\s//g; }
if ($line=~ /var cover_mid.*\"(.*)\"/) { $serial_device = $1; $control++; }
if ($line=~ /var cover_ver.*\"(.*)\"/) { $firmware = $1; $control++; }
}
} else {
print "HTTP request failed: " . $response->status_line . "\n";
}
if ($checkmk){
my $status=0;
my $txt_warn="";
print "<<<check_mk>>>\n";
print "version: $version\n";
print "<<<local>>>\n";
my $str_perf = "current-power=$current_power|production-today=$yield_today|production-total=$yield_total";
my $str_txt = "current-power=$current_power W, today=$yield_today kWH, total=$yield_total kWH, ".
"serial-inverter=$serial_inverter, serial-device=$serial_device, firmware=$firmware, name=$name.";
if ($control != 6){
$status = 1;
$txt_warn = " WARNING - could not get all values! ";
}
print "$status deye-power power=$current_power current-power=$current_power W\n";
print "$status deye-today today=$yield_today today=$yield_today kWH\n";
print "$status deye-total total=$yield_total total=$yield_total kWH\n";
print "$status deye-info - $txt_warn $str_txt\n";
}else{
print "current power=$current_power.\n";
print "production today=$yield_today.\n";
print "production total=$yield_total.\n";
print "serial inverter=$serial_inverter.\n";
print "serial device=$serial_device.\n";
print "firmware=$firmware.\n";
}
computer2know :: thank you for your visit :: have a nice day :: © 2023