diff --git a/fhem/FHEM/98_CustomReadings.pm b/fhem/FHEM/98_CustomReadings.pm index a0eca3f1b..fd33bc994 100644 --- a/fhem/FHEM/98_CustomReadings.pm +++ b/fhem/FHEM/98_CustomReadings.pm @@ -45,6 +45,9 @@ sub CustomReadings_read($) $readingDefinitions =~ s/\n//g; my @used = ("state"); + my $isCombined = 0; + my @combinedOutput = (); + my $hasErrors = 0; readingsBeginUpdate($hash); @@ -59,18 +62,52 @@ sub CustomReadings_read($) } my @definition = split(':', $param, 2); - push(@used, $definition[0]); + if ($definition[0] eq "COMBINED") { + $isCombined = 1; + my $cmdStr = $definition[1]; + my $cmdTemp = eval("$cmdStr"); + if (ref $cmdTemp eq 'ARRAY') { + @combinedOutput = @{ $cmdTemp }; + } else { + @combinedOutput = split(/^/, $cmdTemp); + } + Log 5, "Using combined mode for customReadings: $cmdStr"; + next; + } + else { + push(@used, $definition[0]); + } + + if($definition[1] ne "") { + $isCombined = 0; + } + + my $value = 0; + if ($isCombined) { + $value = shift @combinedOutput; + + if (!($value)) { + $value = 0; + $hasErrors = 1; + Log 3, "customReadings: Warning for $name: combined command for " . $definition[0] . " returned nothing or not enough lines."; + } + } + else { + $value = eval($definition[1]); + } - my $value = eval($definition[1]); if($value) { $value =~ s/^\s+|\s+$//g; } else { $value = "ERROR"; + $hasErrors = 1; } readingsBulkUpdate($hash, $definition[0], $value); } + + readingsBulkUpdate($hash, "state", $hasErrors ? "Errors" : "OK"); readingsEndUpdate($hash, 1); @@ -101,7 +138,8 @@ sub CustomReadings_GetHTML ($) my $result = ""; $result .= "
| $reading: | " . ReadingsVal($name, $reading, "???") . " | "; $result .= "