30_pilight_raw.pm 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. ##############################################
  2. # $Id: 30_pilight_raw.pm 12478 2016-10-31 13:20:55Z risiko79 $
  3. #
  4. # Usage
  5. #
  6. # define <name> pilight_raw
  7. #
  8. # Changelog
  9. #
  10. # V 0.10 2015-07-21 - initial beta version
  11. # V 0.11 2015-07-27 - SetExtensions on-for-timer
  12. # V 0.12 2015-12-17 - NEW: Attribut IODev to switch IO-Device
  13. # V 0.13 2016-10-31 - NEW: Attribut sendCount
  14. ##############################################
  15. package main;
  16. use strict;
  17. use warnings;
  18. use Switch; #libswitch-perl
  19. use SetExtensions;
  20. my %sets = ("on:noArg"=>0, "off:noArg"=>0, "code:textField-long"=>1);
  21. sub pilight_raw_Parse($$);
  22. sub pilight_raw_Define($$);
  23. sub pilight_raw_Initialize($)
  24. {
  25. my ($hash) = @_;
  26. $hash->{DefFn} = "pilight_raw_Define";
  27. $hash->{Match} = "^PIRAW";
  28. $hash->{SetFn} = "pilight_raw_Set";
  29. $hash->{AttrList} = "onCode:textField-long offCode:textField-long IODev sendCount:1,2,3,4,5 ".$readingFnAttributes;
  30. }
  31. #####################################
  32. sub pilight_raw_Define($$)
  33. {
  34. my ($hash, $def) = @_;
  35. my @a = split("[ \t][ \t]*", $def);
  36. if(@a < 2) {
  37. my $msg = "wrong syntax: define <name> pilight_raw";
  38. Log3 undef, 2, $msg;
  39. return $msg;
  40. }
  41. my $me = $a[0];
  42. $hash->{PROTOCOL} = "raw";
  43. #$attr{$me}{verbose} = 5;
  44. $modules{pilight_raw}{defptr}{"raw"}{$me} = $hash;
  45. AssignIoPort($hash);
  46. return undef;
  47. }
  48. #####################################
  49. sub pilight_raw_Set($$)
  50. {
  51. my ($hash, $me, $cmd, @a) = @_;
  52. my $v = join(" ", @a);
  53. Log3 $me, 4, "$me(Set): $v";
  54. #-- check argument
  55. return "no set value specified" unless defined($cmd);
  56. my @match = grep( $_ =~ /^$cmd($|:)/, keys %sets );
  57. return SetExtensions($hash, join(" ", keys %sets), $me, $cmd, @a) unless @match == 1;
  58. #return "$cmd expects $sets{$match[0]} parameters" unless (@a eq $sets{$match[0]});
  59. my $code_on = $attr{$me}{onCode};
  60. my $code_off = $attr{$me}{offCode};
  61. my $code = "";
  62. my $updateReading = 0;
  63. switch($cmd){
  64. case "on" { $code = $code_on; $updateReading = 1;}
  65. case "off" { $code = $code_off; $updateReading = 1;}
  66. case "code" { $v =~ s/code//g; $code=$v;}
  67. }
  68. if($code eq "") {
  69. Log3 $me, 2, "$me(Set): No value for code given";
  70. return "No value for code given";
  71. }
  72. my $msg = "$me,$code";
  73. my $sndCount = AttrVal($me,"sendCount",1);
  74. for (my $i = 0; $i < $sndCount; $i++) {
  75. Log3 $me, 5, "$me(Set): $cmd $v".($i+1)." of $sndCount";
  76. IOWrite($hash, $msg);
  77. }
  78. readingsSingleUpdate($hash,"state",$cmd,1) if($updateReading == 1);
  79. return undef;
  80. }
  81. 1;
  82. =pod
  83. =item summary Sending pilight raw codes
  84. =item summary_DE Send pilight Raw-Codes
  85. =begin html
  86. <a name="pilight_raw"></a>
  87. <h3>pilight_raw</h3>
  88. <ul>
  89. With pilight_raw it si possible to send raw codes<br>
  90. You have to define the base device pilight_ctrl first.<br>
  91. <br>
  92. <a name="pilight_raw_define"></a>
  93. <b>Define</b>
  94. <ul>
  95. <code>define &lt;name&gt; pilight_raw</code>
  96. </ul>
  97. <br>
  98. <a name="pilight_raw_set"></a>
  99. <p><b>Set</b></p>
  100. <ul>
  101. <li>
  102. <b>on</b>
  103. Send 'onCode' as raw code
  104. </li>
  105. <li>
  106. <b>off</b>
  107. Send 'offCode' as raw code
  108. </li>
  109. <li>
  110. <b>code <value></b>
  111. Send <value> as raw code
  112. </li>
  113. <li>
  114. <a href="#setExtensions">set extensions</a> are supported<br>
  115. </li>
  116. </ul>
  117. <br>
  118. <a name="pilight_raw_readings"></a>
  119. <p><b>Readings</b></p>
  120. <ul>
  121. <li>
  122. state<br>
  123. state on or off
  124. </li>
  125. </ul>
  126. <br>
  127. <a name="pilight_raw_attr"></a>
  128. <b>Attributes</b>
  129. <ul>
  130. <li><a name="onCode">onCode</a><br>
  131. raw code for state on
  132. </li>
  133. <li><a name="offCode">onCode</a><br>
  134. raw code for state off
  135. </li>
  136. <li>
  137. sendCount<br>
  138. How many times the command is send. Default: 1
  139. </li>
  140. </ul>
  141. </ul>
  142. =end html
  143. =cut