From 19131e9bbd87e19b36041643586e3e6fde570a64 Mon Sep 17 00:00:00 2001 From: Beta-User <> Date: Tue, 30 Nov 2021 05:38:01 +0000 Subject: [PATCH] RHASSPY: add numericValueMap; extend docu git-svn-id: https://svn.fhem.de/fhem/trunk@25275 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/contrib/RHASSPY/10_RHASSPY.pm | 46 +++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/fhem/contrib/RHASSPY/10_RHASSPY.pm b/fhem/contrib/RHASSPY/10_RHASSPY.pm index ac97165b7..2f343fc39 100644 --- a/fhem/contrib/RHASSPY/10_RHASSPY.pm +++ b/fhem/contrib/RHASSPY/10_RHASSPY.pm @@ -349,7 +349,7 @@ sub Define { $hash->{defaultRoom} = $defaultRoom; my $language = $h->{language} // shift @{$anon} // lc AttrVal('global','language','en'); - $hash->{MODULE_VERSION} = '0.5.03'; + $hash->{MODULE_VERSION} = '0.5.04a'; $hash->{baseUrl} = $Rhasspy; initialize_Language($hash, $language) if !defined $hash->{LANGUAGE} || $hash->{LANGUAGE} ne $language; $hash->{LANGUAGE} = $language; @@ -998,6 +998,9 @@ sub _analyze_rhassypAttr { if ($key eq 'colorTempMap') { $hash->{helper}{devicemap}{devices}{$device}{color_specials}{Colortemp} = $named if defined $named; } + if ($key eq 'numericValueMap') { + $hash->{helper}{devicemap}{devices}{$device}{numeric_ValueMap} = $named if defined $named; + } if ($key eq 'venetianBlind') { my $specials = {}; my $vencmd = $named->{setter} // shift @{$unnamed}; @@ -1061,6 +1064,9 @@ sub _analyze_genDevType { $attrv = AttrVal($device,'siriName',undef); push @names, split m{,}x, lc $attrv if $attrv; + $attrv = AttrVal($device,'gassistantName',undef); + push @names, split m{,}x, lc $attrv if $attrv; + my $alias = lc AttrVal($device,'alias',$device); $names[0] = $alias if !@names; } @@ -3426,6 +3432,8 @@ sub handleIntentSetNumeric { my $part = $mapping->{part}; my $minVal = $mapping->{minVal}; my $maxVal = $mapping->{maxVal}; + my $useMap = defined $hash->{helper}{devicemap}{devices}{$device}->{numeric_ValueMap} + && defined $hash->{helper}{devicemap}{devices}{$device}->{numeric_ValueMap}->{$value} ? $hash->{helper}{devicemap}{devices}{$device}->{numeric_ValueMap}->{$value} : undef; $minVal = 0 if defined $minVal && !looks_like_number($minVal); $maxVal = 100 if defined $maxVal && !looks_like_number($maxVal); @@ -3433,12 +3441,12 @@ sub handleIntentSetNumeric { my $diff = $value // $mapping->{step} // 10; - #my $up = (defined($change) && ($change =~ m/^(höher|heller|lauter|wärmer)$/)) ? 1 : 0; - my $up = $change; - $up = $internal_mappings->{Change}->{$change}->{up} - // $internal_mappings->{Change}->{$de_mappings->{ToEn}->{$change}}->{up} - // defined $change && ($change =~ m{\A$internal_mappings->{regex}->{upward}\z}xi || $change =~ m{\A$de_mappings->{regex}->{upward}\z}xi ) ? 1 - : 0; + my $up = $change // 0; + if ( defined $change ) { + $up = $internal_mappings->{Change}->{$change}->{up} + // $internal_mappings->{Change}->{$de_mappings->{ToEn}->{$change}}->{up} + // ( $change =~ m{\A$internal_mappings->{regex}->{upward}\z}xi || $change =~ m{\A$de_mappings->{regex}->{upward}\z}xi ) ? 1 : 0; + } my $forcePercent = ( defined $mapping->{map} && lc $mapping->{map} eq 'percent' ) ? 1 : 0; @@ -3474,8 +3482,8 @@ sub handleIntentSetNumeric { } else { # defined $change # Stellwert um Wert x ändern ("Mache Lampe um 20 heller" oder "Mache Lampe heller") #elsif ((!defined $unit || $unit ne 'Prozent') && defined $change && !$forcePercent) { - if ( $change eq 'cmdStop' ) { - $newVal = $oldVal; + if ( $change eq 'cmdStop' || $useMap ) { + $newVal = $oldVal // 50; } elsif ( ( !defined $unit || !$ispct ) && !$forcePercent ) { $newVal = ($up) ? $oldVal + $diff : $oldVal - $diff; } @@ -3502,9 +3510,9 @@ sub handleIntentSetNumeric { return $hash->{NAME} if !defined $data->{'.inBulk'} && !$data->{Confirmation} && getNeedsConfirmation( $hash, $data, 'SetNumeric' ); # execute Cmd - $change ne 'cmdStop' - || !defined $mapping->{cmdStop} - ? analyzeAndRunCmd($hash, $device, $cmd, $newVal) + !defined $change || $change ne 'cmdStop' || !defined $mapping->{cmdStop} + ? !defined $useMap ? analyzeAndRunCmd($hash, $device, $cmd, $newVal) + : analyzeAndRunCmd($hash, $device, $useMap) : analyzeAndRunCmd($hash, $device, $mapping->{cmdStop}); #venetian blind special @@ -5058,8 +5066,14 @@ yellow=rgb FFFF00
Example:
attr lamp1 rhasspySpecials group:async_delay=100 prio=1 group=lights
Allows mapping of numeric values from the Value key to individual commands. Might e.g. usefull to address special positioning commands for blinds.
+Example:
+attr blind1 rhasspySpecials numericValueMap:10='Event Slit' 50='myPosition'
Note: will lead to e.g. set blind1 Event Slit
when numeric value 10 is received in {Value} key.
attr blind1 rhasspySpecials venetianBlind:setter=dim device=blind1_slats
attr blind1 rhasspySpecials venetianBlind:setter=dim device=blind1_slats stopCommand="set blind1_slats dim [blind1_slats:dim]"
Explanation (one of the two arguments is mandatory):
If set, the slat target position will be set to the same level than the main device.
Allows mapping of values from the Color> key to individual commands.
+Allows mapping of values from the Color key to individual commands.
Example:
attr lamp1 rhasspySpecials colorCommandMap:0='rgb FF0000' 120='rgb 00FF00' 240='rgb 0000FF'
Allows mapping of values from the Colortemp key to individual commands.
+ Works similar to colorCommandMap +Defaults to "0". If set, a rgb command will be issued, even if the device is capable to handle hue commands.
Example: