70_EGPM.pm 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. ##############################################
  2. # $Id: 70_EGPM.pm 5344 2014-03-27 20:06:31Z alexus2033 $
  3. #
  4. # (c) 2013, 2014 Copyright: Alex Storny (moselking at arcor dot de)
  5. # All rights reserved
  6. #
  7. # This script free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # any later version.
  11. #
  12. # The GNU General Public License can be found at
  13. # http://www.gnu.org/copyleft/gpl.html.
  14. # A copy is found in the textfile GPL.txt and important notices to the license
  15. # from the author is found in LICENSE.txt distributed with these scripts.
  16. #
  17. # This script is distributed in the hope that it will be useful,
  18. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. # GNU General Public License for more details.
  21. #
  22. ################################################################
  23. # -> Module 17_EGPM2LAN.pm (Host) needed.
  24. ################################################################
  25. package main;
  26. use strict;
  27. use warnings;
  28. use SetExtensions;
  29. sub
  30. EGPM_Initialize($)
  31. {
  32. my ($hash) = @_;
  33. $hash->{SetFn} = "EGPM_Set";
  34. $hash->{GetFn} = "EGPM_Get";
  35. $hash->{DefFn} = "EGPM_Define";
  36. $hash->{AttrList} = "loglevel:0,1,2,3,4,5,6 $readingFnAttributes ";
  37. $hash->{UndefFn} = "EGPM_Undef";
  38. }
  39. ###################################
  40. sub
  41. EGPM_Set($@)
  42. {
  43. my ($hash, @a) = @_;
  44. my $name = shift @a;
  45. my $parent = $hash->{IODEV};
  46. my $loglevel = GetLogLevel($name,4);
  47. my $cmdList = "off:noArg on:noArg toggle:noArg";
  48. return "no set value specified" if(int(@a) < 1);
  49. return SetExtensions($hash,$cmdList,$name,@a) if($a[0] eq "?");
  50. if(not Value($parent))
  51. {
  52. my $u = "$parent device not found. Please define EGPM2LAN device.";
  53. Log $loglevel, $u;
  54. return $u;
  55. }
  56. if($a[0] =~ /^(on|off|toggle)$/)
  57. {
  58. my $v = join(" ", @a);
  59. Log $loglevel, "EGPM set $name $v";
  60. CommandSet(undef,$hash->{IODEV}." $v ".$hash->{SOCKETNR});
  61. return undef;
  62. } else {
  63. Log $loglevel, "EGPM set $name $a[0]";
  64. return SetExtensions($hash,$cmdList,$name,@a);
  65. }
  66. }
  67. ###################################
  68. sub
  69. EGPM_Get($@)
  70. {
  71. my ($hash, @a) = @_;
  72. my $what;
  73. return "argument is missing" if(int(@a) != 2);
  74. $what = $a[1];
  75. if($what =~ /^(state)$/)
  76. {
  77. if(defined($hash->{READINGS}{$what}))
  78. {
  79. return $hash->{READINGS}{$what}{VAL};
  80. }
  81. else
  82. {
  83. return "reading not found: $what";
  84. }
  85. }
  86. else
  87. {
  88. return "Unknown argument $what, choose one of state:noArg".(exists($hash->{READINGS}{output})?" output:noArg":"");
  89. }
  90. }
  91. #####################################
  92. sub
  93. EGPM_Define($$)
  94. {
  95. my ($hash, $def) = @_;
  96. my @a = split("[ \t][ \t]*", $def);
  97. my $u = "wrong syntax: use define <name> EGPM <Device> <socketNr.>";
  98. return $u if(int(@a) < 4);
  99. my $name = $a[0];
  100. my $parent = $a[2];
  101. my $socket = $a[3];
  102. $hash->{IODEV} = $parent;
  103. $hash->{SOCKETNR} = $socket;
  104. $hash->{NAME} = $name;
  105. $modules{EGPM}{defptr}{$parent.$socket} = $hash;
  106. if (defined($attr{$parent}{room}))
  107. {
  108. $attr{$name}{room} = $attr{$parent}{room};
  109. }
  110. my $currentstate = ReadingsVal($parent, "state", "?");
  111. if ($currentstate eq "?")
  112. {
  113. $hash->{STATE} = "initialized";
  114. }
  115. else
  116. {
  117. my @powerstates = split(":", $currentstate);
  118. $hash->{STATE} = trim(substr $powerstates[$socket], 1, 3);
  119. }
  120. return undef;
  121. }
  122. #####################################
  123. sub
  124. EGPM_Undef($$)
  125. {
  126. my ($hash, $name) = @_;
  127. my $parent = $hash->{IODEV};
  128. my $socket = $hash->{SOCKETNR};
  129. Log GetLogLevel($name,4), "Delete ".$parent.$socket;
  130. delete $modules{EGPM}{defptr}{$parent.$socket} ;
  131. return undef;
  132. }
  133. 1;
  134. =pod
  135. =begin html
  136. <a name="EGPM"></a>
  137. <h3>EGPM Socket</h3>
  138. <ul>
  139. Defines a Socket from EGPM2LAN Module. If the global Module AUTOCREATE is enabled,
  140. this device will be created automatically. For manual Setup, pls. see the description of <a href="#EGPM2LAN">EGPM2LAN</a>.
  141. <br><br>
  142. <a name="EGPMdefine"></a>
  143. <b>Define</b>
  144. <ul>
  145. <code>define &lt;name&gt; EGPM &lt;device&gt; &lt;socket-nr&gt;</code>
  146. <br>
  147. </ul>
  148. <br>
  149. <a name="EGPMset"></a>
  150. <b>Set</b>
  151. <ul><code>set &lt;name&gt; &lt;[on|off|toggle]&gt;</code><br>
  152. Switches the socket on or of.
  153. </ul>
  154. <ul><code>set &lt;name&gt; &lt;[on-for-timer|off-for-timer|on-till|off-till|blink|intervals]&gt;</code><br>
  155. Switches the socket for a specified time+duration or n-times. For Details see <a href="#setExtensions">set extensions</a>
  156. </ul><br>
  157. Example:
  158. <ul>
  159. <code>define lamp1 EGPM mainswitch 1</code><br>
  160. <code>set lamp1 on</code><br>
  161. </ul>
  162. <br>
  163. <a name="EGPMget"></a>
  164. <b>Get</b> <ul>N/A</ul><br>
  165. <a name="EGPMattr"></a>
  166. <b>Attributes</b>
  167. <ul>
  168. <li><a href="#loglevel">loglevel</a></li>
  169. <li><a href="#readingFnAttributes">readingFnAttributes</a></li>
  170. </ul>
  171. <br>
  172. <a name="EGPM2LANevents"></a>
  173. <b>Generated events</b>
  174. <ul>
  175. <li>EGPM &lt;name&gt; &lt;[on|off]&gt</li>
  176. </ul>
  177. </ul>
  178. =end html
  179. =begin html_DE
  180. <a name="EGPM"></a>
  181. <h3>EGPM Steckdose</h3>
  182. <ul>
  183. Definiert eine einzelne Netzwerk-Steckdose vom EGPM2LAN. Diese Definition wird beim Einrichten eines EGPM2LAN automatisch erstellt,
  184. wenn das globale FHEM-Attribut AUTOCREATE aktiviert wurde. F&uuml;r weitere Informationen, siehe Beschreibung von <a href="#EGPM2LAN">EGPM2LAN</a>.
  185. <br><br>
  186. <a name="EGPMdefine"></a>
  187. <b>Define</b>
  188. <ul>
  189. <code>define &lt;name&gt; EGPM &lt;device&gt; &lt;socket-nr&gt;</code>
  190. <br>
  191. </ul>
  192. <br>
  193. <a name="EGPMset"></a>
  194. <b>Set</b>
  195. <ul><code>set &lt;name&gt; &lt;[on|off|toggle]&gt;</code><br>
  196. Schaltet die Steckdose ein oder aus.
  197. </ul>
  198. <ul><code>set &lt;name&gt; &lt;[on-for-timer|off-for-timer|on-till|off-till|blink|intervals]&gt;</code><br>
  199. Schaltet die Steckdose f&uuml; einen bestimmten Zeitraum oder mehrfach hintereinander. Weitere Infos hierzu unter <a href="#setExtensions">set extensions</a>.
  200. </ul><br>
  201. Beispiel:
  202. <ul>
  203. <code>define lampe1 EGPM steckdose 1</code><br>
  204. <code>set lampe1 on</code><br>
  205. </ul>
  206. <br>
  207. <a name="EGPMget"></a>
  208. <b>Get</b> <ul>N/A</ul>
  209. <br>
  210. <a name="EGPMattr"></a>
  211. <b>Attributes</b>
  212. <ul>
  213. <li><a href="#loglevel">loglevel</a></li>
  214. <li><a href="#readingFnAttributes">readingFnAttributes</a></li>
  215. </ul>
  216. <br>
  217. <a name="EGPM2LANevents"></a>
  218. <b>Generated events</b>
  219. <ul>
  220. <li>EGPM &lt;name&gt; &lt;[on|off]&gt</li>
  221. </ul>
  222. </ul>
  223. =end html_DE
  224. =cut