diff --git a/fhem/CHANGED b/fhem/CHANGED index 0c43d9274..d4f8b58a6 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,6 @@ # Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Do not insert empty lines here, update check depends on it. + - feature: 31_HUEDevice: allow perl code with setList and configList attributes - bugfix: 95_Astro: v2.0.2: Calculate astronomical season based on ecliptic latitude instead of static day of the year to make season transition times more reliable. Also, seasons for diff --git a/fhem/FHEM/31_HUEDevice.pm b/fhem/FHEM/31_HUEDevice.pm index 4bd1878f4..bc6a33e91 100644 --- a/fhem/FHEM/31_HUEDevice.pm +++ b/fhem/FHEM/31_HUEDevice.pm @@ -624,6 +624,8 @@ HUEDevice_Set($@) my ($cmd, @args) = @aa; my %obj; + my @match; + my $entries; $hash->{helper}->{update_timeout} = AttrVal($name, "delayedUpdate", 1); @@ -711,37 +713,53 @@ HUEDevice_Set($@) return undef; - } elsif( my @match = grep { $cmd eq $_ } keys %{($hash->{helper}{setList}{cmds}?$hash->{helper}{setList}{cmds}:{})} ) { + } elsif( @match = grep { $cmd eq $_ } keys %{($hash->{helper}{setList}{cmds}?$hash->{helper}{setList}{cmds}:{})} ) { return HUEBridge_Set( $shash, $shash->{NAME}, 'setsensor', $id, $hash->{helper}{setList}{cmds}{$match[0]} ); - } elsif( my $entries = $hash->{helper}{setList}{regex} ) { + } elsif( $entries = $hash->{helper}{setList}{regex} ) { foreach my $entry (@{$entries}) { if( join(' ', @aa) =~ /$entry->{regex}/ ) { my $VALUE1 = $1; my $VALUE2 = $2; my $VALUE3 = $3; my $json = $entry->{json}; - $json =~ s/\$1/$VALUE1/; - $json =~ s/\$2/$VALUE2/; - $json =~ s/\$3/$VALUE3/; + if( $json =~ m/^perl:{(.*)}$/ ) { + $json = eval $json; + if($@) { + Log3 $name, 3, "$name: configList: ". join(' ', @aa). ": ". $@; + return "error: ". join(' ', @aa). ": ". $@; + } + } else { + $json =~ s/\$1/$VALUE1/; + $json =~ s/\$2/$VALUE2/; + $json =~ s/\$3/$VALUE3/; + } return HUEBridge_Set( $shash, $shash->{NAME}, 'setsensor', $id, $json ); } } - } elsif( my @match = grep { $cmd eq $_ } keys %{($hash->{helper}{configList}{cmds}?$hash->{helper}{configList}{cmds}:{})} ) { + } elsif( @match = grep { $cmd eq $_ } keys %{($hash->{helper}{configList}{cmds}?$hash->{helper}{configList}{cmds}:{})} ) { return HUEBridge_Set( $shash, $shash->{NAME}, 'configsensor', $id, $hash->{helper}{configList}{cmds}{$match[0]} ); - } elsif( my $entries = $hash->{helper}{configList}{regex} ) { + } elsif( $entries = $hash->{helper}{configList}{regex} ) { foreach my $entry (@{$entries}) { if( join(' ', @aa) =~ /$entry->{regex}/ ) { my $VALUE1 = $1; my $VALUE2 = $2; my $VALUE3 = $3; my $json = $entry->{json}; - $json =~ s/\$1/$VALUE1/; - $json =~ s/\$2/$VALUE2/; - $json =~ s/\$3/$VALUE3/; + if( $json =~ m/^perl:{(.*)}$/ ) { + $json = eval $json; + if($@) { + Log3 $name, 3, "$name: configList: ". join(' ', @aa). ": ". $@; + return "error: ". join(' ', @aa). ": ". $@; + } + } else { + $json =~ s/\$1/$VALUE1/; + $json =~ s/\$2/$VALUE2/; + $json =~ s/\$3/$VALUE3/; + } return HUEBridge_Set( $shash, $shash->{NAME}, 'configsensor', $id, $json ); } @@ -1810,7 +1828,8 @@ HUEDevice_Attr($$$;$) absent:{<json>}
  • configList
    The list of know config commands for sensor type devices. one command per line, eg.:
    -mode:{<json>}
  • +attr mySensor mode:{<json>}\
    +/heatsetpoint (.*)/:perl:{'{"heatsetpoint":'. $VALUE1 * 100 .'}'}
  • subType
    extcolordimmer -> device has rgb and color temperatur control
    colordimmer -> device has rgb controll