diff --git a/fhem/CHANGED b/fhem/CHANGED
index 4cedf1879..98c34e12c 100644
--- a/fhem/CHANGED
+++ b/fhem/CHANGED
@@ -1,5 +1,6 @@
# Add changes at the top of the list. Keep it in ASCII
- SVN
+ - feature: YAMAHA_AVR: new set command to select scenes
- feature: PRESENCE: new attribute ping_count
- feature: userReadings may have a filter
- feature: HUEBridge: allow starting of bridge firmware update
diff --git a/fhem/FHEM/71_YAMAHA_AVR.pm b/fhem/FHEM/71_YAMAHA_AVR.pm
index 143ac1042..2490ea08f 100755
--- a/fhem/FHEM/71_YAMAHA_AVR.pm
+++ b/fhem/FHEM/71_YAMAHA_AVR.pm
@@ -84,7 +84,7 @@ YAMAHA_AVR_GetStatus($;$)
YAMAHA_AVR_getModel($hash);
}
- if(not defined($hash->{helper}{INPUTS}) or length($hash->{helper}{INPUTS}) == 0)
+ if((not defined($hash->{helper}{INPUTS}) or length($hash->{helper}{INPUTS}) == 0) or (not defined($hash->{helper}{SCENES}) or length($hash->{helper}{SCENES}) == 0))
{
YAMAHA_AVR_getInputs($hash);
}
@@ -202,10 +202,15 @@ YAMAHA_AVR_Set($@)
my $inputs_piped = defined($hash->{helper}{INPUTS}) ? YAMAHA_AVR_InputParam2Fhem(lc($hash->{helper}{INPUTS}), 0) : "" ;
my $inputs_comma = defined($hash->{helper}{INPUTS}) ? YAMAHA_AVR_InputParam2Fhem(lc($hash->{helper}{INPUTS}), 1) : "" ;
+
+ my $scenes_piped = defined($hash->{helper}{SCENES}) ? YAMAHA_AVR_InputParam2Fhem(lc($hash->{helper}{SCENES}), 0) : "" ;
+ my $scenes_comma = defined($hash->{helper}{SCENES}) ? YAMAHA_AVR_InputParam2Fhem(lc($hash->{helper}{SCENES}), 1) : "" ;
+
+
return "No Argument given" if(!defined($a[1]));
my $what = $a[1];
- my $usage = "Unknown argument $what, choose one of on off volume:slider,-80,1,16 input:".$inputs_comma." mute:on,off remoteControl:setup,up,down,left,right,return,option,display,enter statusRequest";
+ my $usage = "Unknown argument $what, choose one of on off volume:slider,-80,1,16 input:".$inputs_comma." mute:on,off remoteControl:setup,up,down,left,right,return,option,display,enter scene:".$scenes_comma." statusRequest";
readingsBeginUpdate($hash);
@@ -243,37 +248,35 @@ YAMAHA_AVR_Set($@)
{
if($hash->{STATE} eq "on")
{
- $inputs_piped =~ s/,/|/g;
- if(not $inputs_piped eq "")
- {
- if($a[2] =~ /^($inputs_piped)$/)
+ if(not $inputs_piped eq "")
{
- $command = YAMAHA_AVR_getCommandParam($hash, $a[2]);
- if(defined($command) and length($command) > 0)
+ if($a[2] =~ /^($inputs_piped)$/)
{
- $result = YAMAHA_AVR_SendCommand($hash, "<$zone>".$command."$zone>");
+ $command = YAMAHA_AVR_getInputParam($hash, $a[2]);
+ if(defined($command) and length($command) > 0)
+ {
+ $result = YAMAHA_AVR_SendCommand($hash, "<$zone>".$command."$zone>");
+ }
+ else
+ {
+ return "invalid input: ".$a[2];
+ }
+
+ if(not $result =~ /RC="0"/)
+ {
+ # if the returncode isn't 0, than the command was not successful
+ return "Could not set input to ".$a[2].".";
+ }
}
else
{
- return "invalid input: ".$a[2];
+ return $usage;
}
-
- if(not $result =~ /RC="0"/)
- {
- # if the returncode isn't 0, than the command was not successful
- return "Could not set input to ".$a[2].".";
- }
- }
- else
- {
- return $usage;
- }
- }
- else
- {
- return "No inputs are avaible. Please try an statusUpdate.";
- }
-
+ }
+ else
+ {
+ return "No inputs are avaible. Please try an statusUpdate.";
+ }
}
else
{
@@ -285,6 +288,53 @@ YAMAHA_AVR_Set($@)
return $inputs_piped eq "" ? "No inputs are available. Please try an statusUpdate." : "No input parameter was given";
}
+ }
+ elsif($what eq "scene")
+ {
+ if(defined($a[2]))
+ {
+ if($hash->{STATE} eq "on")
+ {
+ if(not $scenes_piped eq "")
+ {
+ if($a[2] =~ /^($scenes_piped)$/)
+ {
+ $command = YAMAHA_AVR_getSceneName($hash, $a[2]);
+ if(defined($command) and length($command) > 0)
+ {
+ $result = YAMAHA_AVR_SendCommand($hash, "<$zone>".$command."$zone>");
+ }
+ else
+ {
+ return "invalid input: ".$a[2];
+ }
+
+ if(not $result =~ /RC="0"/)
+ {
+ # if the returncode isn't 0, than the command was not successful
+ return "Could not set scene to ".$a[2].".";
+ }
+ }
+ else
+ {
+ return $usage;
+ }
+ }
+ else
+ {
+ return "No scenes are avaible. Please try an statusUpdate.";
+ }
+ }
+ else
+ {
+ return "scene can only be used when device is powered on";
+ }
+ }
+ else
+ {
+ return $scenes_piped eq "" ? "No inputs are available. Please try an statusUpdate." : "No input parameter was given";
+ }
+
}
elsif($what eq "mute")
{
@@ -568,16 +618,16 @@ sub YAMAHA_AVR_InputParam2Fhem($$)
#############################
# Converts all Zones to FHEM usable command lists
-sub YAMAHA_AVR_Zone2Fhem($$)
+sub YAMAHA_AVR_Param2Fhem($$)
{
- my ($zones, $replace_pipes) = @_;
+ my ($param, $replace_pipes) = @_;
- $zones =~ s/\s+//g;
- $zones =~ s/_//g;
- $zones =~ s/\|/,/g if($replace_pipes == 1);
+ $param =~ s/\s+//g;
+ $param =~ s/_//g;
+ $param =~ s/\|/,/g if($replace_pipes == 1);
- return lc $zones;
+ return lc $param;
}
@@ -594,7 +644,31 @@ sub YAMAHA_AVR_getZoneName($$)
foreach $item (@commands)
{
- if(YAMAHA_AVR_Zone2Fhem($item, 0) eq $zone)
+ if(YAMAHA_AVR_Param2Fhem($item, 0) eq $zone)
+ {
+ return $item;
+ }
+
+ }
+
+ return undef;
+
+}
+
+#############################
+# Returns the Yamaha Parameter Name for the FHEM like aquivalents
+sub YAMAHA_AVR_getSceneName($$)
+{
+ my ($hash, $scene) = @_;
+ my $item;
+
+ return undef if(not defined($hash->{helper}{SCENES}));
+
+ my @commands = split("\\|", $hash->{helper}{SCENES});
+
+ foreach $item (@commands)
+ {
+ if(YAMAHA_AVR_Param2Fhem($item, 0) eq $scene)
{
return $item;
}
@@ -607,7 +681,7 @@ sub YAMAHA_AVR_getZoneName($$)
#############################
# Returns the Yamaha Parameter Name for the FHEM like input channel
-sub YAMAHA_AVR_getCommandParam($$)
+sub YAMAHA_AVR_getInputParam($$)
{
my ($hash, $command) = @_;
my $item;
@@ -685,7 +759,7 @@ sub YAMAHA_AVR_getModel($)
#
# $hash->{helper}{ZONES} .= "|Zone_2";
- $hash->{ZONES_AVAILABLE} = YAMAHA_AVR_Zone2Fhem($hash->{helper}{ZONES}, 1);
+ $hash->{ZONES_AVAILABLE} = YAMAHA_AVR_Param2Fhem($hash->{helper}{ZONES}, 1);
if(defined(YAMAHA_AVR_getZoneName($hash, lc $hash->{helper}{SELECTED_ZONE})))
@@ -740,6 +814,26 @@ sub YAMAHA_AVR_getInputs($)
$hash->{helper}{INPUTS} = join("|", sort split("\\|", $hash->{helper}{INPUTS}));
+ $response = YAMAHA_AVR_SendCommand($hash, "<$zone>GetParam$zone>");
+
+ Log GetLogLevel($name, 3), "YAMAHA_AVR: could not get the available scenes from device $name. Please turn on the device or check for correct hostaddress!!!" if (not defined($response) and defined($hash->{helper}{AVAILABLE}) and $hash->{helper}{AVAILABLE} eq 1);
+
+ return undef unless (defined($response));
+
+ delete($hash->{helper}{SCENES}) if(defined($hash->{helper}{SCENES}));
+
+ while($response =~ /.*?(.+?)<\/Param>.*?(\w+)<\/RW>.*?<\/Item_\d+>/gc)
+ {
+ if($2 eq "W")
+ {
+ if(defined($hash->{helper}{SCENES}) and length($hash->{helper}{SCENES}) > 0)
+ {
+ $hash->{helper}{SCENES} .= "|";
+ }
+
+ $hash->{helper}{SCENES} .= $1;
+ }
+ }
}
@@ -815,7 +909,7 @@ sub YAMAHA_AVR_getInputs($)
set <name> <command> [<parameter>]
Currently, the following commands are defined; the available inputs are depending on the used receiver.
- The module only offers the real available inputs. The following input commands are just an example and can differ.
+ The module only offers the real available inputs and scenes. The following input commands are just an example and can differ.
on
off
@@ -836,7 +930,11 @@ input tuner
input v-aux
input audio
input server
-volume -80..16 (volume between -80 and +16 dB)
+scene scene1
+scene scene2
+scene scene3
+scene scene4
+volume -80..16 # (volume between -80 and +16 dB)
mute on
mute off
@@ -998,7 +1096,7 @@ volume_level
set <Name> <Kommando> [<Parameter>]
- Aktuell werden folgende Kommandos unterstützt. Die verfügbaren Eingänge können je nach Receiver-Modell variieren.
+ Aktuell werden folgende Kommandos unterstützt. Die verfügbaren Eingänge und Szenen können je nach Receiver-Modell variieren.
Die folgenden Eingänge stehen beispielhaft an einem RX-V473 Receiver zur Verfügung.
Aktuell stehen folgende Kommandos zur Verfügung.
@@ -1022,7 +1120,11 @@ input tuner
input v-aux
input audio
input server
-volume -80..16 (Lautstärke zwischen -80 und +16 dB)
+scene scene1
+scene scene2
+scene scene3
+scene scene4
+volume -80..16 # (Lautstärke zwischen -80 und +16 dB)
mute on
mute off