70_EGPM.pm 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. ##############################################
  2. # $Id: 70_EGPM.pm 14071 2017-04-22 12:13:43Z alexus $
  3. #
  4. # (c) 2013, 2017 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} = "$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 $cmdList = "off:noArg on:noArg toggle:noArg";
  47. return "no set value specified" if(int(@a) < 1);
  48. return SetExtensions($hash,$cmdList,$name,@a) if($a[0] eq "?");
  49. if(not Value($parent))
  50. {
  51. my $u = "$parent device not found. Please define EGPM2LAN device.";
  52. Log3 $name, 1, $u;
  53. return $u;
  54. }
  55. if($a[0] =~ /^(on|off|toggle)$/)
  56. {
  57. my $v = join(" ", @a);
  58. Log3 $name, 4, "EGPM set $name $v";
  59. CommandSet(undef,$hash->{IODEV}." $v ".$hash->{SOCKETNR});
  60. return undef;
  61. } else {
  62. Log3 $name, 4, "EGPM set $name $a[0]";
  63. return SetExtensions($hash,$cmdList,$name,@a);
  64. }
  65. }
  66. ###################################
  67. sub
  68. EGPM_Get($@)
  69. {
  70. my ($hash, @a) = @_;
  71. my $what;
  72. return "argument is missing" if(int(@a) != 2);
  73. $what = $a[1];
  74. if($what =~ /^(state)$/)
  75. {
  76. if(defined($hash->{READINGS}{$what}))
  77. {
  78. return $hash->{READINGS}{$what}{VAL};
  79. }
  80. else
  81. {
  82. return "reading not found: $what";
  83. }
  84. }
  85. else
  86. {
  87. return "Unknown argument $what, choose one of state:noArg".(exists($hash->{READINGS}{output})?" output:noArg":"");
  88. }
  89. }
  90. #####################################
  91. sub
  92. EGPM_Define($$)
  93. {
  94. my ($hash, $def) = @_;
  95. my @a = split("[ \t][ \t]*", $def);
  96. my $u = "wrong syntax: use define <name> EGPM <Device> <socketNr.>";
  97. return $u if(int(@a) < 4);
  98. my $name = $a[0];
  99. my $parent = $a[2];
  100. my $socket = $a[3];
  101. $hash->{IODEV} = $parent;
  102. $hash->{SOCKETNR} = $socket;
  103. $hash->{NAME} = $name;
  104. $modules{EGPM}{defptr}{$parent.$socket} = $hash;
  105. if (defined($attr{$parent}{room}))
  106. {
  107. $attr{$name}{room} = $attr{$parent}{room};
  108. }
  109. my $currentstate = ReadingsVal($parent, "state", "?");
  110. if ($currentstate eq "?")
  111. {
  112. $hash->{STATE} = "initialized";
  113. }
  114. else
  115. {
  116. my @powerstates = split(":", $currentstate);
  117. $hash->{STATE} = trim(substr $powerstates[$socket], 1, 3);
  118. }
  119. return undef;
  120. }
  121. #####################################
  122. sub
  123. EGPM_Undef($$)
  124. {
  125. my ($hash, $name) = @_;
  126. my $parent = $hash->{IODEV};
  127. my $socket = $hash->{SOCKETNR};
  128. Log3 $name, 3 ,"EGPM: Delete ".$parent.$socket;
  129. delete $modules{EGPM}{defptr}{$parent.$socket} ;
  130. return undef;
  131. }
  132. 1;
  133. =pod
  134. =item device
  135. =item summary controls a single Socket of EGPM2LAN-Module
  136. =item summary_DE steuert eine Steckdose von der EGPM2LAN-Steckdosenleiste
  137. =begin html
  138. <a name="EGPM"></a>
  139. <h3>EGPM Socket</h3>
  140. <ul>
  141. Defines a Socket from EGPM2LAN Module. If the global Module AUTOCREATE is enabled,
  142. this device will be created automatically. For manual Setup, pls. see the description of <a href="#EGPM2LAN">EGPM2LAN</a>.
  143. <br><br>
  144. <a name="EGPMdefine"></a>
  145. <b>Define</b>
  146. <ul>
  147. <code>define &lt;name&gt; EGPM &lt;device&gt; &lt;socket-nr&gt;</code>
  148. <br>
  149. </ul>
  150. <br>
  151. <a name="EGPMset"></a>
  152. <b>Set</b>
  153. <ul><code>set &lt;name&gt; &lt;[on|off|toggle]&gt;</code><br>
  154. Switches the socket on or of.
  155. </ul>
  156. <ul><code>set &lt;name&gt; &lt;[on-for-timer|off-for-timer|on-till|off-till|blink|intervals]&gt;</code><br>
  157. Switches the socket for a specified time+duration or n-times. For Details see <a href="#setExtensions">set extensions</a>
  158. </ul><br>
  159. Example:
  160. <ul>
  161. <code>define lamp1 EGPM mainswitch 1</code><br>
  162. <code>set lamp1 on</code><br>
  163. </ul>
  164. <br>
  165. <a name="EGPMget"></a>
  166. <b>Get</b> <ul>N/A</ul><br>
  167. <a name="EGPMattr"></a>
  168. <b>Attributes</b>
  169. <ul>
  170. <li><a href="#readingFnAttributes">readingFnAttributes</a></li>
  171. </ul>
  172. <br>
  173. <a name="EGPM2LANevents"></a>
  174. <b>Generated events</b>
  175. <ul>
  176. <li>EGPM &lt;name&gt; &lt;[on|off]&gt</li>
  177. </ul>
  178. </ul>
  179. =end html
  180. =begin html_DE
  181. <a name="EGPM"></a>
  182. <h3>EGPM Steckdose</h3>
  183. <ul>
  184. Definiert eine einzelne Netzwerk-Steckdose vom EGPM2LAN. Diese Definition wird beim Einrichten eines EGPM2LAN automatisch erstellt,
  185. wenn das globale FHEM-Attribut AUTOCREATE aktiviert wurde. F&uuml;r weitere Informationen, siehe Beschreibung von <a href="#EGPM2LAN">EGPM2LAN</a>.
  186. <br><br>
  187. <a name="EGPMdefine"></a>
  188. <b>Define</b>
  189. <ul>
  190. <code>define &lt;name&gt; EGPM &lt;device&gt; &lt;socket-nr&gt;</code>
  191. <br>
  192. </ul>
  193. <br>
  194. <a name="EGPMset"></a>
  195. <b>Set</b>
  196. <ul><code>set &lt;name&gt; &lt;[on|off|toggle]&gt;</code><br>
  197. Schaltet die Steckdose ein oder aus.
  198. </ul>
  199. <ul><code>set &lt;name&gt; &lt;[on-for-timer|off-for-timer|on-till|off-till|blink|intervals]&gt;</code><br>
  200. Schaltet die Steckdose f&uuml; einen bestimmten Zeitraum oder mehrfach hintereinander. Weitere Infos hierzu unter <a href="#setExtensions">set extensions</a>.
  201. </ul><br>
  202. Beispiel:
  203. <ul>
  204. <code>define lampe1 EGPM steckdose 1</code><br>
  205. <code>set lampe1 on</code><br>
  206. </ul>
  207. <br>
  208. <a name="EGPMget"></a>
  209. <b>Get</b> <ul>N/A</ul>
  210. <br>
  211. <a name="EGPMattr"></a>
  212. <b>Attributes</b>
  213. <ul>
  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