10_MQTT2_DEVICE.pm: att MATCHED variable to readingsList (Forum #142401)

git-svn-id: https://svn.fhem.de/fhem/trunk@30247 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig
2025-09-03 10:35:29 +00:00
parent b7a58de1ee
commit cfbfac9fe9

View File

@@ -174,15 +174,19 @@ MQTT2_DEVICE_Parse($$)
next if(!$hash);
my $reRepl = $re;
map { $reRepl =~ s/\$$_/$hash->{".DT"}{$_}/g } keys %{$hash->{".DT"}};
next if(!("$topic:$value" =~ m/^$reRepl$/s ||
"$cid:$topic:$value" =~ m/^$reRepl$/s));
my @matched = ("$topic:$value" =~ m/^$reRepl$/sg); # 143401
@matched = ("$cid:$topic:$value" =~ m/^$reRepl$/sg) if(!@matched);
next if(!@matched);
next if(IsDisabled($dev));
Log3 $dev, 4, "MQTT2_DEVICE_Parse: $dev $topic => $code";
if($code =~ m/^{.*}$/s) {
my %v = ("%TOPIC"=>$topic, "%EVENT"=>$value, "%NAME"=>$hash->{NAME},
"%CID"=>$cid, "%JSONMAP","\$defs{\"$dev\"}{JSONMAP}");
"%CID"=>$cid, "%JSONMAP","\$defs{\"$dev\"}{JSONMAP}",
"%MATCHED"=>\@matched);
map { $v{"%$_"} = $hash->{".DT"}{$_} } keys %{$hash->{".DT"}};
$code = EvalSpecials($code, %v);
my $ret = AnalyzePerlCommand(undef, $code);
@@ -1136,7 +1140,11 @@ zigbee2mqtt_devStateIcon255($;$$)
<li>in the perl expression the variables $TOPIC, $NAME, $DEVICETOPIC
$JSONMAP and $EVENT are available (the letter containing the whole
message), as well as $EVTPART0, $EVTPART1, ... each containing a
single word of the message.</li>
single word of the message.<br>
The @MATCHED array contains the result of the regexp: the captured
groups if present, or the whole matched string.
</li>
<li>the helper function json2nameValue($EVENT) can be used to parse a
json encoded value. Importing all values from a Sonoff device with a
Tasmota firmware can be done with: