24_Iluminize.pm 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. ################################################################################################
  2. #
  3. # $Id: 24_Iluminize.pm 17537 2018-10-15 16:08:23Z vk $
  4. #
  5. #
  6. # Copyright notice
  7. #
  8. # Release 2018-10 First version
  9. #
  10. # (c) 2018 Copyright: Volker Kettenbach
  11. # e-mail: volker at kettenbach minus it dot de
  12. #
  13. # Description:
  14. # This is an FHEM-Module for the Iluinize LED Stripes,
  15. #
  16. # Requirements:
  17. # This module requires:
  18. # Perl Module: IO::Socket::INET
  19. # Perl Module: IO::Socket::Timeout
  20. # On a Debian (based) system, these requirements can be fullfilled by:
  21. # apt-get install install libio-socket-inet6-perl libio-socket-timeout-perl
  22. #
  23. # Origin:
  24. # https://gitlab.com/volkerkettenbach/FHEM-Iluminize
  25. #
  26. # Support: https://forum.fhem.de/index.php/topic,92007.0.html
  27. #
  28. #
  29. #################################################################################################
  30. package main;
  31. use strict;
  32. use warnings;
  33. sub Iluminize_Initialize($)
  34. {
  35. my ($hash) = @_;
  36. $hash->{DefFn} = "Iluminize::Define";
  37. $hash->{ReadFn} = "Iluminize::Get";
  38. $hash->{SetFn} = "Iluminize::Set";
  39. $hash->{UndefFn} = "Iluminize::Undefine";
  40. $hash->{DeleteFn} = "Iluminize::Delete";
  41. $hash->{AttrFn} = "Iluminize::Attr";
  42. $hash->{AttrList} = "$readingFnAttributes";
  43. }
  44. package Iluminize;
  45. use strict;
  46. use warnings;
  47. use POSIX;
  48. use IO::Socket::INET;
  49. use IO::Socket::Timeout;
  50. use SetExtensions;
  51. use GPUtils qw(:all); # wird für den Import der FHEM Funktionen aus der fhem.pl benötigt
  52. ## Import der FHEM Funktionen
  53. BEGIN {
  54. GP_Import(qw(
  55. readingsSingleUpdate
  56. readingsBulkUpdate
  57. readingsBulkUpdateIfChanged
  58. readingsBeginUpdate
  59. readingsEndUpdate
  60. Log3
  61. CommandAttr
  62. AttrVal
  63. ReadingsVal
  64. CommandDefMod
  65. modules
  66. setKeyValue
  67. getKeyValue
  68. getUniqueId
  69. RemoveInternalTimer
  70. InternalTimer
  71. defs
  72. init_done
  73. IsDisabled
  74. deviceEvents
  75. HttpUtils_NonblockingGet
  76. gettimeofday
  77. Dispatch
  78. SetExtensions
  79. ))
  80. };
  81. my $on =
  82. chr(hex("55")) .
  83. chr(hex("99")) .
  84. chr(hex("5e")) .
  85. chr(hex("bb")) .
  86. chr(hex("01")) .
  87. chr(hex("02")) .
  88. chr(hex("02")) .
  89. chr(hex("12")) .
  90. chr(hex("ab")) .
  91. chr(hex("c2")) .
  92. chr(hex("aa")) .
  93. chr(hex("aa"));
  94. my $off=
  95. chr(hex("55")) .
  96. chr(hex("99")) .
  97. chr(hex("5e")) .
  98. chr(hex("bb")) .
  99. chr(hex("01")) .
  100. chr(hex("02")) .
  101. chr(hex("02")) .
  102. chr(hex("12")) .
  103. chr(hex("a9")) .
  104. chr(hex("c0")) .
  105. chr(hex("aa")) .
  106. chr(hex("aa"));
  107. sub Define($$)
  108. {
  109. my ($hash, $def) = @_;
  110. my $name= $hash->{NAME};
  111. my @a = split( "[ \t][ \t]*", $def );
  112. return "Wrong syntax: use define <name> Iluminize <hostname/ip> " if (int(@a) != 3);
  113. $hash->{HOST}=$a[2];
  114. Log3 $hash, 0, "Iluminize: $name defined.";
  115. return undef;
  116. }
  117. # No get so far
  118. sub Get($$) {}
  119. sub Set($$)
  120. {
  121. my ($hash, $name, $cmd, @args) = @_;
  122. my $cmdList = "on off";
  123. my $remote_host = $hash->{HOST};
  124. my $remote_port = 8899;
  125. Log3 $hash, 3, "Iluminize: $name Set <". $cmd ."> called" if ($cmd !~ /\?/);
  126. return "\"set $name\" needs at least one argument" unless(defined($cmd));
  127. my $command;
  128. if ($cmd eq "on") {
  129. $command = $on;
  130. readingsSingleUpdate($hash, "state", "on", 1);
  131. } elsif($cmd eq "off") {
  132. $command = $off;
  133. readingsSingleUpdate($hash, "state", "off", 1);
  134. } else {
  135. return SetExtensions($hash, $cmdList, $name, $cmd, @args);
  136. }
  137. my $socket = IO::Socket::INET->new(PeerAddr => $remote_host,
  138. PeerPort => $remote_port,
  139. Proto => 'tcp',
  140. Type => SOCK_STREAM,
  141. Timeout => 2 )
  142. or return "Couldn't connect to $remote_host:$remote_port: $@\n";
  143. $socket->write($command);
  144. return undef;
  145. }
  146. sub Undefine($$)
  147. {
  148. my ($hash, $arg) = @_;
  149. my $name= $hash->{NAME};
  150. Log3 $hash, 4, "Iluminize: $name undefined.";
  151. return;
  152. }
  153. sub Delete($$) {
  154. my ($hash, $arg) = @_;
  155. my $name= $hash->{NAME};
  156. Log3 $hash, 0, "Ilumnize: $name deleted.";
  157. return undef;
  158. }
  159. sub Attr($$$$) {
  160. my ($cmd, $name, $aName, $aVal) = @_;
  161. my $hash = $defs{$name};
  162. return undef;
  163. }
  164. 1;
  165. =pod
  166. =item summary Support for Iluminize wifi controlled led stripe
  167. =item summary_DE Support für die Iluminize wlan LED-Produkte
  168. =begin html
  169. <a name="Iluminize"></a>
  170. <h3>Iluminize</h3>
  171. <br>
  172. <a name="Iluminize"></a>
  173. <b>Define</b>
  174. <code>define &lt;name&gt; Iluminize &lt;ip/hostname&gt;</code><br>
  175. <br>
  176. Defines a wifi controlled Iluminize LED light
  177. =end html
  178. =begin html_DE
  179. <a name="Iluminize"></a>
  180. <h3>Iluminize</h3>
  181. <br>
  182. <a name="Iluminize"></a>
  183. <b>Define</b>
  184. <code>define &lt;name&gt; Iluminize &lt;ip/hostname&gt;</code><br>
  185. <br>
  186. Definiert ein Iluminize LED Wifi-Licht
  187. =end html_DE