20_GUEST.pm 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866
  1. # $Id: 20_GUEST.pm 13439 2017-02-18 21:10:08Z loredo $
  2. ##############################################################################
  3. #
  4. # 20_GUEST.pm
  5. # Submodule of 10_RESIDENTS.
  6. #
  7. # Copyright by Julian Pawlowski
  8. # e-mail: julian.pawlowski at gmail.com
  9. #
  10. # This file is part of fhem.
  11. #
  12. # Fhem is free software: you can redistribute it and/or modify
  13. # it under the terms of the GNU General Public License as published by
  14. # the Free Software Foundation, either version 2 of the License, or
  15. # (at your option) any later version.
  16. #
  17. # Fhem 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. # You should have received a copy of the GNU General Public License
  23. # along with fhem. If not, see <http://www.gnu.org/licenses/>.
  24. #
  25. ##############################################################################
  26. package main;
  27. use strict;
  28. use warnings;
  29. use Time::Local;
  30. use Data::Dumper;
  31. require RESIDENTStk;
  32. no if $] >= 5.017011, warnings => 'experimental';
  33. sub GUEST_Set($@);
  34. sub GUEST_Define($$);
  35. sub GUEST_Notify($$);
  36. sub GUEST_Undefine($$);
  37. ###################################
  38. sub GUEST_Initialize($) {
  39. my ($hash) = @_;
  40. Log3 $hash, 5, "GUEST_Initialize: Entering";
  41. $hash->{SetFn} = "GUEST_Set";
  42. $hash->{DefFn} = "GUEST_Define";
  43. $hash->{NotifyFn} = "GUEST_Notify";
  44. $hash->{UndefFn} = "GUEST_Undefine";
  45. $hash->{AttrList} =
  46. "rg_locationHome rg_locationWayhome rg_locationUnderway rg_autoGoneAfter:12,16,24,26,28,30,36,48,60 rg_showAllStates:0,1 rg_realname:group,alias rg_states:multiple-strict,home,gotosleep,asleep,awoken,absent,gone rg_locations rg_moods rg_moodDefault rg_moodSleepy rg_noDuration:0,1 rg_wakeupDevice rg_geofenceUUIDs rg_presenceDevices "
  47. . $readingFnAttributes;
  48. }
  49. ###################################
  50. sub GUEST_Define($$) {
  51. my ( $hash, $def ) = @_;
  52. my @a = split( "[ \t][ \t]*", $def );
  53. my $name = $hash->{NAME};
  54. my $name_attr;
  55. Log3 $name, 5, "GUEST $name: called function GUEST_Define()";
  56. if ( int(@a) < 2 ) {
  57. my $msg = "Wrong syntax: define <name> GUEST [RESIDENTS-DEVICE-NAMES]";
  58. Log3 $name, 4, $msg;
  59. return $msg;
  60. }
  61. $hash->{TYPE} = "GUEST";
  62. my $parents = ( defined( $a[2] ) ? $a[2] : "" );
  63. # unregister at parent objects if we get modified
  64. my @registeredResidentgroups;
  65. my $modified = 0;
  66. if ( defined( $hash->{RESIDENTGROUPS} ) && $hash->{RESIDENTGROUPS} ne "" ) {
  67. $modified = 1;
  68. @registeredResidentgroups =
  69. split( /,/, $hash->{RESIDENTGROUPS} );
  70. # unregister at parent objects
  71. foreach my $parent (@registeredResidentgroups) {
  72. if ( defined( $defs{$parent} )
  73. && $defs{$parent}{TYPE} eq "RESIDENTS" )
  74. {
  75. fhem("set $parent unregister $name");
  76. Log3 $name, 4,
  77. "GUEST $name: Unregistered at RESIDENTS device $parent";
  78. }
  79. }
  80. }
  81. # register at parent objects
  82. $hash->{RESIDENTGROUPS} = "";
  83. if ( $parents ne "" ) {
  84. @registeredResidentgroups = split( /,/, $parents );
  85. foreach my $parent (@registeredResidentgroups) {
  86. if ( !defined( $defs{$parent} ) ) {
  87. Log3 $name, 3,
  88. "GUEST $name: Unable to register at RESIDENTS device $parent (not existing)";
  89. next;
  90. }
  91. if ( $defs{$parent}{TYPE} ne "RESIDENTS" ) {
  92. Log3 $name, 3,
  93. "GUEST $name: Device $parent is not a RESIDENTS device (wrong type)";
  94. next;
  95. }
  96. fhem("set $parent register $name");
  97. $hash->{RESIDENTGROUPS} .= $parent . ",";
  98. Log3 $name, 4,
  99. "GUEST $name: Registered at RESIDENTS device $parent";
  100. }
  101. }
  102. else {
  103. $modified = 0;
  104. }
  105. # set reverse pointer
  106. $modules{GUEST}{defptr}{$name} = \$hash;
  107. readingsBeginUpdate($hash);
  108. # set default settings on first define
  109. if ( $init_done && !defined( $hash->{OLDDEF} ) ) {
  110. my $aliasname = $name;
  111. $aliasname =~ s/^rg_//;
  112. $attr{$name}{alias} = $aliasname;
  113. $attr{$name}{devStateIcon} =
  114. ".*home:user_available:absent .*absent:user_away:home .*none:control_building_empty:home .*gotosleep:scene_toilet:asleep .*asleep:scene_sleeping:awoken .*awoken:scene_sleeping_alternat:home .*:user_unknown:home";
  115. $attr{$name}{group} = "Guests";
  116. $attr{$name}{icon} = "scene_visit_guests";
  117. $attr{$name}{rg_realname} = "alias";
  118. $attr{$name}{sortby} = "1";
  119. $attr{$name}{webCmd} = "state";
  120. $attr{$name}{room} = $attr{ $registeredResidentgroups[0] }{room}
  121. if ( @registeredResidentgroups
  122. && exists( $attr{ $registeredResidentgroups[0] }{room} ) );
  123. }
  124. # trigger for modified objects
  125. unless ( $modified == 0 ) {
  126. readingsBulkUpdate( $hash, "state", ReadingsVal( $name, "state", "" ) );
  127. }
  128. readingsEndUpdate( $hash, 1 );
  129. # run timers
  130. InternalTimer( gettimeofday() + 15, "GUEST_StartInternalTimers", $hash, 0 );
  131. # Injecting AttrFn for use with RESIDENTS Toolkit
  132. if ( !defined( $modules{dummy}{AttrFn} ) ) {
  133. $modules{dummy}{AttrFn} = "RESIDENTStk_AttrFnDummy";
  134. }
  135. elsif ( $modules{dummy}{AttrFn} ne "RESIDENTStk_AttrFnDummy" ) {
  136. Log3 $name, 4,
  137. "RESIDENTStk $name: concurrent AttrFn already defined for dummy module ("
  138. . $modules{dummy}{AttrFn}
  139. . "). Some attribute based functions like auto-creations will not be available.";
  140. }
  141. return undef;
  142. }
  143. ###################################
  144. sub GUEST_Undefine($$) {
  145. my ( $hash, $name ) = @_;
  146. RESIDENTStk_RemoveInternalTimer( "AutoGone", $hash );
  147. RESIDENTStk_RemoveInternalTimer( "DurationTimer", $hash );
  148. if ( defined( $hash->{RESIDENTGROUPS} ) ) {
  149. my @registeredResidentgroups =
  150. split( /,/, $hash->{RESIDENTGROUPS} );
  151. # unregister at parent objects
  152. foreach my $parent (@registeredResidentgroups) {
  153. if ( defined( $defs{$parent} )
  154. && $defs{$parent}{TYPE} eq "RESIDENTS" )
  155. {
  156. fhem("set $parent unregister $name");
  157. Log3 $name, 4,
  158. "GUEST $name: Unregistered at RESIDENTS device $parent";
  159. }
  160. }
  161. }
  162. # release reverse pointer
  163. delete $modules{GUEST}{defptr}{$name};
  164. return undef;
  165. }
  166. ###################################
  167. sub GUEST_Notify($$) {
  168. my ( $hash, $dev ) = @_;
  169. my $devName = $dev->{NAME};
  170. my $hashName = $hash->{NAME};
  171. # process global:INITIALIZED
  172. if ( $dev->{NAME} eq "global"
  173. && grep( m/^INITIALIZED$/, @{ $dev->{CHANGED} } ) )
  174. {
  175. my @registeredWakeupdevs =
  176. split( /,/, AttrVal( $hashName, "rg_wakeupDevice", 0 ) );
  177. # if we have registered wakeup devices
  178. if (@registeredWakeupdevs) {
  179. # look for at devices for each wakeup device
  180. foreach my $wakeupDev (@registeredWakeupdevs) {
  181. my $wakeupAtdevice = AttrVal( $wakeupDev, "wakeupAtdevice", 0 );
  182. # make sure computeAfterInit is set at at-device
  183. # and re-calculate on our own this time
  184. if ( defined( $defs{$wakeupAtdevice} )
  185. && $defs{$wakeupAtdevice}{TYPE} eq "at"
  186. && AttrVal( $wakeupAtdevice, "computeAfterInit", 0 ) ne
  187. "1" )
  188. {
  189. Log3 $wakeupDev, 3,
  190. "RESIDENTStk $wakeupDev: Correcting '$wakeupAtdevice' attribute computeAfterInit required for correct recalculation after reboot";
  191. fhem "attr $wakeupAtdevice computeAfterInit 1";
  192. my $command;
  193. ( $command, undef ) =
  194. split( "[ \t]+", $defs{$wakeupAtdevice}{DEF}, 2 );
  195. $command =~ s/^[*+]//;
  196. return at_Set( $defs{$wakeupAtdevice},
  197. ( $wakeupAtdevice, "modifyTimeSpec", $command ) );
  198. }
  199. }
  200. }
  201. }
  202. # process child notifies
  203. elsif ( $devName ne $hashName ) {
  204. my @registeredWakeupdevs =
  205. split( ',', AttrVal( $hashName, "rg_wakeupDevice", "" ) );
  206. my @presenceDevices =
  207. split( ',', AttrVal( $hashName, "rg_presenceDevices", "" ) );
  208. # if we have registered wakeup devices
  209. if (@registeredWakeupdevs) {
  210. # if this is a notification of a registered wakeup device
  211. if ( $devName ~~ @registeredWakeupdevs ) {
  212. # Some previous notify deleted the array.
  213. return
  214. if ( !$dev->{CHANGED} );
  215. foreach my $change ( @{ $dev->{CHANGED} } ) {
  216. RESIDENTStk_wakeupSet( $devName, $change );
  217. }
  218. return;
  219. }
  220. # process sub-child notifies: *_wakeupDevice
  221. foreach my $wakeupDev (@registeredWakeupdevs) {
  222. # if this is a notification of a registered sub dummy device
  223. # of one of our wakeup devices
  224. if (
  225. AttrVal( $wakeupDev, "wakeupResetSwitcher", "" ) eq $devName
  226. && $dev->{TYPE} eq "dummy" )
  227. {
  228. # Some previous notify deleted the array.
  229. return
  230. if ( !$dev->{CHANGED} );
  231. foreach my $change ( @{ $dev->{CHANGED} } ) {
  232. RESIDENTStk_wakeupSet( $wakeupDev, $change )
  233. if ( $change ne "off" );
  234. }
  235. last;
  236. }
  237. }
  238. }
  239. # process PRESENCE
  240. if ( @presenceDevices && $devName ~~ @presenceDevices ) {
  241. my $counter = {
  242. absent => 0,
  243. present => 0,
  244. };
  245. foreach (@presenceDevices) {
  246. my $presenceState =
  247. ReadingsVal( $_, "presence", ReadingsVal( $_, "state", "" ) );
  248. next
  249. unless ( $presenceState =~
  250. /^((absent|disappeared|unavailable)|(present|appeared|available|))$/i
  251. );
  252. $counter->{absent}++ if ($2);
  253. $counter->{present}++ if ($3);
  254. }
  255. if ( $counter->{absent} && !$counter->{present} ) {
  256. Log3 $hashName, 4,
  257. "GUEST $hashName: Syncing status with $devName = absent";
  258. fhem "set $hashName:FILTER=presence=present absent";
  259. }
  260. elsif ( $counter->{present} ) {
  261. Log3 $hashName, 4,
  262. "GUEST $hashName: Syncing status with $devName = present";
  263. fhem "set $hashName:FILTER=presence=absent home";
  264. }
  265. }
  266. }
  267. return;
  268. }
  269. ###################################
  270. sub GUEST_Set($@) {
  271. my ( $hash, @a ) = @_;
  272. my $name = $hash->{NAME};
  273. my $state = ReadingsVal( $name, "state", "initialized" );
  274. my $presence = ReadingsVal( $name, "presence", "undefined" );
  275. my $mood = ReadingsVal( $name, "mood", "-" );
  276. my $location = ReadingsVal( $name, "location", "undefined" );
  277. my $silent = 0;
  278. Log3 $name, 5, "GUEST $name: called function GUEST_Set()";
  279. return "No Argument given" if ( !defined( $a[1] ) );
  280. # depending on current FHEMWEB instance's allowedCommands,
  281. # restrict set commands if there is "set-user" in it
  282. my $adminMode = 1;
  283. my $FWallowedCommands = 0;
  284. $FWallowedCommands = AttrVal( $FW_wname, "allowedCommands", 0 )
  285. if ( defined($FW_wname) );
  286. if ( $FWallowedCommands && $FWallowedCommands =~ m/\bset-user\b/ ) {
  287. $adminMode = 0;
  288. return "Forbidden command: set " . $a[1]
  289. if ( lc( $a[1] ) eq "create" );
  290. }
  291. # states
  292. my $states = (
  293. defined( $attr{$name}{rg_states} ) ? $attr{$name}{rg_states}
  294. : (
  295. defined( $attr{$name}{rg_showAllStates} )
  296. && $attr{$name}{rg_showAllStates} == 1
  297. ? "home,gotosleep,asleep,awoken,absent,none"
  298. : "home,gotosleep,absent,none"
  299. )
  300. );
  301. $states = $state . "," . $states if ( $states !~ /$state/ );
  302. $states =~ s/ /,/g;
  303. # moods
  304. my $moods = (
  305. defined( $attr{$name}{rg_moods} )
  306. ? $attr{$name}{rg_moods} . ",toggle"
  307. : "calm,relaxed,happy,excited,lonely,sad,bored,stressed,uncomfortable,sleepy,angry,toggle"
  308. );
  309. $moods = $mood . "," . $moods if ( $moods !~ /$mood/ );
  310. $moods =~ s/ /,/g;
  311. # locations
  312. my $locations = (
  313. defined( $attr{$name}{rg_locations} )
  314. ? $attr{$name}{rg_locations}
  315. : ""
  316. );
  317. if ( $locations !~ /$location/
  318. && $locations ne "" )
  319. {
  320. $locations = ":" . $location . "," . $locations;
  321. }
  322. elsif ( $locations ne "" ) {
  323. $locations = ":" . $locations;
  324. }
  325. $locations =~ s/ /,/g;
  326. my $usage = "Unknown argument " . $a[1] . ", choose one of state:$states";
  327. $usage .= " mood:$moods";
  328. $usage .= " location$locations";
  329. if ($adminMode) {
  330. $usage .= " create:wakeuptimer";
  331. $usage .= ",locationMap"
  332. if ( ReadingsVal( $name, "locationLat", "-" ) ne "-"
  333. && ReadingsVal( $name, "locationLong", "-" ) ne "-" );
  334. }
  335. # silentSet
  336. if ( $a[1] eq "silentSet" ) {
  337. $silent = 1;
  338. my $first = shift @a;
  339. $a[0] = $first;
  340. }
  341. # states
  342. if ( $a[1] eq "state"
  343. || $a[1] eq "home"
  344. || $a[1] eq "gotosleep"
  345. || $a[1] eq "asleep"
  346. || $a[1] eq "awoken"
  347. || $a[1] eq "absent"
  348. || $a[1] eq "none"
  349. || $a[1] eq "gone" )
  350. {
  351. my $newstate;
  352. # if not direct
  353. if (
  354. $a[1] eq "state"
  355. && defined( $a[2] )
  356. && ( $a[2] eq "home"
  357. || $a[2] eq "gotosleep"
  358. || $a[2] eq "asleep"
  359. || $a[2] eq "awoken"
  360. || $a[2] eq "absent"
  361. || $a[2] eq "none"
  362. || $a[2] eq "gone" )
  363. )
  364. {
  365. $newstate = $a[2];
  366. }
  367. elsif ( defined( $a[2] ) ) {
  368. return
  369. "Invalid 2nd argument, choose one of home gotosleep asleep awoken absent none ";
  370. }
  371. else {
  372. $newstate = $a[1];
  373. }
  374. $newstate = "none" if ( $newstate eq "gone" );
  375. Log3 $name, 2, "GUEST set $name " . $newstate if ( !$silent );
  376. # if state changed
  377. if ( $state ne $newstate ) {
  378. readingsBeginUpdate($hash);
  379. readingsBulkUpdate( $hash, "lastState", $state );
  380. readingsBulkUpdate( $hash, "state", $newstate );
  381. my $datetime = TimeNow();
  382. # reset mood
  383. my $mood_default =
  384. ( defined( $attr{$name}{"rg_moodDefault"} ) )
  385. ? $attr{$name}{"rg_moodDefault"}
  386. : "calm";
  387. my $mood_sleepy =
  388. ( defined( $attr{$name}{"rg_moodSleepy"} ) )
  389. ? $attr{$name}{"rg_moodSleepy"}
  390. : "sleepy";
  391. if (
  392. $mood ne "-"
  393. && ( $newstate eq "gone"
  394. || $newstate eq "none"
  395. || $newstate eq "absent"
  396. || $newstate eq "asleep" )
  397. )
  398. {
  399. Log3 $name, 4,
  400. "GUEST $name: implicit mood change caused by state "
  401. . $newstate;
  402. GUEST_Set( $hash, $name, "silentSet", "mood", "-" );
  403. }
  404. elsif ( $mood ne $mood_sleepy
  405. && ( $newstate eq "gotosleep" || $newstate eq "awoken" ) )
  406. {
  407. Log3 $name, 4,
  408. "GUEST $name: implicit mood change caused by state "
  409. . $newstate;
  410. GUEST_Set( $hash, $name, "silentSet", "mood", $mood_sleepy );
  411. }
  412. elsif ( ( $mood eq "-" || $mood eq $mood_sleepy )
  413. && $newstate eq "home" )
  414. {
  415. Log3 $name, 4,
  416. "GUEST $name: implicit mood change caused by state "
  417. . $newstate;
  418. GUEST_Set( $hash, $name, "silentSet", "mood", $mood_default );
  419. }
  420. # if state is asleep, start sleep timer
  421. readingsBulkUpdate( $hash, "lastSleep", $datetime )
  422. if ( $newstate eq "asleep" );
  423. # if prior state was asleep, update sleep statistics
  424. if ( $state eq "asleep"
  425. && ReadingsVal( $name, "lastSleep", "" ) ne "" )
  426. {
  427. readingsBulkUpdate( $hash, "lastAwake", $datetime );
  428. readingsBulkUpdate(
  429. $hash,
  430. "lastDurSleep",
  431. RESIDENTStk_TimeDiff(
  432. $datetime, ReadingsVal( $name, "lastSleep", "" )
  433. )
  434. );
  435. readingsBulkUpdate(
  436. $hash,
  437. "lastDurSleep_cr",
  438. RESIDENTStk_TimeDiff(
  439. $datetime, ReadingsVal( $name, "lastSleep", "" ),
  440. "min"
  441. )
  442. );
  443. }
  444. # calculate presence state
  445. my $newpresence =
  446. ( $newstate ne "none"
  447. && $newstate ne "gone"
  448. && $newstate ne "absent" )
  449. ? "present"
  450. : "absent";
  451. # stop any running wakeup-timers in case state changed
  452. my $wakeupState = ReadingsVal( $name, "wakeup", 0 );
  453. if ( $wakeupState > 0 ) {
  454. my $wakeupDeviceList = AttrVal( $name, "rg_wakeupDevice", 0 );
  455. for my $wakeupDevice ( split /,/, $wakeupDeviceList ) {
  456. next if !$wakeupDevice;
  457. if ( defined( $defs{$wakeupDevice} )
  458. && $defs{$wakeupDevice}{TYPE} eq "dummy" )
  459. {
  460. # forced-stop only if resident is not present anymore
  461. if ( $newpresence eq "present" ) {
  462. Log3 $name, 4,
  463. "ROOMMATE $name: ending wakeup-timer $wakeupDevice";
  464. fhem "set $wakeupDevice:FILTER=running!=0 end";
  465. }
  466. else {
  467. Log3 $name, 4,
  468. "ROOMMATE $name: stopping wakeup-timer $wakeupDevice";
  469. fhem "set $wakeupDevice:FILTER=running!=0 stop";
  470. }
  471. }
  472. }
  473. }
  474. # if presence changed
  475. if ( $newpresence ne $presence ) {
  476. readingsBulkUpdate( $hash, "presence", $newpresence );
  477. # update location
  478. my @location_home =
  479. split( ' ', AttrVal( $name, "rg_locationHome", "home" ) );
  480. my @location_underway =
  481. split( ' ',
  482. AttrVal( $name, "rg_locationUnderway", "underway" ) );
  483. my @location_wayhome =
  484. split( ' ',
  485. AttrVal( $name, "rg_locationWayhome", "wayhome" ) );
  486. my $searchstring = quotemeta($location);
  487. if ( $newpresence eq "present" ) {
  488. if ( !grep( m/^$searchstring$/, @location_home )
  489. && $location ne $location_home[0] )
  490. {
  491. Log3 $name, 4,
  492. "GUEST $name: implicit location change caused by state "
  493. . $newstate;
  494. GUEST_Set( $hash, $name, "silentSet", "location",
  495. $location_home[0] );
  496. }
  497. }
  498. else {
  499. if ( !$silent
  500. && !grep( m/^$searchstring$/, @location_underway )
  501. && $location ne $location_underway[0] )
  502. {
  503. Log3 $name, 4,
  504. "GUEST $name: implicit location change caused by state "
  505. . $newstate;
  506. GUEST_Set( $hash, $name, "silentSet", "location",
  507. $location_underway[0] );
  508. }
  509. }
  510. # reset wayhome
  511. if ( ReadingsVal( $name, "wayhome", 1 ) > 0 ) {
  512. readingsBulkUpdate( $hash, "wayhome", "0" );
  513. }
  514. # update statistics
  515. if ( $newpresence eq "present" ) {
  516. readingsBulkUpdate( $hash, "lastArrival", $datetime );
  517. # absence duration
  518. if ( ReadingsVal( $name, "lastDeparture", "-" ) ne "-" ) {
  519. readingsBulkUpdate(
  520. $hash,
  521. "lastDurAbsence",
  522. RESIDENTStk_TimeDiff(
  523. $datetime,
  524. ReadingsVal( $name, "lastDeparture", "-" )
  525. )
  526. );
  527. readingsBulkUpdate(
  528. $hash,
  529. "lastDurAbsence_cr",
  530. RESIDENTStk_TimeDiff(
  531. $datetime,
  532. ReadingsVal( $name, "lastDeparture", "-" ),
  533. "min"
  534. )
  535. );
  536. }
  537. }
  538. else {
  539. readingsBulkUpdate( $hash, "lastDeparture", $datetime );
  540. # presence duration
  541. if ( ReadingsVal( $name, "lastArrival", "-" ) ne "-" ) {
  542. readingsBulkUpdate(
  543. $hash,
  544. "lastDurPresence",
  545. RESIDENTStk_TimeDiff(
  546. $datetime,
  547. ReadingsVal( $name, "lastArrival", "-" )
  548. )
  549. );
  550. readingsBulkUpdate(
  551. $hash,
  552. "lastDurPresence_cr",
  553. RESIDENTStk_TimeDiff(
  554. $datetime,
  555. ReadingsVal( $name, "lastArrival", "-" ), "min"
  556. )
  557. );
  558. }
  559. }
  560. # adjust linked objects
  561. if ( defined( $attr{$name}{"rg_passPresenceTo"} )
  562. && $attr{$name}{"rg_passPresenceTo"} ne "" )
  563. {
  564. my @linkedObjects =
  565. split( ' ', $attr{$name}{"rg_passPresenceTo"} );
  566. foreach my $object (@linkedObjects) {
  567. if (
  568. defined( $defs{$object} )
  569. && $defs{$object} ne $name
  570. && defined( $defs{$object}{TYPE} )
  571. && ( $defs{$object}{TYPE} eq "ROOMMATE"
  572. || $defs{$object}{TYPE} eq "GUEST" )
  573. && ReadingsVal( $object, "state", "" ) ne "gone"
  574. && ReadingsVal( $object, "state", "" ) ne "none"
  575. )
  576. {
  577. fhem("set $object $newstate");
  578. }
  579. }
  580. }
  581. }
  582. # clear readings if guest is gone
  583. if ( $newstate eq "none" ) {
  584. readingsBulkUpdate( $hash, "lastArrival", "-" )
  585. if ( ReadingsVal( $name, "lastArrival", "-" ) ne "-" );
  586. readingsBulkUpdate( $hash, "lastAwake", "-" )
  587. if ( ReadingsVal( $name, "lastAwake", "-" ) ne "-" );
  588. readingsBulkUpdate( $hash, "lastDurAbsence", "-" )
  589. if ( ReadingsVal( $name, "lastDurAbsence", "-" ) ne "-" );
  590. readingsBulkUpdate( $hash, "lastDurSleep", "-" )
  591. if ( ReadingsVal( $name, "lastDurSleep", "-" ) ne "-" );
  592. readingsBulkUpdate( $hash, "lastLocation", "-" )
  593. if ( ReadingsVal( $name, "lastLocation", "-" ) ne "-" );
  594. readingsBulkUpdate( $hash, "lastSleep", "-" )
  595. if ( ReadingsVal( $name, "lastSleep", "-" ) ne "-" );
  596. readingsBulkUpdate( $hash, "lastMood", "-" )
  597. if ( ReadingsVal( $name, "lastMood", "-" ) ne "-" );
  598. readingsBulkUpdate( $hash, "location", "-" )
  599. if ( ReadingsVal( $name, "location", "-" ) ne "-" );
  600. readingsBulkUpdate( $hash, "mood", "-" )
  601. if ( ReadingsVal( $name, "mood", "-" ) ne "-" );
  602. }
  603. # calculate duration timers
  604. GUEST_DurationTimer( $hash, $silent );
  605. readingsEndUpdate( $hash, 1 );
  606. # enable or disable AutoGone timer
  607. if ( $newstate eq "absent" ) {
  608. GUEST_AutoGone($hash);
  609. }
  610. elsif ( $state eq "absent" ) {
  611. RESIDENTStk_RemoveInternalTimer( "AutoGone", $hash );
  612. }
  613. }
  614. }
  615. # mood
  616. elsif ( $a[1] eq "mood" ) {
  617. if ( defined( $a[2] ) && $a[2] ne "" ) {
  618. Log3 $name, 2, "GUEST set $name mood " . $a[2] if ( !$silent );
  619. readingsBeginUpdate($hash) if ( !$silent );
  620. if ( $a[2] eq "toggle"
  621. && ReadingsVal( $name, "lastMood", "" ) ne "" )
  622. {
  623. readingsBulkUpdate( $hash, "mood",
  624. ReadingsVal( $name, "lastMood", "" ) );
  625. readingsBulkUpdate( $hash, "lastMood", $mood );
  626. }
  627. elsif ( $mood ne $a[2] ) {
  628. readingsBulkUpdate( $hash, "lastMood", $mood )
  629. if ( $mood ne "-" );
  630. readingsBulkUpdate( $hash, "mood", $a[2] );
  631. }
  632. readingsEndUpdate( $hash, 1 ) if ( !$silent );
  633. }
  634. else {
  635. return "Invalid 2nd argument, choose one of mood toggle";
  636. }
  637. }
  638. # location
  639. elsif ( $a[1] eq "location" ) {
  640. if ( defined( $a[2] ) && $a[2] ne "" ) {
  641. Log3 $name, 2, "GUEST set $name location " . $a[2] if ( !$silent );
  642. if ( $location ne $a[2] ) {
  643. my $searchstring;
  644. readingsBeginUpdate($hash) if ( !$silent );
  645. # read attributes
  646. my @location_home =
  647. split( ' ', AttrVal( $name, "rg_locationHome", "home" ) );
  648. my @location_underway =
  649. split( ' ',
  650. AttrVal( $name, "rg_locationUnderway", "underway" ) );
  651. my @location_wayhome =
  652. split( ' ',
  653. AttrVal( $name, "rg_locationWayhome", "wayhome" ) );
  654. $searchstring = quotemeta($location);
  655. readingsBulkUpdate( $hash, "lastLocation", $location )
  656. if ( $location ne "wayhome"
  657. && !grep( m/^$searchstring$/, @location_underway ) );
  658. readingsBulkUpdate( $hash, "location", $a[2] )
  659. if ( $a[2] ne "wayhome" );
  660. # wayhome detection
  661. $searchstring = quotemeta($location);
  662. if (
  663. (
  664. $a[2] eq "wayhome"
  665. || grep( m/^$searchstring$/, @location_wayhome )
  666. )
  667. && ( $presence eq "absent" )
  668. )
  669. {
  670. Log3 $name, 3,
  671. "GUEST $name: on way back home from $location";
  672. readingsBulkUpdate( $hash, "wayhome", "1" )
  673. if ( ReadingsVal( $name, "wayhome", "0" ) ne "1" );
  674. }
  675. readingsEndUpdate( $hash, 1 ) if ( !$silent );
  676. # auto-updates
  677. $searchstring = quotemeta( $a[2] );
  678. if (
  679. (
  680. $a[2] eq "home"
  681. || grep( m/^$searchstring$/, @location_home )
  682. )
  683. && $state ne "home"
  684. && $state ne "gotosleep"
  685. && $state ne "asleep"
  686. && $state ne "awoken"
  687. && $state ne "initialized"
  688. )
  689. {
  690. Log3 $name, 4,
  691. "GUEST $name: implicit state change caused by location "
  692. . $a[2];
  693. GUEST_Set( $hash, $name, "silentSet", "state", "home" );
  694. }
  695. elsif (
  696. (
  697. $a[2] eq "underway"
  698. || grep( m/^$searchstring$/, @location_underway )
  699. )
  700. && $state ne "gone"
  701. && $state ne "none"
  702. && $state ne "absent"
  703. && $state ne "initialized"
  704. )
  705. {
  706. Log3 $name, 4,
  707. "GUEST $name: implicit state change caused by location "
  708. . $a[2];
  709. GUEST_Set( $hash, $name, "silentSet", "state", "absent" );
  710. }
  711. }
  712. }
  713. else {
  714. return "Invalid 2nd argument, choose one of location ";
  715. }
  716. }
  717. # create
  718. elsif ( lc( $a[1] ) eq "create" ) {
  719. if ( !defined( $a[2] ) ) {
  720. return
  721. "Invalid 2nd argument, choose one of wakeuptimer locationMap ";
  722. }
  723. elsif ( lc( $a[2] ) eq "wakeuptimer" ) {
  724. my $i = "1";
  725. my $wakeuptimerName = $name . "_wakeuptimer" . $i;
  726. my $created = 0;
  727. until ($created) {
  728. if ( defined( $defs{$wakeuptimerName} ) ) {
  729. $i++;
  730. $wakeuptimerName = $name . "_wakeuptimer" . $i;
  731. }
  732. else {
  733. my $sortby = AttrVal( $name, "sortby", -1 );
  734. $sortby++;
  735. # create new dummy device
  736. fhem "define $wakeuptimerName dummy";
  737. fhem "attr $wakeuptimerName alias Wake-up Timer $i";
  738. fhem
  739. "attr $wakeuptimerName comment Auto-created by GUEST module for use with RESIDENTS Toolkit";
  740. fhem
  741. "attr $wakeuptimerName devStateIcon OFF:general_aus\@red:reset running:general_an\@green:stop .*:general_an\@orange:nextRun%20OFF";
  742. fhem "attr $wakeuptimerName group " . $attr{$name}{group}
  743. if ( defined( $attr{$name}{group} ) );
  744. fhem "attr $wakeuptimerName icon time_timer";
  745. fhem "attr $wakeuptimerName room " . $attr{$name}{room}
  746. if ( defined( $attr{$name}{room} ) );
  747. fhem
  748. "attr $wakeuptimerName setList nextRun:OFF,00:00,00:15,00:30,00:45,01:00,01:15,01:30,01:45,02:00,02:15,02:30,02:45,03:00,03:15,03:30,03:45,04:00,04:15,04:30,04:45,05:00,05:15,05:30,05:45,06:00,06:15,06:30,06:45,07:00,07:15,07:30,07:45,08:00,08:15,08:30,08:45,09:00,09:15,09:30,09:45,10:00,10:15,10:30,10:45,11:00,11:15,11:30,11:45,12:00,12:15,12:30,12:45,13:00,13:15,13:30,13:45,14:00,14:15,14:30,14:45,15:00,15:15,15:30,15:45,16:00,16:15,16:30,16:45,17:00,17:15,17:30,17:45,18:00,18:15,18:30,18:45,19:00,19:15,19:30,19:45,20:00,20:15,20:30,20:45,21:00,21:15,21:30,21:45,22:00,22:15,22:30,22:45,23:00,23:15,23:30,23:45 reset:noArg trigger:noArg start:noArg stop:noArg end:noArg";
  749. fhem "attr $wakeuptimerName userattr wakeupUserdevice";
  750. fhem "attr $wakeuptimerName sortby " . $sortby
  751. if ($sortby);
  752. fhem "attr $wakeuptimerName wakeupUserdevice $name";
  753. fhem "attr $wakeuptimerName webCmd nextRun";
  754. # register slave device
  755. my $wakeupDevice = AttrVal( $name, "rg_wakeupDevice", 0 );
  756. if ( !$wakeupDevice ) {
  757. fhem "attr $name rg_wakeupDevice $wakeuptimerName";
  758. }
  759. elsif ( $wakeupDevice !~ /(.*,?)($wakeuptimerName)(.*,?)/ )
  760. {
  761. fhem "attr $name rg_wakeupDevice "
  762. . $wakeupDevice
  763. . ",$wakeuptimerName";
  764. }
  765. # trigger first update
  766. fhem "set $wakeuptimerName nextRun OFF";
  767. $created = 1;
  768. }
  769. }
  770. return
  771. "Dummy $wakeuptimerName and other pending devices created and pre-configured.\nYou may edit Macro_$wakeuptimerName to define your wake-up actions\nand at_$wakeuptimerName for optional at-device adjustments.";
  772. }
  773. elsif ( lc( $a[2] ) eq "locationmap" ) {
  774. my $locationmapName = $name . "_map";
  775. if ( defined( $defs{$locationmapName} ) ) {
  776. return
  777. "Device $locationmapName existing already, delete it first to have it re-created.";
  778. }
  779. else {
  780. my $sortby = AttrVal( $name, "sortby", -1 );
  781. $sortby++;
  782. # create new weblink device
  783. fhem "define $locationmapName weblink htmlCode {
  784. '<ul style=\"width: 400px;; overflow: hidden;; height: 300px;;\">
  785. <iframe name=\"$locationmapName\" src=\"https://www.google.com/maps/embed/v1/place?key=AIzaSyB66DvcpbXJ5eWgIkzxpUN2s_9l3_6fegM&q='
  786. .ReadingsVal('$name','locationLat','')
  787. .','
  788. .ReadingsVal('$name','locationLong','')
  789. .'&zoom=13\" width=\"480\" height=\"480\" frameborder=\"0\" style=\"border:0;; margin-top: -165px;; margin-left: -135px;;\">
  790. </iframe>
  791. </ul>'
  792. }";
  793. fhem "attr $locationmapName alias Current Location";
  794. fhem
  795. "attr $locationmapName comment Auto-created by GUEST module";
  796. fhem "attr $locationmapName group " . $attr{$name}{group}
  797. if ( defined( $attr{$name}{group} ) );
  798. fhem "attr $locationmapName room " . $attr{$name}{room}
  799. if ( defined( $attr{$name}{room} ) );
  800. }
  801. return "Weblink device $locationmapName was created.";
  802. }
  803. }
  804. # return usage hint
  805. else {
  806. return $usage;
  807. }
  808. return undef;
  809. }
  810. ############################################################################################################
  811. #
  812. # Begin of helper functions
  813. #
  814. ############################################################################################################
  815. ###################################
  816. sub GUEST_AutoGone($;$) {
  817. my ( $mHash, @a ) = @_;
  818. my $hash = ( $mHash->{HASH} ) ? $mHash->{HASH} : $mHash;
  819. my $name = $hash->{NAME};
  820. RESIDENTStk_RemoveInternalTimer( "AutoGone", $hash );
  821. if ( ReadingsVal( $name, "state", "home" ) eq "absent" ) {
  822. my ( $date, $time, $y, $m, $d, $hour, $min, $sec, $timestamp,
  823. $timeDiff );
  824. my $timestampNow = gettimeofday();
  825. my $timeout = (
  826. defined( $attr{$name}{rg_autoGoneAfter} )
  827. ? $attr{$name}{rg_autoGoneAfter}
  828. : "16"
  829. );
  830. ( $date, $time ) = split( ' ', $hash->{READINGS}{state}{TIME} );
  831. ( $y, $m, $d ) = split( '-', $date );
  832. ( $hour, $min, $sec ) = split( ':', $time );
  833. $m -= 01;
  834. $timestamp = timelocal( $sec, $min, $hour, $d, $m, $y );
  835. $timeDiff = $timestampNow - $timestamp;
  836. if ( $timeDiff >= $timeout * 3600 ) {
  837. Log3 $name, 3,
  838. "GUEST $name: AutoGone timer changed state to 'gone'";
  839. GUEST_Set( $hash, $name, "silentSet", "state", "gone" );
  840. }
  841. else {
  842. my $runtime = $timestamp + $timeout * 3600;
  843. Log3 $name, 4, "GUEST $name: AutoGone timer scheduled: $runtime";
  844. RESIDENTStk_InternalTimer( "AutoGone", $runtime, "GUEST_AutoGone",
  845. $hash, 1 );
  846. }
  847. }
  848. return undef;
  849. }
  850. ###################################
  851. sub GUEST_DurationTimer($;$) {
  852. my ( $mHash, @a ) = @_;
  853. my $hash = ( $mHash->{HASH} ) ? $mHash->{HASH} : $mHash;
  854. my $name = $hash->{NAME};
  855. my $state = ReadingsVal( $name, "state", "initialized" );
  856. my $silent = ( defined( $a[0] ) && $a[0] eq "1" ) ? 1 : 0;
  857. my $timestampNow = gettimeofday();
  858. my $diff;
  859. my $durPresence = "0";
  860. my $durAbsence = "0";
  861. my $durSleep = "0";
  862. RESIDENTStk_RemoveInternalTimer( "DurationTimer", $hash );
  863. if ( !defined( $attr{$name}{rg_noDuration} )
  864. || $attr{$name}{rg_noDuration} == 0 )
  865. {
  866. # presence timer
  867. if ( ReadingsVal( $name, "presence", "absent" ) eq "present"
  868. && ReadingsVal( $name, "lastArrival", "-" ) ne "-" )
  869. {
  870. $durPresence =
  871. $timestampNow -
  872. time_str2num( ReadingsVal( $name, "lastArrival", "" ) );
  873. }
  874. # absence timer
  875. if ( ReadingsVal( $name, "presence", "present" ) eq "absent"
  876. && ReadingsVal( $name, "lastDeparture", "-" ) ne "-" )
  877. {
  878. $durAbsence =
  879. $timestampNow -
  880. time_str2num( ReadingsVal( $name, "lastDeparture", "" ) );
  881. }
  882. # sleep timer
  883. if ( ReadingsVal( $name, "state", "home" ) eq "asleep"
  884. && ReadingsVal( $name, "lastSleep", "-" ) ne "-" )
  885. {
  886. $durSleep =
  887. $timestampNow -
  888. time_str2num( ReadingsVal( $name, "lastSleep", "" ) );
  889. }
  890. my $durPresence_hr =
  891. ( $durPresence > 0 )
  892. ? RESIDENTStk_sec2time($durPresence)
  893. : "00:00:00";
  894. my $durPresence_cr =
  895. ( $durPresence > 60 ) ? int( $durPresence / 60 + 0.5 ) : 0;
  896. my $durAbsence_hr =
  897. ( $durAbsence > 0 ) ? RESIDENTStk_sec2time($durAbsence) : "00:00:00";
  898. my $durAbsence_cr =
  899. ( $durAbsence > 60 ) ? int( $durAbsence / 60 + 0.5 ) : 0;
  900. my $durSleep_hr =
  901. ( $durSleep > 0 ) ? RESIDENTStk_sec2time($durSleep) : "00:00:00";
  902. my $durSleep_cr = ( $durSleep > 60 ) ? int( $durSleep / 60 + 0.5 ) : 0;
  903. readingsBeginUpdate($hash) if ( !$silent );
  904. readingsBulkUpdate( $hash, "durTimerPresence_cr", $durPresence_cr )
  905. if ( ReadingsVal( $name, "durTimerPresence_cr", "" ) ne
  906. $durPresence_cr );
  907. readingsBulkUpdate( $hash, "durTimerPresence", $durPresence_hr )
  908. if (
  909. ReadingsVal( $name, "durTimerPresence", "" ) ne $durPresence_hr );
  910. readingsBulkUpdate( $hash, "durTimerAbsence_cr", $durAbsence_cr )
  911. if (
  912. ReadingsVal( $name, "durTimerAbsence_cr", "" ) ne $durAbsence_cr );
  913. readingsBulkUpdate( $hash, "durTimerAbsence", $durAbsence_hr )
  914. if ( ReadingsVal( $name, "durTimerAbsence", "" ) ne $durAbsence_hr );
  915. readingsBulkUpdate( $hash, "durTimerSleep_cr", $durSleep_cr )
  916. if ( ReadingsVal( $name, "durTimerSleep_cr", "" ) ne $durSleep_cr );
  917. readingsBulkUpdate( $hash, "durTimerSleep", $durSleep_hr )
  918. if ( ReadingsVal( $name, "durTimerSleep", "" ) ne $durSleep_hr );
  919. readingsEndUpdate( $hash, 1 ) if ( !$silent );
  920. }
  921. RESIDENTStk_InternalTimer( "DurationTimer", $timestampNow + 60,
  922. "GUEST_DurationTimer", $hash, 1 )
  923. if ( $state ne "none" );
  924. return undef;
  925. }
  926. ###################################
  927. sub GUEST_SetLocation($$$;$$$$$$) {
  928. my ( $name, $location, $trigger, $id, $time, $lat, $long, $address,
  929. $device ) = @_;
  930. my $hash = $defs{$name};
  931. my $state = ReadingsVal( $name, "state", "initialized" );
  932. my $presence = ReadingsVal( $name, "presence", "present" );
  933. my $currLocation = ReadingsVal( $name, "location", "-" );
  934. my $currWayhome = ReadingsVal( $name, "wayhome", "0" );
  935. my $currLat = ReadingsVal( $name, "locationLat", "-" );
  936. my $currLong = ReadingsVal( $name, "locationLong", "-" );
  937. my $currAddr = ReadingsVal( $name, "locationAddr", "" );
  938. $id = "-" if ( !$id || $id eq "" );
  939. $lat = "-" if ( !$lat || $lat eq "" );
  940. $long = "-" if ( !$long || $long eq "" );
  941. $address = "" if ( !$address );
  942. $time = "" if ( !$time );
  943. $device = "" if ( !$device );
  944. Log3 $name, 5,
  945. "GUEST $name: received location information: id=$id name=$location trig=$trigger date=$time lat=$lat long=$long address:$address device=$device";
  946. my $searchstring;
  947. readingsBeginUpdate($hash);
  948. # read attributes
  949. my @location_home =
  950. split( ' ', AttrVal( $name, "rg_locationHome", "home" ) );
  951. my @location_underway =
  952. split( ' ', AttrVal( $name, "rg_locationUnderway", "underway" ) );
  953. my @location_wayhome =
  954. split( ' ', AttrVal( $name, "rg_locationWayhome", "wayhome" ) );
  955. $searchstring = quotemeta($location);
  956. # update locationPresence
  957. readingsBulkUpdate( $hash, "locationPresence", "present" )
  958. if ( $trigger == 1 );
  959. readingsBulkUpdate( $hash, "locationPresence", "absent" )
  960. if ( $trigger == 0 );
  961. # check for implicit state change
  962. #
  963. my $stateChange = 0;
  964. # home
  965. if ( $location eq "home" || grep( m/^$searchstring$/, @location_home ) ) {
  966. Log3 $name, 5, "GUEST $name: received signal from home location";
  967. # home
  968. if ( $state ne "home"
  969. && $state ne "gotosleep"
  970. && $state ne "asleep"
  971. && $state ne "awoken"
  972. && $trigger eq "1" )
  973. {
  974. $stateChange = 1;
  975. }
  976. # absent
  977. elsif ($state ne "gone"
  978. && $state ne "none"
  979. && $state ne "absent"
  980. && $trigger eq "0" )
  981. {
  982. $stateChange = 2;
  983. }
  984. }
  985. # underway
  986. elsif ($location eq "underway"
  987. || $location eq "wayhome"
  988. || grep( m/^$searchstring$/, @location_underway )
  989. || grep( m/^$searchstring$/, @location_wayhome ) )
  990. {
  991. Log3 $name, 5, "GUEST $name: received signal from underway location";
  992. # absent
  993. $stateChange = 2
  994. if ( $state ne "gone"
  995. && $state ne "none"
  996. && $state ne "absent" );
  997. }
  998. # wayhome
  999. if (
  1000. $location eq "wayhome"
  1001. || ( grep( m/^$searchstring$/, @location_wayhome )
  1002. && $trigger eq "0" )
  1003. )
  1004. {
  1005. Log3 $name, 5, "GUEST $name: wayhome signal received";
  1006. # wayhome=true
  1007. if (
  1008. (
  1009. ( $location eq "wayhome" && $trigger eq "1" )
  1010. || ( $location ne "wayhome" && $trigger eq "0" )
  1011. )
  1012. && ReadingsVal( $name, "wayhome", "0" ) ne "1"
  1013. )
  1014. {
  1015. Log3 $name, 3, "GUEST $name: on way back home from $location";
  1016. readingsBulkUpdate( $hash, "wayhome", "1" );
  1017. }
  1018. # wayhome=false
  1019. elsif ($location eq "wayhome"
  1020. && $trigger eq "0"
  1021. && ReadingsVal( $name, "wayhome", "0" ) ne "0" )
  1022. {
  1023. Log3 $name, 3,
  1024. "GUEST $name: seems not to be on way back home anymore";
  1025. readingsBulkUpdate( $hash, "wayhome", "0" );
  1026. }
  1027. }
  1028. # activate wayhome tracing when reaching another location while wayhome=1
  1029. elsif ( $stateChange == 0 && $trigger == 1 && $currWayhome == 1 ) {
  1030. Log3 $name, 3,
  1031. "GUEST $name: seems to stay at $location before coming home";
  1032. readingsBulkUpdate( $hash, "wayhome", "2" );
  1033. }
  1034. # revert wayhome during active wayhome tracing
  1035. elsif ( $stateChange == 0 && $trigger == 0 && $currWayhome == 2 ) {
  1036. Log3 $name, 3, "GUEST $name: finally on way back home from $location";
  1037. readingsBulkUpdate( $hash, "wayhome", "1" );
  1038. }
  1039. my $currLongDiff = 0;
  1040. my $currLatDiff = 0;
  1041. $currLongDiff =
  1042. maxNum( ReadingsVal( $name, "lastLocationLong", 0 ), $currLong ) -
  1043. minNum( ReadingsVal( $name, "lastLocationLong", 0 ), $currLong )
  1044. if ( $currLong ne "-" );
  1045. $currLatDiff =
  1046. maxNum( ReadingsVal( $name, "lastLocationLat", 0 ), $currLat ) -
  1047. minNum( ReadingsVal( $name, "lastLocationLat", 0 ), $currLat )
  1048. if ( $currLat ne "-" );
  1049. if (
  1050. $trigger == 1
  1051. && ( $stateChange > 0
  1052. || ReadingsVal( $name, "lastLocation", "-" ) ne $currLocation
  1053. || $currLongDiff > 0.00002
  1054. || $currLatDiff > 0.00002 )
  1055. )
  1056. {
  1057. Log3 $name, 5, "GUEST $name: archiving last known location";
  1058. readingsBulkUpdate( $hash, "lastLocationLat", $currLat );
  1059. readingsBulkUpdate( $hash, "lastLocationLong", $currLong );
  1060. readingsBulkUpdate( $hash, "lastLocationAddr", $currAddr )
  1061. if ( $currAddr ne "" );
  1062. readingsBulkUpdate( $hash, "lastLocation", $currLocation );
  1063. }
  1064. readingsBulkUpdate( $hash, "locationLat", $lat );
  1065. readingsBulkUpdate( $hash, "locationLong", $long );
  1066. if ( $address ne "" ) {
  1067. readingsBulkUpdate( $hash, "locationAddr", $address );
  1068. }
  1069. elsif ( $currAddr ne "" ) {
  1070. readingsBulkUpdate( $hash, "locationAddr", "-" );
  1071. }
  1072. readingsBulkUpdate( $hash, "location", $location );
  1073. readingsEndUpdate( $hash, 1 );
  1074. # trigger state change
  1075. if ( $stateChange > 0 ) {
  1076. Log3 $name, 4,
  1077. "GUEST $name: implicit state change caused by location " . $location;
  1078. GUEST_Set( $hash, $name, "silentSet", "state", "home" )
  1079. if $stateChange == 1;
  1080. GUEST_Set( $hash, $name, "silentSet", "state", "absent" )
  1081. if $stateChange == 2;
  1082. }
  1083. }
  1084. ###################################
  1085. sub GUEST_StartInternalTimers($$) {
  1086. my ($hash) = @_;
  1087. GUEST_AutoGone($hash);
  1088. GUEST_DurationTimer($hash);
  1089. }
  1090. 1;
  1091. =pod
  1092. =item helper
  1093. =item summary special virtual device to represent a guest of your home
  1094. =item summary_DE spezielles virtuelles Device, welches einen Gast zu Hause repr&auml;sentiert
  1095. =begin html
  1096. <a name="GUEST" id="GUEST"></a>
  1097. <h3>GUEST</h3>
  1098. <ul>
  1099. <a name="GUESTdefine" id="GUESTdefine"></a> <b>Define</b>
  1100. <ul>
  1101. <code>define &lt;rg_GuestName&gt; GUEST [&lt;device name(s) of resident group(s)&gt;]</code><br>
  1102. <br>
  1103. Provides a special virtual device to represent a guest of your home.<br>
  1104. Based on the current state and other readings, you may trigger other actions within FHEM.<br>
  1105. <br>
  1106. Used by superior module <a href="#RESIDENTS">RESIDENTS</a> but may also be used stand-alone.<br>
  1107. <br />
  1108. Use comma separated list of resident device names for multi-membership (see example below).<br />
  1109. <br>
  1110. Example:<br>
  1111. <ul>
  1112. <code># Standalone<br>
  1113. define rg_Guest GUEST<br>
  1114. <br>
  1115. # Typical group member<br>
  1116. define rg_Guest GUEST rgr_Residents # to be member of resident group rgr_Residents<br>
  1117. <br>
  1118. # Member of multiple groups<br>
  1119. define rg_Guest GUEST rgr_Residents,rgr_Guests # to be member of resident group rgr_Residents and rgr_Guests</code>
  1120. </ul>
  1121. </ul><br>
  1122. <ul>
  1123. Please note the RESIDENTS group device needs to be existing before a GUEST device can become a member of it.
  1124. </ul><br>
  1125. <br>
  1126. <br>
  1127. <a name="GUESTset" id="GUESTset"></a> <b>Set</b>
  1128. <ul>
  1129. <code>set &lt;rg_GuestName&gt; &lt;command&gt; [&lt;parameter&gt;]</code><br>
  1130. <br>
  1131. Currently, the following commands are defined.<br>
  1132. <ul>
  1133. <li>
  1134. <b>location</b> &nbsp;&nbsp;-&nbsp;&nbsp; sets reading 'location'; see attribute rg_locations to adjust list shown in FHEMWEB
  1135. </li>
  1136. <li>
  1137. <b>mood</b> &nbsp;&nbsp;-&nbsp;&nbsp; sets reading 'mood'; see attribute rg_moods to adjust list shown in FHEMWEB
  1138. </li>
  1139. <li>
  1140. <b>state</b> &nbsp;&nbsp;home,gotosleep,asleep,awoken,absent,none&nbsp;&nbsp; switch between states; see attribute rg_states to adjust list shown in FHEMWEB
  1141. </li>
  1142. <li>
  1143. <b>create</b>
  1144. <li><i>locationMap</i>&nbsp;&nbsp; add a pre-configured weblink device using showing a Google Map if readings locationLat+locationLong are present.</li>
  1145. <li><i>wakeuptimer</i>&nbsp;&nbsp; add several pre-configurations provided by RESIDENTS Toolkit. See separate section in <a href="#RESIDENTS">RESIDENTS module commandref</a> for details.</li>
  1146. </li>
  1147. </ul>
  1148. <ul>
  1149. <u>Note:</u> If you would like to restrict access to admin set-commands (-> create) you may set your FHEMWEB instance's attribute allowedCommands like 'set,set-user'.
  1150. The string 'set-user' will ensure only non-admin set-commands can be executed when accessing FHEM using this FHEMWEB instance.
  1151. </ul>
  1152. </ul><br>
  1153. <br>
  1154. <ul>
  1155. <u>Possible states and their meaning</u><br>
  1156. <br>
  1157. <ul>
  1158. This module differs between 6 states:<br>
  1159. <br>
  1160. <ul>
  1161. <li>
  1162. <b>home</b> - individual is present at home and awake
  1163. </li>
  1164. <li>
  1165. <b>gotosleep</b> - individual is on it's way to bed
  1166. </li>
  1167. <li>
  1168. <b>asleep</b> - individual is currently sleeping
  1169. </li>
  1170. <li>
  1171. <b>awoken</b> - individual just woke up from sleep
  1172. </li>
  1173. <li>
  1174. <b>absent</b> - individual is not present at home but will be back shortly
  1175. </li>
  1176. <li>
  1177. <b>none</b> - guest device is disabled
  1178. </li>
  1179. </ul>
  1180. </ul>
  1181. </ul><br>
  1182. <br>
  1183. <ul>
  1184. <u>Presence correlation to location</u><br>
  1185. <br>
  1186. <ul>
  1187. Under specific circumstances, changing state will automatically change reading 'location' as well.<br>
  1188. <br>
  1189. Whenever presence state changes from 'absent' to 'present', the location is set to 'home'. If attribute rg_locationHome was defined, first location from it will be used as home location.<br>
  1190. <br>
  1191. Whenever presence state changes from 'present' to 'absent', the location is set to 'underway'. If attribute rg_locationUnderway was defined, first location from it will be used as underway location.
  1192. </ul>
  1193. </ul><br>
  1194. <br>
  1195. <ul>
  1196. <u>Auto Gone</u><br>
  1197. <br>
  1198. <ul>
  1199. Whenever an individual is set to 'absent', a trigger is started to automatically change state to 'gone' after a specific timeframe.<br>
  1200. Default value is 16 hours.<br>
  1201. <br>
  1202. This behaviour can be customized by attribute rg_autoGoneAfter.
  1203. </ul>
  1204. </ul><br>
  1205. <br>
  1206. <ul>
  1207. <u>Synchronizing presence with other ROOMMATE or GUEST devices</u><br>
  1208. <br>
  1209. <ul>
  1210. If you always leave or arrive at your house together with other roommates or guests, you may enable a synchronization of your presence state for certain individuals.<br>
  1211. By setting attribute rg_passPresenceTo, those individuals will follow your presence state changes to 'home', 'absent' or 'gone' as you do them with your own device.<br>
  1212. <br>
  1213. Please note that individuals with current state 'none' or 'gone' (in case of roommates) will not be touched.
  1214. </ul>
  1215. </ul><br>
  1216. <br>
  1217. <ul>
  1218. <u>Location correlation to state</u><br>
  1219. <br>
  1220. <ul>
  1221. Under specific circumstances, changing location will have an effect on the actual state as well.<br>
  1222. <br>
  1223. Whenever location is set to 'home', the state is set to 'home' if prior presence state was 'absent'. If attribute rg_locationHome was defined, all of those locations will trigger state change to 'home' as well.<br>
  1224. <br>
  1225. Whenever location is set to 'underway', the state is set to 'absent' if prior presence state was 'present'. If attribute rg_locationUnderway was defined, all of those locations will trigger state change to 'absent' as well. Those locations won't appear in reading 'lastLocation'.<br>
  1226. <br>
  1227. Whenever location is set to 'wayhome', the reading 'wayhome' is set to '1' if current presence state is 'absent'. If attribute rg_locationWayhome was defined, LEAVING one of those locations will set reading 'wayhome' to '1' as well. So you actually have implicit and explicit options to trigger wayhome.<br>
  1228. Arriving at home will reset the value of 'wayhome' to '0'.<br>
  1229. <br>
  1230. If you are using the <a href="#GEOFANCY">GEOFANCY</a> module, you can easily have your location updated with GEOFANCY events by defining a simple NOTIFY-trigger like this:<br>
  1231. <br>
  1232. <code>define n_rg_Guest.location notify geofancy:currLoc_Guest.* set rg_Guest:FILTER=location!=$EVTPART1 location $EVTPART1</code><br>
  1233. <br>
  1234. By defining geofencing zones called 'home' and 'wayhome' in the iOS app, you automatically get all the features of automatic state changes described above.
  1235. </ul>
  1236. </ul><br>
  1237. <br>
  1238. <a name="GUESTattr" id="GUESTattr"></a> <b>Attributes</b><br>
  1239. <ul>
  1240. <ul>
  1241. <li>
  1242. <b>rg_autoGoneAfter</b> - hours after which state should be auto-set to 'gone' when current state is 'absent'; defaults to 16 hours
  1243. </li>
  1244. <li>
  1245. <b>rg_geofenceUUIDs</b> - comma separated list of device UUIDs updating their location via <a href="#GEOFANCY">GEOFANCY</a>. Avoids necessity for additional notify/DOIF/watchdog devices and can make GEOFANCY attribute <i>devAlias</i> obsolete. (using more than one UUID/device might not be a good idea as location my leap)
  1246. </li>
  1247. <li>
  1248. <b>rg_locationHome</b> - locations matching these will be treated as being at home; first entry reflects default value to be used with state correlation; separate entries by space; defaults to 'home'
  1249. </li>
  1250. <li>
  1251. <b>rg_locationUnderway</b> - locations matching these will be treated as being underway; first entry reflects default value to be used with state correlation; separate entries by comma or space; defaults to "underway"
  1252. </li>
  1253. <li>
  1254. <b>rg_locationWayhome</b> - leaving a location matching these will set reading wayhome to 1; separate entries by space; defaults to "wayhome"
  1255. </li>
  1256. <li>
  1257. <b>rg_locations</b> - list of locations to be shown in FHEMWEB; separate entries by comma only and do NOT use spaces
  1258. </li>
  1259. <li>
  1260. <b>rg_moodDefault</b> - the mood that should be set after arriving at home or changing state from awoken to home
  1261. </li>
  1262. <li>
  1263. <b>rg_moodSleepy</b> - the mood that should be set if state was changed to gotosleep or awoken
  1264. </li>
  1265. <li>
  1266. <b>rg_moods</b> - list of moods to be shown in FHEMWEB; separate entries by comma only and do NOT use spaces
  1267. </li>
  1268. <li>
  1269. <b>rg_noDuration</b> - may be used to disable duration timer calculation (see readings durTimer*)
  1270. </li>
  1271. <li>
  1272. <b>rg_passPresenceTo</b> - synchronize presence state with other GUEST or GUEST devices; separte devices by space
  1273. </li>
  1274. <li>
  1275. <b>rg_presenceDevices</b> - take over presence state from any other FHEM device. Separate more than one device with comma meaning ALL of them need to be either present or absent to trigger update of this ROOMMATE device.
  1276. </li>
  1277. <li>
  1278. <b>rg_realname</b> - whenever GUEST wants to use the realname it uses the value of attribute alias or group; defaults to group
  1279. </li>
  1280. <li>
  1281. <b>rg_showAllStates</b> - states 'asleep' and 'awoken' are hidden by default to allow simple gotosleep process via devStateIcon; defaults to 0
  1282. </li>
  1283. <li>
  1284. <b>rg_states</b> - list of states to be shown in FHEMWEB; separate entries by comma only and do NOT use spaces; unsupported states will lead to errors though
  1285. </li>
  1286. <li>
  1287. <b>rg_wakeupDevice</b> - reference to enslaved DUMMY devices used as a wake-up timer (part of RESIDENTS Toolkit's wakeuptimer)
  1288. </li>
  1289. </ul>
  1290. </ul><br>
  1291. <br>
  1292. <br>
  1293. <b>Generated Readings/Events:</b><br>
  1294. <ul>
  1295. <ul>
  1296. <li>
  1297. <b>durTimerAbsence</b> - timer to show the duration of absence from home in human readable format (hours:minutes:seconds)
  1298. </li>
  1299. <li>
  1300. <b>durTimerAbsence_cr</b> - timer to show the duration of absence from home in computer readable format (minutes)
  1301. </li>
  1302. <li>
  1303. <b>durTimerPresence</b> - timer to show the duration of presence at home in human readable format (hours:minutes:seconds)
  1304. </li>
  1305. <li>
  1306. <b>durTimerPresence_cr</b> - timer to show the duration of presence at home in computer readable format (minutes)
  1307. </li>
  1308. <li>
  1309. <b>durTimerSleep</b> - timer to show the duration of sleep in human readable format (hours:minutes:seconds)
  1310. </li>
  1311. <li>
  1312. <b>durTimerSleep_cr</b> - timer to show the duration of sleep in computer readable format (minutes)
  1313. </li>
  1314. <li>
  1315. <b>lastArrival</b> - timestamp of last arrival at home
  1316. </li>
  1317. <li>
  1318. <b>lastAwake</b> - timestamp of last sleep cycle end
  1319. </li>
  1320. <li>
  1321. <b>lastDeparture</b> - timestamp of last departure from home
  1322. </li>
  1323. <li>
  1324. <b>lastDurAbsence</b> - duration of last absence from home in human readable format (hours:minutes:seconds)
  1325. </li>
  1326. <li>
  1327. <b>lastDurAbsence_cr</b> - duration of last absence from home in computer readable format (minutes)
  1328. </li>
  1329. <li>
  1330. <b>lastDurPresence</b> - duration of last presence at home in human readable format (hours:minutes:seconds)
  1331. </li>
  1332. <li>
  1333. <b>lastDurPresence_cr</b> - duration of last presence at home in computer readable format (minutes)
  1334. </li>
  1335. <li>
  1336. <b>lastDurSleep</b> - duration of last sleep in human readable format (hours:minutes:seconds)
  1337. </li>
  1338. <li>
  1339. <b>lastDurSleep_cr</b> - duration of last sleep in computer readable format (minutes)
  1340. </li>
  1341. <li>
  1342. <b>lastLocation</b> - the prior location
  1343. </li>
  1344. <li>
  1345. <b>lastMood</b> - the prior mood
  1346. </li>
  1347. <li>
  1348. <b>lastSleep</b> - timestamp of last sleep cycle begin
  1349. </li>
  1350. <li>
  1351. <b>lastState</b> - the prior state
  1352. </li>
  1353. <li>
  1354. <b>lastWakeup</b> - time of last wake-up timer run
  1355. </li>
  1356. <li>
  1357. <b>lastWakeupDev</b> - device name of last wake-up timer
  1358. </li>
  1359. <li>
  1360. <b>location</b> - the current location
  1361. </li>
  1362. <li>
  1363. <b>mood</b> - the current mood
  1364. </li>
  1365. <li>
  1366. <b>nextWakeup</b> - time of next wake-up program run
  1367. </li>
  1368. <li>
  1369. <b>nextWakeupDev</b> - device name for next wake-up program run
  1370. </li>
  1371. <li>
  1372. <b>presence</b> - reflects the home presence state, depending on value of reading 'state' (can be 'present' or 'absent')
  1373. </li>
  1374. <li>
  1375. <b>state</b> - reflects the current state
  1376. </li>
  1377. <li>
  1378. <b>wakeup</b> - becomes '1' while a wake-up program of this resident is being executed
  1379. </li>
  1380. <li>
  1381. <b>wayhome</b> - depending on current location, it can become '1' if individual is on his/her way back home
  1382. </li>
  1383. <li>
  1384. <br>
  1385. <br>
  1386. The following readings will be set to '-' if state was changed to 'none':<br>
  1387. lastArrival, lastDurAbsence, lastLocation, lastMood, location, mood
  1388. </li>
  1389. </ul>
  1390. </ul>
  1391. </ul>
  1392. =end html
  1393. =begin html_DE
  1394. <a name="GUEST" id="GUEST"></a>
  1395. <h3>GUEST</h3>
  1396. <ul>
  1397. <a name="GUESTdefine" id="GUESTdefine"></a> <b>Define</b>
  1398. <ul>
  1399. <code>define &lt;rg_FirstName&gt; GUEST [&lt;Device Name(n) der Bewohnergruppe(n)&gt;]</code><br>
  1400. <br>
  1401. Stellt ein spezielles virtuelles Device bereit, welches einen Gast zu Hause repr&auml;sentiert.<br>
  1402. Basierend auf dem aktuellen Status und anderen Readings k&ouml;nnen andere Aktionen innerhalb von FHEM angestoßen werden.<br>
  1403. <br>
  1404. Wird vom &uuml;bergeordneten Modul <a href="#RESIDENTS">RESIDENTS</a> verwendet, kann aber auch einzeln benutzt werden.<br>
  1405. <br />
  1406. Bei Mitgliedschaft mehrerer Bewohnergruppen werden diese durch Komma getrennt angegeben (siehe Beispiel unten).<br />
  1407. <br>
  1408. Beispiele:<br>
  1409. <ul>
  1410. <code># Einzeln<br>
  1411. define rg_Guest GUEST<br>
  1412. <br>
  1413. # Typisches Gruppenmitglied<br>
  1414. define rg_Guest GUEST rgr_Residents # um Mitglied der Gruppe rgr_Residents zu sein<br>
  1415. <br>
  1416. # Mitglied in mehreren Gruppen<br>
  1417. define rg_Guest GUEST rgr_Residents,rgr_Guests # um Mitglied der Gruppen rgr_Residents und rgr_Guests zu sein</code>
  1418. </ul>
  1419. </ul><br>
  1420. <ul>
  1421. Bitte beachten, dass das RESIDENTS Gruppen Device zun&auml;chst angelegt werden muss, bevor ein GUEST Objekt dort Mitglied werden kann.
  1422. </ul><br>
  1423. <br>
  1424. <br>
  1425. <a name="GUESTset" id="GUESTset"></a> <b>Set</b>
  1426. <ul>
  1427. <code>set &lt;rg_FirstName&gt; &lt;command&gt; [&lt;parameter&gt;]</code><br>
  1428. <br>
  1429. Momentan sind die folgenden Kommandos definiert.<br>
  1430. <ul>
  1431. <li>
  1432. <b>location</b> &nbsp;&nbsp;-&nbsp;&nbsp; setzt das Reading 'location'; siehe auch Attribut rg_locations, um die in FHEMWEB angezeigte Liste anzupassen
  1433. </li>
  1434. <li>
  1435. <b>mood</b> &nbsp;&nbsp;-&nbsp;&nbsp; setzt das Reading 'mood'; siehe auch Attribut rg_moods, um die in FHEMWEB angezeigte Liste anzupassen
  1436. </li>
  1437. <li>
  1438. <b>state</b> &nbsp;&nbsp;home,gotosleep,asleep,awoken,absent,gone&nbsp;&nbsp; wechselt den Status; siehe auch Attribut rg_states, um die in FHEMWEB angezeigte Liste anzupassen
  1439. </li>
  1440. <li>
  1441. <b>create</b>
  1442. <li><i>locationMap</i>&nbsp;&nbsp; f&uuml;gt ein vorkonfiguriertes weblink Device hinzu, welches eine Google Map anzeigt, sofern die Readings locationLat+locationLong vorhanden sind.</li>
  1443. <li><i>wakeuptimer</i>&nbsp;&nbsp; f&uuml;gt diverse Vorkonfigurationen auf Basis von RESIDENTS Toolkit hinzu. Siehe separate Sektion in der <a href="#RESIDENTS">RESIDENTS Modul Kommandoreferenz</a>.</li>
  1444. </li>
  1445. </ul>
  1446. <ul>
  1447. <u>Hinweis:</u> Sofern der Zugriff auf administrative set-Kommandos (-> create) eingeschr&auml;nkt werden soll, kann in einer FHEMWEB Instanz das Attribut allowedCommands &auml;hnlich wie 'set,set-user' erweitert werden.
  1448. Die Zeichenfolge 'set-user' stellt dabei sicher, dass beim Zugriff auf FHEM &uuml;ber diese FHEMWEB Instanz nur nicht-administrative set-Kommandos ausgef&uuml;hrt werden k&ouml;nnen.
  1449. </ul>
  1450. </ul><br>
  1451. <br>
  1452. <ul>
  1453. <u>M&ouml;gliche Status und ihre Bedeutung</u><br>
  1454. <br>
  1455. <ul>
  1456. Dieses Modul unterscheidet 6 verschiedene Status:<br>
  1457. <br>
  1458. <ul>
  1459. <li>
  1460. <b>home</b> - Mitbewohner ist zu Hause und wach
  1461. </li>
  1462. <li>
  1463. <b>gotosleep</b> - Mitbewohner ist auf dem Weg ins Bett
  1464. </li>
  1465. <li>
  1466. <b>asleep</b> - Mitbewohner schl&auml;ft
  1467. </li>
  1468. <li>
  1469. <b>awoken</b> - Mitbewohner ist gerade aufgewacht
  1470. </li>
  1471. <li>
  1472. <b>absent</b> - Mitbewohner ist momentan nicht zu Hause, wird aber bald zur&uuml;ck sein
  1473. </li>
  1474. <li>
  1475. <b>none</b> - Gast Device ist deaktiviert
  1476. </li>
  1477. </ul>
  1478. </ul>
  1479. </ul><br>
  1480. <br>
  1481. <ul>
  1482. <u>Zusammenhang zwischen Anwesenheit/Presence und Aufenthaltsort/Location</u><br>
  1483. <br>
  1484. <ul>
  1485. Unter bestimmten Umst&auml;nden f&uuml;hrt der Wechsel des Status auch zu einer Änderung des Readings 'location'.<br>
  1486. <br>
  1487. Wannimmer die Anwesenheit (bzw. das Reading 'presence') von 'absent' auf 'present' wechselt, wird 'location' auf 'home' gesetzt. Sofern das Attribut rg_locationHome gesetzt ist, wird die erste Lokation daraus anstelle von 'home' verwendet.<br>
  1488. <br>
  1489. Wannimmer die Anwesenheit (bzw. das Reading 'presence') von 'present' auf 'absent' wechselt, wird 'location' auf 'underway' gesetzt. Sofern das Attribut rg_locationUnderway gesetzt ist, wird die erste Lokation daraus anstelle von 'underway' verwendet.
  1490. </ul>
  1491. </ul><br>
  1492. <br>
  1493. <ul>
  1494. <u>Auto-Status 'gone'</u><br>
  1495. <br>
  1496. <ul>
  1497. Immer wenn ein Mitbewohner auf 'absent' gesetzt wird, wird ein Z&auml;hler gestartet, der nach einer bestimmten Zeit den Status automatisch auf 'gone' setzt.<br>
  1498. Der Standard ist nach 16 Stunden.<br>
  1499. <br>
  1500. Dieses Verhalten kann &uuml;ber das Attribut rg_autoGoneAfter angepasst werden.
  1501. </ul>
  1502. </ul><br>
  1503. <br>
  1504. <ul>
  1505. <u>Anwesenheit mit anderen GUEST oder ROOMMATE Devices synchronisieren</u><br>
  1506. <br>
  1507. <ul>
  1508. Wenn Sie immer zusammen mit anderen Mitbewohnern oder G&auml;sten das Haus verlassen oder erreichen, k&ouml;nnen Sie ihren Status ganz einfach auf andere Mitbewohner &uuml;bertragen.<br>
  1509. Durch das Setzen des Attributs rg_PassPresenceTo folgen die dort aufgef&uuml;hrten Mitbewohner ihren eigenen Status&auml;nderungen nach 'home', 'absent' oder 'gone'.<br>
  1510. <br>
  1511. Bitte beachten, dass Mitbewohner mit dem aktuellen Status 'none' oder 'gone' (im Falle von ROOMMATE Devices) nicht beachtet werden.
  1512. </ul>
  1513. </ul><br>
  1514. <br>
  1515. <ul>
  1516. <u>Zusammenhang zwischen Aufenthaltsort/Location und Anwesenheit/Presence</u><br>
  1517. <br>
  1518. <ul>
  1519. Unter bestimmten Umst&auml;nden hat der Wechsel des Readings 'location' auch einen Einfluss auf den tats&auml;chlichen Status.<br>
  1520. <br>
  1521. Immer wenn eine Lokation mit dem Namen 'home' gesetzt wird, wird auch der Status auf 'home' gesetzt, sofern die Anwesenheit bis dahin noch auf 'absent' stand. Sofern das Attribut rg_locationHome gesetzt wurde, so l&ouml;sen alle dort angegebenen Lokationen einen Statuswechsel nach 'home' aus.<br>
  1522. <br>
  1523. Immer wenn eine Lokation mit dem Namen 'underway' gesetzt wird, wird auch der Status auf 'absent' gesetzt, sofern die Anwesenheit bis dahin noch auf 'present' stand. Sofern das Attribut rg_locationUnderway gesetzt wurde, so l&ouml;sen alle dort angegebenen Lokationen einen Statuswechsel nach 'underway' aus. Diese Lokationen werden auch nicht in das Reading 'lastLocation' &uuml;bertragen.<br>
  1524. <br>
  1525. Immer wenn eine Lokation mit dem Namen 'wayhome' gesetzt wird, wird das Reading 'wayhome' auf '1' gesetzt, sofern die Anwesenheit zu diesem Zeitpunkt 'absent' ist. Sofern das Attribut rg_locationWayhome gesetzt wurde, so f&uuml;hrt das VERLASSEN einer dort aufgef&uuml;hrten Lokation ebenfalls dazu, dass das Reading 'wayhome' auf '1' gesetzt wird. Es gibt also 2 M&ouml;glichkeiten den Nach-Hause-Weg-Indikator zu beeinflussen (implizit und explizit).<br>
  1526. Die Ankunft zu Hause setzt den Wert von 'wayhome' zur&uuml;ck auf '0'.<br>
  1527. <br>
  1528. Wenn Sie auch das <a href="#GEOFANCY">GEOFANCY</a> Modul verwenden, k&ouml;nnen Sie das Reading 'location' ganz einfach &uuml;ber GEOFANCY Ereignisse aktualisieren lassen. Definieren Sie dazu einen NOTIFY-Trigger wie diesen:<br>
  1529. <br>
  1530. <code>define n_rg_Manfred.location notify geofancy:currLoc_Manfred.* set rg_Manfred:FILTER=location!=$EVTPART1 location $EVTPART1</code><br>
  1531. <br>
  1532. Durch das Anlegen von Geofencing-Zonen mit den Namen 'home' und 'wayhome' in der iOS App werden zuk&uuml;nftig automatisch alle Status&auml;nderungen wie oben beschrieben durchgef&uuml;hrt.
  1533. </ul>
  1534. </ul><br>
  1535. <br>
  1536. <a name="GUESTattr" id="GUESTattr"></a> <b>Attribute</b><br>
  1537. <ul>
  1538. <ul>
  1539. <li>
  1540. <b>rg_autoGoneAfter</b> - Anzahl der Stunden, nach denen sich der Status automatisch auf 'gone' &auml;ndert, wenn der aktuellen Status 'absent' ist; Standard ist 36 Stunden
  1541. </li>
  1542. <li>
  1543. <b>rg_geofenceUUIDs</b> - Mit Komma getrennte Liste von Ger&auml;te UUIDs, die ihren Standort &uuml;ber <a href="#GEOFANCY">GEOFANCY</a> aktualisieren. Vermeidet zus&auml;tzliche notify/DOIF/watchdog Ger&auml;te und kann als Ersatz f&uuml;r das GEOFANCY attribute <i>devAlias</i> dienen. (hier ehr als eine UUID/Device zu hinterlegen ist eher keine gute Idee da die Lokation dann wom&ouml;glich anf&auml;ngt zu springen)
  1544. </li>
  1545. <li>
  1546. <b>rg_locationHome</b> - hiermit &uuml;bereinstimmende Lokationen werden als zu Hause gewertet; der erste Eintrag wird f&uuml;r das Zusammenspiel bei Status&auml;nderungen benutzt; mehrere Eintr&auml;ge durch Leerzeichen trennen; Standard ist 'home'
  1547. </li>
  1548. <li>
  1549. <b>rg_locationUnderway</b> - hiermit &uuml;bereinstimmende Lokationen werden als unterwegs gewertet; der erste Eintrag wird f&uuml;r das Zusammenspiel bei Status&auml;nderungen benutzt; mehrere Eintr&auml;ge durch Leerzeichen trennen; Standard ist 'underway'
  1550. </li>
  1551. <li>
  1552. <b>rg_locationWayhome</b> - das Verlassen einer Lokation, die hier aufgef&uuml;hrt ist, l&auml;sst das Reading 'wayhome' auf '1' setzen; mehrere Eintr&auml;ge durch Leerzeichen trennen; Standard ist "wayhome"
  1553. </li>
  1554. <li>
  1555. <b>rg_locations</b> - Liste der in FHEMWEB anzuzeigenden Lokationsauswahlliste in FHEMWEB; mehrere Eintr&auml;ge nur durch Komma trennen und KEINE Leerzeichen verwenden
  1556. </li>
  1557. <li>
  1558. <b>rg_moodDefault</b> - die Stimmung, die nach Ankunft zu Hause oder nach dem Statuswechsel von 'awoken' auf 'home' gesetzt werden soll
  1559. </li>
  1560. <li>
  1561. <b>rg_moodSleepy</b> - die Stimmung, die nach Statuswechsel zu 'gotosleep' oder 'awoken' gesetzt werden soll
  1562. </li>
  1563. <li>
  1564. <b>rg_moods</b> - Liste von Stimmungen, wie sie in FHEMWEB angezeigt werden sollen; mehrere Eintr&auml;ge nur durch Komma trennen und KEINE Leerzeichen verwenden
  1565. </li>
  1566. <li>
  1567. <b>rg_noDuration</b> - deaktiviert die Berechnung der Zeitspannen (siehe Readings durTimer*)
  1568. </li>
  1569. <li>
  1570. <b>rg_passPresenceTo</b> - synchronisiere die Anwesenheit mit anderen GUEST oder ROOMMATE Devices; mehrere Devices durch Leerzeichen trennen
  1571. </li>
  1572. <li>
  1573. <b>rg_presenceDevices</b> - &uuml;bernehmen des presence Status von einem anderen FHEM Device. Bei mehreren Devices diese mit Komma trennen, um ein Update des GUEST Devices auszul&ouml;sen, sobald ALLE Devices entweder absent oder present sind.
  1574. </li>
  1575. <li>
  1576. <b>rg_realname</b> - wo immer GUEST den richtigen Namen verwenden m&ouml;chte nutzt es den Wert des Attributs alias oder group; Standard ist group
  1577. </li>
  1578. <li>
  1579. <b>rg_showAllStates</b> - die Status 'asleep' und 'awoken' sind normalerweise nicht immer sichtbar, um einen einfachen Zubettgeh-Prozess &uuml;ber das devStateIcon Attribut zu erm&ouml;glichen; Standard ist 0
  1580. </li>
  1581. <li>
  1582. <b>rg_states</b> - Liste aller in FHEMWEB angezeigter Status; Eintrage nur mit Komma trennen und KEINE Leerzeichen benutzen; nicht unterst&uuml;tzte Status f&uuml;hren zu Fehlern
  1583. </li>
  1584. <li>
  1585. <b>rg_wakeupDevice</b> - Referenz zu versklavten DUMMY Ger&auml;ten, welche als Wecker benutzt werden (Teil von RESIDENTS Toolkit's wakeuptimer)
  1586. </li>
  1587. </ul>
  1588. </ul><br>
  1589. <br>
  1590. <br>
  1591. <b>Generierte Readings/Events:</b><br>
  1592. <ul>
  1593. <ul>
  1594. <li>
  1595. <b>durTimerAbsence</b> - Timer, der die Dauer der Abwesenheit in normal lesbarem Format anzeigt (Stunden:Minuten:Sekunden)
  1596. </li>
  1597. <li>
  1598. <b>durTimerAbsence_cr</b> - Timer, der die Dauer der Abwesenheit in Computer lesbarem Format anzeigt (Minuten)
  1599. </li>
  1600. <li>
  1601. <b>durTimerPresence</b> - Timer, der die Dauer der Anwesenheit in normal lesbarem Format anzeigt (Stunden:Minuten:Sekunden)
  1602. </li>
  1603. <li>
  1604. <b>durTimerPresence_cr</b> - Timer, der die Dauer der Anwesenheit in Computer lesbarem Format anzeigt (Minuten)
  1605. </li>
  1606. <li>
  1607. <b>durTimerSleep</b> - Timer, der die Schlafdauer in normal lesbarem Format anzeigt (Stunden:Minuten:Sekunden)
  1608. </li>
  1609. <li>
  1610. <b>durTimerSleep_cr</b> - Timer, der die Schlafdauer in Computer lesbarem Format anzeigt (Minuten)
  1611. </li>
  1612. <li>
  1613. <b>lastArrival</b> - Zeitstempel der letzten Ankunft zu Hause
  1614. </li>
  1615. <li>
  1616. <b>lastAwake</b> - Zeitstempel des Endes des letzten Schlafzyklus
  1617. </li>
  1618. <li>
  1619. <b>lastDeparture</b> - Zeitstempel des letzten Verlassens des Zuhauses
  1620. </li>
  1621. <li>
  1622. <b>lastDurAbsence</b> - Dauer der letzten Abwesenheit in normal lesbarem Format (Stunden:Minuten:Sekunden)
  1623. </li>
  1624. <li>
  1625. <b>lastDurAbsence_cr</b> - Dauer der letzten Abwesenheit in Computer lesbarem Format (Minuten)
  1626. </li>
  1627. <li>
  1628. <b>lastDurPresence</b> - Dauer der letzten Anwesenheit in normal lesbarem Format (Stunden:Minuten:Sekunden)
  1629. </li>
  1630. <li>
  1631. <b>lastDurPresence_cr</b> - Dauer der letzten Anwesenheit in Computer lesbarem Format (Minuten)
  1632. </li>
  1633. <li>
  1634. <b>lastDurSleep</b> - Dauer des letzten Schlafzyklus in normal lesbarem Format (Stunden:Minuten:Sekunden)
  1635. </li>
  1636. <li>
  1637. <b>lastDurSleep_cr</b> - Dauer des letzten Schlafzyklus in Computer lesbarem Format (Minuten)
  1638. </li>
  1639. <li>
  1640. <b>lastLocation</b> - der vorherige Aufenthaltsort
  1641. </li>
  1642. <li>
  1643. <b>lastMood</b> - die vorherige Stimmung
  1644. </li>
  1645. <li>
  1646. <b>lastSleep</b> - Zeitstempel des Beginns des letzten Schlafzyklus
  1647. </li>
  1648. <li>
  1649. <b>lastState</b> - der vorherige Status
  1650. </li>
  1651. <li>
  1652. <b>lastWakeup</b> - Zeit der letzten Wake-up Timer Ausf&uuml;hring
  1653. </li>
  1654. <li>
  1655. <b>lastWakeupDev</b> - Device Name des zuletzt verwendeten Wake-up Timers
  1656. </li>
  1657. <li>
  1658. <b>location</b> - der aktuelle Aufenthaltsort
  1659. </li>
  1660. <li>
  1661. <b>mood</b> - die aktuelle Stimmung
  1662. </li>
  1663. <li>
  1664. <b>nextWakeup</b> - Zeit der n&auml;chsten Wake-up Timer Ausf&uuml;hrung
  1665. </li>
  1666. <li>
  1667. <b>nextWakeupDev</b> - Device Name des als n&auml;chstes ausgef&auml;hrten Wake-up Timer
  1668. </li>
  1669. <li>
  1670. <b>presence</b> - gibt den zu Hause Status in Abh&auml;ngigkeit des Readings 'state' wieder (kann 'present' oder 'absent' sein)
  1671. </li>
  1672. <li>
  1673. <b>state</b> - gibt den aktuellen Status wieder
  1674. </li>
  1675. <li>
  1676. <b>wakeup</b> - hat den Wert '1' w&auml;hrend ein Weckprogramm dieses Bewohners ausgef&uuml;hrt wird
  1677. </li>
  1678. <li>
  1679. <b>wayhome</b> - abh&auml;ngig vom aktullen Aufenthaltsort, kann der Wert '1' werden, wenn die Person auf dem weg zur&uuml;ck nach Hause ist
  1680. </li>
  1681. <li>
  1682. <br>
  1683. Die folgenden Readings werden auf '-' gesetzt, sobald der Status auf 'none' steht:<br>
  1684. lastArrival, lastDurAbsence, lastLocation, lastMood, location, mood
  1685. </li>
  1686. </ul>
  1687. </ul>
  1688. </ul>
  1689. =end html_DE
  1690. =cut