71_PIONEERAVRZONE.pm 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  1. # $Id: 71_PIONEERAVRZONE.pm 7365 2014-12-30 15:42:43Z hofrichter $
  2. ##############################################################################
  3. #
  4. # 71_PIONEERAVRZONE.pm
  5. #
  6. # This file is part of Fhem.
  7. #
  8. # Fhem is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation, either version 2 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # Fhem is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with Fhem. If not, see <http://www.gnu.org/licenses/>.
  20. #
  21. ##############################################################################
  22. package main;
  23. use strict;
  24. use warnings;
  25. use Time::HiRes qw(gettimeofday);
  26. use SetExtensions qw/ :all /;
  27. sub PIONEERAVRZONE_Get($@);
  28. sub PIONEERAVRZONE_Set($@);
  29. sub PIONEERAVRZONE_Attr($@);
  30. sub PIONEERAVRZONE_Define($$);
  31. ###################################
  32. sub
  33. PIONEERAVRZONE_Initialize($)
  34. {
  35. my ($hash) = @_;
  36. $hash->{Match} = ".+";
  37. $hash->{GetFn} = "PIONEERAVRZONE_Get";
  38. $hash->{SetFn} = "PIONEERAVRZONE_Set";
  39. $hash->{DefFn} = "PIONEERAVRZONE_Define";
  40. $hash->{ParseFn} = "PIONEERAVRZONE_Parse";
  41. $hash->{AttrFn} = "PIONEERAVRZONE_Attr";
  42. $hash->{AttrList} = "IODev ".
  43. $readingFnAttributes;
  44. }
  45. ###################################
  46. sub
  47. PIONEERAVRZONE_Changed($$$)
  48. {
  49. my ($hash, $cmd, $value)= @_;
  50. readingsBeginUpdate($hash);
  51. my $state= $cmd;
  52. if(defined($value) && $value ne "") {
  53. readingsBulkUpdate($hash, $cmd, $value);
  54. $state.= " $value";
  55. }
  56. readingsBulkUpdate($hash, "state", $state);
  57. readingsEndUpdate($hash, 1);
  58. my $name= $hash->{NAME};
  59. Log3 $hash, 4 , "PIONEERAVRZONE $name $state";
  60. return $state;
  61. }
  62. ###################################
  63. sub
  64. PIONEERAVRZONE_Get($@)
  65. {
  66. my ($hash, @a)= @_;
  67. my $name= $hash->{NAME};
  68. my $zone= $hash->{helper}{ZONE};
  69. my $expect= ".*";
  70. return "get $name needs at least one argument" if(int(@a) < 2);
  71. my $cmdName= $a[1];
  72. my $IOhash= $hash->{IODev};
  73. if ($cmdName eq "input" ) {
  74. } elsif (!defined($IOhash->{helper}{GETS}{$zone}{$cmdName})) {
  75. my $gets= $IOhash->{helper}{GETS}{$zone};
  76. return "$name error: unknown argument $cmdName, choose one of " .
  77. (join " ", sort keys %$gets);
  78. }
  79. my $cmd= $IOhash->{helper}{GETS}{$zone}{$cmdName};
  80. my $v= IOWrite($hash, $cmd);
  81. # return PIONEERAVRZONE_Changed($hash, $cmdname, $v);;
  82. return undef;
  83. }
  84. #############################
  85. sub
  86. PIONEERAVRZONE_Set($@)
  87. {
  88. my ($hash, @a)= @_;
  89. my @args= @a; shift @args; shift @args;
  90. my $name= $hash->{NAME};
  91. my $type= $hash->{TYPE};
  92. return "set $name needs at least one argument" if(int(@a) < 2);
  93. my $cmd= $a[1];
  94. my $IOhash= $hash->{IODev};
  95. my $zone= $hash->{helper}{ZONE};
  96. my $vmax = 0;
  97. my $zahl= 0;
  98. my $muteStr ="";
  99. my @setsWithoutArg= ("off","toggle","volumeUp","volumeDown","muteOn","muteOff","muteToggle","inputUp","inputDown");
  100. Log3 $name, 5, "PIONEERAVRZONE $name: called function PIONEERAVR_Set($cmd)";
  101. return "No Argument given" if ( !defined( $cmd ) );
  102. my $inputNames= $IOhash->{helper}{INPUTNAMES};
  103. # get all input names (preferable the aliasName) of the enabled inputs for the drop down list of "set <device> input xxx"
  104. my @listInputNames = ();
  105. foreach my $key ( keys %{$IOhash->{helper}{INPUTNAMES}} ) {
  106. if (defined($IOhash->{helper}{INPUTNAMES}->{$key}{enabled})) {
  107. if ( $IOhash->{helper}{INPUTNAMES}->{$key}{enabled} eq "1" ) {
  108. if ($IOhash->{helper}{INPUTNAMES}{$key}{aliasName}) {
  109. push(@listInputNames,$IOhash->{helper}{INPUTNAMES}{$key}{aliasName});
  110. } elsif ($IOhash->{helper}{INPUTNAMES}{$key}{name}) {
  111. push(@listInputNames,$IOhash->{helper}{INPUTNAMES}{$key}{name});
  112. }
  113. }
  114. }
  115. }
  116. if (($zone eq "zone2") || ($zone eq "zone3")) {
  117. $muteStr = " mute:on,off,toggle";
  118. }
  119. my $list =
  120. "on:noArg off:noArg toggle:noArg input:"
  121. . join(',', sort @listInputNames)
  122. . " inputUp:noArg inputDown:noArg"
  123. . " volumeUp:noArg volumeDown:noArg"
  124. . $muteStr
  125. . " statusRequest:noArg volume:slider,0,1,100"
  126. . " volumeStraight:slider,-80,1,".$vmax;
  127. if ( $cmd eq "?" ) {
  128. Log3 $name, 5, "PIONEERAVRZONE set $name " . $cmd;
  129. return SetExtensions($hash, $list, $name, $cmd, @args);
  130. }
  131. if(@a == 2) {
  132. Log3 $name, 5, "PIONEERAVRZONE $name: Set $cmd";
  133. #### simple set commands without attributes
  134. #### we just "translate" the human readable command to the PioneerAvr command
  135. #### lookup in $IOhash->{helper}{SETS}{$zone} if the command exists and what to write to PioneerAvr
  136. if ( $cmd ~~ @setsWithoutArg ) {
  137. Log3 $name, 5, "PIONEERAVR $name: Set $cmd (setsWithoutArg)";
  138. my $setCmd= $IOhash->{helper}{SETS}{$zone}{$cmd};
  139. my $v= IOWrite($hash, $setCmd);
  140. Log3 $hash, 5, "PIONEERAVR $name: Set_IOwrite($zone ... $cmd ): $setCmd";
  141. return undef;
  142. ### Power on
  143. ### Command: PO
  144. ### according to "Elite & Pioneer FY14AVR IP & RS-232 7-31-13.xlsx" (notice) we need to send <cr> and
  145. ### wait 100ms before the first command is accepted by the Pioneer AVR
  146. } elsif ( $cmd eq "on" ) {
  147. Log3 $name, 5, "PIONEERAVR $name: Set $cmd ";
  148. my $setCmd= "";
  149. IOWrite($hash, $setCmd);
  150. select(undef, undef, undef, 0.1);
  151. if ( $zone eq "zone2" ) {
  152. $setCmd = "APO";
  153. } elsif ( $zone eq "zone3" ) {
  154. $setCmd = "BPO";
  155. } elsif ( $zone eq "hdZone" ) {
  156. $setCmd = "ZEO";
  157. }
  158. IOWrite($hash, $setCmd);
  159. select(undef, undef, undef, 0.1);
  160. Log3 $hash, 5, "PIONEERAVR $name: Set_IOwrite: $setCmd";
  161. return undef;
  162. # statusRequest: execute all "get" commands to update the readings
  163. } elsif ( $cmd eq "statusRequest") {
  164. Log3 $name, 5, "PIONEERAVR $name: Set $cmd ";
  165. foreach my $key ( keys %{$IOhash->{helper}{GETS}{$zone}} ) {
  166. IOWrite($hash, $IOhash->{helper}{GETS}->{$zone}->{$key});
  167. }
  168. return undef;
  169. }
  170. #### commands with argument(s)
  171. } elsif(@a > 2) {
  172. my $arg = $a[2];
  173. ####Input (all available Inputs of the Pioneer Avr -> see 'get $name loadInputNames')
  174. ####according to http://www.fhemwiki.de/wiki/DevelopmentGuidelinesAV
  175. if ( $cmd eq "input" ) {
  176. Log3 $name, 5, "PIONEERAVRZONE $name: set $cmd ".dq($arg);
  177. foreach my $key ( keys %{$IOhash->{helper}{INPUTNAMES}} ) {
  178. if ( $IOhash->{helper}{INPUTNAMES}->{$key}{aliasName} eq $arg ) {
  179. if ( $zone eq "zone2" ) {
  180. IOWrite($hash, sprintf "%02dZS", $key);
  181. } elsif ($zone eq "zone3") {
  182. IOWrite($hash, sprintf "%02dZT", $key);
  183. } elsif ($zone eq "hdZone") {
  184. IOWrite($hash, sprintf "%02dZEA", $key);
  185. }
  186. } elsif ( $IOhash->{helper}{INPUTNAMES}->{$key}{name} eq $arg ) {
  187. if ( $zone eq "zone2" ) {
  188. IOWrite($hash, sprintf "%02dZS", $key);
  189. } elsif ($zone eq "zone3") {
  190. IOWrite($hash, sprintf "%02dZT", $key);
  191. } elsif ($zone eq "hdZone") {
  192. IOWrite($hash, sprintf "%02dZEA", $key);
  193. }
  194. }
  195. }
  196. return undef;
  197. #####VolumeStraight (-80.5 - 12) in dB
  198. ####according to http://www.fhemwiki.de/wiki/DevelopmentGuidelinesAV
  199. } elsif ( $cmd eq "volumeStraight" ) {
  200. $zahl = 80.5 + $arg;
  201. if ( $zone eq "zone2" ) {
  202. IOWrite($hash, sprintf "%02dZV", $zahl);
  203. } elsif ( $zone eq "zone3" ) {
  204. IOWrite($hash, sprintf "%02dYV", $zahl);
  205. }
  206. readingsBeginUpdate($hash);
  207. readingsBulkUpdate($hash, "volumeStraight", $arg );
  208. readingsBulkUpdate($hash, "volume", sprintf "%d", ($a[2]+80)/0.8 );
  209. readingsEndUpdate($hash, 1);
  210. return undef;
  211. ####Volume (0 - 100) in %
  212. ####according to http://www.fhemwiki.de/wiki/DevelopmentGuidelinesAV
  213. } elsif ( $cmd eq "volume" ) {
  214. $zahl = sprintf "%d", $arg*0.8;
  215. if ( $zone eq "zone2" ) {
  216. IOWrite($hash, sprintf "%02dZV", $zahl);
  217. } elsif ( $zone eq "zone3" ) {
  218. IOWrite($hash, sprintf "%02dYV", $zahl);
  219. }
  220. readingsBeginUpdate($hash);
  221. readingsBulkUpdate($hash, "volumeStraight", $zahl - 80 );
  222. readingsBulkUpdate($hash, "volume", sprintf "%d", $a[2] );
  223. readingsEndUpdate($hash, 1);
  224. return undef;
  225. ####Mute (on|off|toggle)
  226. ####according to http://www.fhemwiki.de/wiki/DevelopmentGuidelinesAV
  227. } elsif ( $cmd eq "mute" ) {
  228. if ($arg eq "on") {
  229. IOWrite($hash, $IOhash->{helper}{SETS}{$zone}{muteOn});
  230. readingsSingleUpdate($hash, "mute", "on", 1 );
  231. }
  232. elsif ($arg eq "off") {
  233. IOWrite($hash, $IOhash->{helper}{SETS}{$zone}{muteOff});
  234. readingsSingleUpdate($hash, "mute", "off", 1 );
  235. }
  236. elsif ($arg eq "toggle") {
  237. IOWrite($hash, $IOhash->{helper}{SETS}{$zone}{muteToggle});
  238. }
  239. return undef;
  240. } else {
  241. return SetExtensions($hash, $list, $name, $cmd, @args);
  242. }
  243. } else {
  244. return SetExtensions($hash, $list, $name, $cmd, @args);
  245. }
  246. return undef;
  247. }
  248. #############################
  249. sub
  250. PIONEERAVRZONE_Parse($$)
  251. {
  252. # we are called from dispatch() from the PIONEERAVR device
  253. # we never come here if $msg does not match $hash->{MATCH} in the first place
  254. # NOTE: we will update all matching readings for all (logical) devices, not just the first!
  255. my ($IOhash, $msg) = @_; # IOhash points to the PIONEERAVR, not to the PIONEERAVRZONE
  256. my @matches;
  257. my $name= $IOhash->{NAME};
  258. my $state = '';
  259. #Debug "Trying to find a match for \"" . escapeLogLine($msg) ."\"";
  260. # walk over all clients
  261. foreach my $d (keys %defs) {
  262. my $hash= $defs{$d};
  263. if($hash->{TYPE} eq "PIONEERAVRZONE" && $hash->{IODev} eq $IOhash) {
  264. my $zone= $hash->{helper}{ZONE};
  265. readingsBeginUpdate($hash);
  266. # zone2
  267. if ($zone eq "zone2") {
  268. # volume zone2
  269. # ZVXX
  270. # XX 00 ... 81 -> -81dB ... 0dB
  271. if ( $msg =~ m/^ZV(\d\d)$/ ) {
  272. Log3 $name, 5, "PIONEERAVRZONE $name: ". dq($msg) ." interpreted as: Zone2 - New volume = " . $1 . " (raw volume data).";
  273. readingsBulkUpdate($hash, "volumeStraight", $1 - 81 );
  274. readingsBulkUpdate($hash, "volume", sprintf "%d", $1/0.8 );
  275. push @matches, $d;
  276. # Mute zone2
  277. # Z2MUTX
  278. # X = 0: Mute on; X = 1: Mute off
  279. } elsif ( $msg =~ m/^Z2MUT(\d)$/) {
  280. if ($1) {
  281. readingsBulkUpdate($hash, "mute", "off" );
  282. Log3 $name, 5, "PIONEERAVRZONE $name: ". dq($msg) ." interpreted as: Zone2 - Mute off.";
  283. }
  284. else {
  285. readingsBulkUpdate($hash, "mute", "on" );
  286. Log3 $name, 5, "PIONEERAVRZONE $name: ". dq($msg) ." interpreted as: Zone2 - Mute on.";
  287. }
  288. push @matches, $d;
  289. # Input zone2
  290. # Z2FXX
  291. # XX -> input number 00 ... 49
  292. } elsif ($msg =~ m/^Z2F(\d\d)$/ ) {
  293. my $inputNr = $1;
  294. Log3 $hash,5,"PIONEERAVRZONE $name: ".dq($msg) ." interpreted as: Zone2 - Input is set to inputNr: $inputNr ";
  295. if ( $IOhash->{helper}{INPUTNAMES}->{$inputNr}{aliasName} ne "") {
  296. Log3 $hash,5,"PIONEERAVRZONE $name: Zone2 - Input aliasName for input $inputNr is " . $IOhash->{helper}{INPUTNAMES}{$inputNr}{aliasName};
  297. readingsBulkUpdate($hash, "input", $IOhash->{helper}{INPUTNAMES}->{$inputNr}{aliasName} );
  298. } elsif ( $IOhash->{helper}{INPUTNAMES}->{$inputNr}{name} ne "" ) {
  299. Log3 $hash,5,"PIONEERAVRZONE $name: Zone2 - Input Name for input $inputNr is " . $IOhash->{helper}{INPUTNAMES}{$inputNr}{name};
  300. readingsBulkUpdate($hash, "input", $IOhash->{helper}{INPUTNAMES}->{$inputNr}{name} );
  301. } else {
  302. readingsBulkUpdate($hash, "input", $msg );
  303. Log3 $hash,5,"PIONEERAVRZONE $name: Zone2 - InputName: can't find Name for input $inputNr";
  304. }
  305. push @matches, $d;
  306. # Power zone2
  307. # APRX
  308. # X = 0: Power on; X = 1: Power off
  309. } elsif ( $msg =~ m/^APR(0|1)$/ ) {
  310. if ($1 == "0") {
  311. readingsBulkUpdate($hash, "power", "on" );
  312. $state = "on";
  313. Log3 $hash,5,"PIONEERAVRZONE $name: ".dq($msg) ." interpreted as: Zone2 - Power: on";
  314. } elsif ($1 == "1") {
  315. readingsBulkUpdate($hash, "power", "off" );
  316. $state = "off";
  317. Log3 $hash,5,"PIONEERAVRZONE $name: ".dq($msg) ." interpreted as: Zone2 - Power: off";
  318. }
  319. # Set reading for state
  320. #
  321. if ( !defined( $hash->{READINGS}{state}{VAL} )
  322. || $hash->{READINGS}{state}{VAL} ne $state )
  323. {
  324. readingsBulkUpdate( $hash, "state", $state );
  325. }
  326. }
  327. push @matches, $d;
  328. # zone3
  329. } elsif ($zone eq "zone3") {
  330. # volume zone3
  331. # YVXX
  332. # XX 00 ... 81 -> -81dB ... 0dB
  333. if ( $msg =~ m/^YV(\d\d)$/ ) {
  334. Log3 $name, 5, "PIONEERAVRZONE $name: ". dq($msg) ." interpreted as: Zone3 - New volume = " . $1 . " (raw volume data).";
  335. readingsBulkUpdate($hash, "volumeStraight", $1 - 81 );
  336. readingsBulkUpdate($hash, "volume", sprintf "%d", $1/0.8 );
  337. push @matches, $d;
  338. # Mute zone3
  339. # Z3MUTX
  340. # X = 0: Mute on; X = 1: Mute off
  341. } elsif ( $msg =~ m/^Z3MUT(\d)$/) {
  342. if ($1) {
  343. readingsBulkUpdate($hash, "mute", "off" );
  344. Log3 $name, 5, "PIONEERAVRZONE $name: ". dq($msg) ." interpreted as: Zone3 - Mute off.";
  345. }
  346. else {
  347. readingsBulkUpdate($hash, "mute", "on" );
  348. Log3 $name, 5, "PIONEERAVRZONE $name: ". dq($msg) ." interpreted as: Zone3 - Mute on.";
  349. }
  350. push @matches, $d;
  351. # Input zone3
  352. # Z3FXX
  353. # XX -> input number 00 ... 49
  354. } elsif ($msg =~ m/^Z3F(\d\d)$/ ) {
  355. my $inputNr = $1;
  356. Log3 $hash,5,"PIONEERAVRZONE $name: ".dq($msg) ." interpreted as: Zone3 - Input is set to inputNr: $inputNr ";
  357. if ( defined ( $IOhash->{helper}{INPUTNAMES}->{$inputNr}{aliasName}) ) {
  358. readingsBulkUpdate($hash, "input", $IOhash->{helper}{INPUTNAMES}->{$inputNr}{aliasName} );
  359. Log3 $hash,5,"PIONEERAVRZONE $name: Zone3 - Input aliasName for input $inputNr is " . $hash->{helper}{INPUTNAMES}{$inputNr}{aliasName};
  360. } elsif ( defined ( $IOhash->{helper}{INPUTNAMES}->{$inputNr}{name}) ) {
  361. Log3 $hash,5,"PIONEERAVRZONE $name: Zone3 - Input Name for input $inputNr is " . $hash->{helper}{INPUTNAMES}{$inputNr}{name};
  362. readingsBulkUpdate($hash, "input", $IOhash->{helper}{INPUTNAMES}->{$inputNr}{name} );
  363. } else {
  364. Log3 $hash,5,"PIONEERAVRZONE $name: Zone3 - InputName: can't find Name for input $inputNr";
  365. readingsBulkUpdate($hash, "input", $msg );
  366. }
  367. push @matches, $d;
  368. # Power zone3
  369. # BPRX
  370. # X = 0: Power on; X = 1: Power off
  371. } elsif ( $msg =~ m/^BPR(0|1)$/ ) {
  372. if ($1 == "0") {
  373. Log3 $hash,5,"PIONEERAVRZONE $name: ".dq($msg) ." interpreted as: Zone3 - Power: on";
  374. readingsBulkUpdate($hash, "power", "on" );
  375. $state = "on";
  376. } elsif ($1 == "1") {
  377. Log3 $hash,5,"PIONEERAVRZONE $name: ".dq($msg) ." interpreted as: Zone3 - Power: off";
  378. readingsBulkUpdate($hash, "power", "off" );
  379. $state = "off";
  380. }
  381. # Set reading for state
  382. #
  383. if ( !defined( $hash->{READINGS}{state}{VAL} )
  384. || $hash->{READINGS}{state}{VAL} ne $state )
  385. {
  386. readingsBulkUpdate( $hash, "state", $state );
  387. }
  388. push @matches, $d;
  389. }
  390. # hdZone
  391. } elsif ($zone eq "hdZone") {
  392. # Input hdZone
  393. # ZEAXX
  394. # XX -> input number 00 ... 49
  395. if ($msg =~ m/^ZEA(\d\d)$/ ) {
  396. my $inputNr = $1;
  397. Log3 $hash,5,"PIONEERAVRZONE $name: ".dq($msg) ." interpreted as: hdZone - Input is set to inputNr: $inputNr ";
  398. if ( defined ( $IOhash->{helper}{INPUTNAMES}->{$1}{aliasName}) ) {
  399. Log3 $hash,5,"PIONEERAVRZONE $name: hdZone - Input aliasName for input $inputNr is " . $IOhash->{helper}{INPUTNAMES}{$inputNr}{aliasName};
  400. readingsBulkUpdate($hash, "input", $IOhash->{helper}{INPUTNAMES}->{$1}{aliasName} );
  401. } elsif ( defined ( $IOhash->{helper}{INPUTNAMES}->{$1}{name}) ) {
  402. Log3 $hash,5,"PIONEERAVRZONE $name: hdZone - Input Name for input $inputNr is " . $IOhash->{helper}{INPUTNAMES}{$inputNr}{name};
  403. readingsBulkUpdate($hash, "input", $IOhash->{helper}{INPUTNAMES}->{$1}{name} );
  404. } else {
  405. Log3 $hash,5,"PIONEERAVRZONE $name: Zone3 - InputName: can't find Name for input $inputNr";
  406. readingsBulkUpdate($hash, "input", $msg );
  407. }
  408. push @matches, $d;
  409. # Power hdZone
  410. # ZEPX
  411. # X = 0: Power on; X = 1: Power off
  412. } elsif ( $msg =~ m/^ZEP(0|1)$/ ) {
  413. if ($1 == "0") {
  414. Log3 $hash,5,"PIONEERAVRZONE $name: ".dq($msg) ." interpreted as: hdZone - Power: on";
  415. readingsBulkUpdate($hash, "power", "on" );
  416. $state = "on";
  417. } elsif ($1 == "1") {
  418. Log3 $hash,5,"PIONEERAVRZONE $name: ".dq($msg) ." interpreted as: hdZone - Power: off";
  419. readingsBulkUpdate($hash, "power", "off" );
  420. $state = "off";
  421. }
  422. # Set reading for state
  423. #
  424. if ( !defined( $hash->{READINGS}{state}{VAL} )
  425. || $hash->{READINGS}{state}{VAL} ne $state )
  426. {
  427. readingsBulkUpdate( $hash, "state", $state );
  428. }
  429. push @matches, $d;
  430. }
  431. }
  432. readingsEndUpdate($hash, 1);
  433. }
  434. }
  435. return @matches if(@matches);
  436. return "UNDEFINED PIONEERAVRZONE message1 $msg";
  437. }
  438. #####################################
  439. sub
  440. PIONEERAVRZONE_Attr($@)
  441. {
  442. my @a = @_;
  443. my $hash= $defs{$a[1]};
  444. return undef;
  445. }
  446. #############################
  447. sub
  448. PIONEERAVRZONE_Define($$)
  449. {
  450. my ($hash, $def) = @_;
  451. my @a = split("[ \t]+", $def);
  452. return "Usage: define <name> PIONEERAVRZONE <zone> ... wrong paramter count: ".int(@a) if(int(@a) != 3);
  453. my $name= $a[0];
  454. AssignIoPort($hash);
  455. my $IOhash= $hash->{IODev};
  456. if(!defined($IOhash)) {
  457. my $err= "PIONEERAVRZONE $name error: no I/O device.";
  458. Log3 $hash, 1, $err;
  459. return $err;
  460. }
  461. #Parameter (Zone)
  462. my $zone="";
  463. if ($a[2] =~ m/^(zone\d|hdZone)$/) {
  464. $zone= $a[2];
  465. } else {
  466. my $err= "PIONEERAVRZONE define $name error: unknown Zone ".dq($a[2])." -> must be one of [zone2|zone3|hdZone] (I/O device is "
  467. . $IOhash->{NAME} . "). Usage: define <name> PIONEERAVRZONE <zone>";
  468. Log3 $hash, 1, $err;
  469. return $err;
  470. }
  471. # for autocreate: we store here a pointer of defined devices
  472. # so we can check if the device exists
  473. $modules{PIONEERAVRZONE}{defptr}{$zone} = $hash;
  474. if(!defined($IOhash->{helper}{SETS}{$zone})) {
  475. my $err= "PIONEERAVRZONE define $name error: unknown Zone $zone (I/O device is "
  476. . $IOhash->{NAME} . ").";
  477. Log3 $hash, 1, $err;
  478. return $err;
  479. }
  480. $hash->{helper}{ZONE}= $zone;
  481. # set default attributes
  482. unless ( exists( $attr{$name}{webCmd} ) ) {
  483. $attr{$name}{webCmd} = 'volume:mute:input';
  484. }
  485. unless ( exists( $attr{$name}{devStateIcon} ) ) {
  486. $attr{$name}{devStateIcon} =
  487. 'on:rc_GREEN:off off:rc_STOP:on absent:rc_RED';
  488. }
  489. return undef;
  490. }
  491. #####################################
  492. #Function to show special chars (e.g. \n\r) in logs
  493. #sub
  494. #dq($)
  495. #{
  496. # my ($s)= @_;
  497. # $s= "<nothing>" unless(defined($s));
  498. # return "\"" . escapeLogLine($s) . "\"";
  499. #}
  500. 1;
  501. =pod
  502. =begin html
  503. <a name="PIONEERAVRZONE"></a>
  504. <h3>PIONEERAVRZONE</h3>
  505. <ul>
  506. <br>
  507. <a name="PIONEERAVRZONEdefine"></a>
  508. <b>Define</b>
  509. <ul>
  510. <code>define &lt;name&gt; PIONEERAVRZONE &lt;zone&gt; </code>
  511. <br><br>
  512. Defines a Zone (zone2, zone3 or hdZone) of a PioneerAVR device.<br>
  513. Note: devices to control zone2, zone3 and/or HD-zone are autocreated on reception of the first message for those zones.<br><br>
  514. Normally, the PIONEERAVRZONE device is attached to the latest previously defined PIONEERAVR device
  515. for I/O. Use the <code>IODev</code> attribute of the PIONEERAVRZONE device to attach to any
  516. PIONEERAVR device, e.g. <code>attr myPioneerAvrZone2 IODev myPioneerAvr</code>.
  517. <br><br>
  518. Examples:
  519. <ul>
  520. <code>define myPioneerAvrZone2 PIONEERAVRZONE zone2</code><br>
  521. <code>attr myPioneerAvrZone2 IODev myPIONEERAVR</code>
  522. </ul>
  523. <br>
  524. </ul>
  525. <a name="PIONEERAVRZONEset"></a>
  526. <b>Set</b>
  527. <ul>
  528. <code>set &lt;name&gt; &lt;what&gt; [&lt;value&gt;]</code>
  529. <br><br>
  530. where &lt;what&gt; is one of
  531. <li>reopen</li>
  532. <li>off <br>put zone into standby</li>
  533. <li>on <br>turn zone on from standby</li>
  534. <li>toggle <br>toggles zone power</li>
  535. <li>volume <0 ... 100><br>zone volume in % of the maximum volume</li>
  536. <li>volumeUp<br>increases the zone volume by 0.5dB</li>
  537. <li>volumeDown<br>decreases the zone volume by 0.5dB</li>
  538. <li>volumeStraight<-80.5 ... 12><br>same values for zone volume as shown on the display of the Pioneer AV receiver</li>
  539. <li>mute <on|off|toggle></li>
  540. <li>input <not on the Pioneer hardware deactivated input><br>the list of possible (i.e. not deactivated)
  541. inputs is read in during Fhem start and with <code>get <name> statusRequest</code></li>
  542. <li>inputUp<br>change zone input to next input</li>
  543. <li>inputDown<br>change zone input to previous input</li>
  544. <li><a href="#setExtensions">set extensions</a> are supported (except <code>&lt;name&gt;</code>)</li>
  545. <br><br>
  546. Example:
  547. <ul>
  548. <code>set VSX923Zone2 on</code><br>
  549. </ul>
  550. <br><br>
  551. </ul>
  552. <a name="PIONEERAVRZONEget"></a>
  553. <b>Get</b>
  554. <ul>
  555. <li><code>get &lt;name&gt; input</code>
  556. <br><br>
  557. Update the reading for the zone input
  558. </li>
  559. </ul>
  560. <br><br>
  561. <a name="PIONEERAVRattr"></a>
  562. <b>Attributes</b>
  563. <br><br>
  564. <ul>
  565. <li>IOdev Name of the device which communicates with the phisical Pioneer AV receiver via ethernet or rs232</li>
  566. <li><a href="#verbose">verbose</a></li>
  567. </ul>
  568. <br><br>
  569. </ul>
  570. =end html
  571. =begin html_DE
  572. <a name="PIONEERAVRZONE"></a>
  573. <h3>PIONEERAVRZONE</h3>
  574. <ul>
  575. <br>
  576. <a name="PIONEERAVRZONEdefine"></a>
  577. <b>Define</b>
  578. <ul>
  579. <code>define &lt;name&gt; PIONEERAVRZONE &lt;zone&gt; </code>
  580. <br><br>
  581. Definiert ein PioneerAVR device für eine Zone Zone (zone2, zone3 or hdZone).<p>
  582. Im Allgemeinen verwendet das logische device PIONEERAVRZONE das zuletzt definierte PIONEERAVR device für die Kommunikation mit dem Pioneer AV Receiver.
  583. Mit dem Atribut <code>IODev</code> kann das PIONEERAVRZONE device jedes PIONEERAVR device zur Kommunikation verwenden,
  584. z.B. <code>attr myPioneerAvrZone2 IODev myPioneerAvr</code>.
  585. <br><br>
  586. Examples:
  587. <ul>
  588. <code>define myPioneerAvrZone2 PIONEERAVRZONE zone2</code><br>
  589. <code>attr myPioneerAvrZone2 IODev myPIONEERAVR</code>
  590. </ul>
  591. <br>
  592. </ul>
  593. <a name="PIONEERAVRZONEset"></a>
  594. <b>Set</b>
  595. <ul>
  596. <code>set &lt;name&gt; &lt;was&gt; [&lt;value&gt;]</code>
  597. <br><br>
  598. wobei &lt;was&gt; eines der folgenden Befehle sein kann:
  599. <li>reopen</li>
  600. <li>off <br>Zone in den Standby-Modus schalten</li>
  601. <li>on <br>Zone aus dem Standby-Modus Einschalten</li>
  602. <li>toggle <br>Zone Ein/Ausschalten</li>
  603. <li>volume <0 ... 100><br>Zonenlautstärke in % der maximalen Lautstärke</li>
  604. <li>volumeUp<br>Zonenlautstärke um 0.5dB erhöhen</li>
  605. <li>volumeDown<br>Zonenlautstärke um 0.5dB verringern</li>
  606. <li>volumeStraight<-80.5 ... 12><br>Einstellen der Zonenlautstärke mit einem Wert, wie er am Display des Pioneer AV Receiver angezeigt wird</li>
  607. <li>mute <on|off|toggle></li>
  608. <li>input <nicht am Pioneer AV Receiver deaktivierte Eingangsquelle><br> Die Liste der verfügbaren (also der nicht deaktivierten)
  609. Eingangsquellen wird beim Start von Fhem und auch mit <code>get <name> statusRequest</code> eingelesen</li>
  610. <li>inputUp<br>nächste Eingangsquelle für die Zone auswählen</li>
  611. <li>inputDown<br>vorherige Eingangsquelle für die Zone auswählen</li>
  612. <li><a href="#setExtensions">set extensions</a> (ausser <code>&lt;name&gt;</code>) werden unterstützt</li>
  613. <br><br>
  614. Beispiel:
  615. <ul>
  616. <code>set VSX923Zone2 on</code><br>
  617. </ul>
  618. <br><br>
  619. </ul>
  620. <a name="PIONEERAVRZONEget"></a>
  621. <b>Get</b>
  622. <ul>
  623. <li><code>get &lt;name&gt; input</code>
  624. <br><br>
  625. reading für die Eingangsquelle aktualisieren
  626. </li>
  627. </ul>
  628. <br><br>
  629. <a name="PIONEERAVRattr"></a>
  630. <b>Attributes</b>
  631. <br><br>
  632. <ul>
  633. <li>IOdev Name des device welches die Kommunikation mit dem Pioneer AV Receiver zur Verfügung stellt</li>
  634. <li><a href="#verbose">verbose</a></li>
  635. </ul>
  636. <br><br>
  637. </ul>
  638. =end html_DE
  639. =cut