RESIDENTS,ROOMMATE,GUEST: fix readingsBeginUpdate
git-svn-id: svn://svn.code.sf.net/p/fhem/code/trunk@10387 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
@@ -151,8 +151,8 @@ sub RESIDENTS_Notify($$) {
|
|||||||
|
|
||||||
foreach my $change ( @{ $dev->{CHANGED} } ) {
|
foreach my $change ( @{ $dev->{CHANGED} } ) {
|
||||||
|
|
||||||
Log3 $dev->{NAME}, 5,
|
Log3 $hash, 5,
|
||||||
"RESIDENTS " . $dev->{NAME} . ": processing change $change";
|
"RESIDENTS " . $hashName . ": processing change $change";
|
||||||
|
|
||||||
# state changed
|
# state changed
|
||||||
if ( $change !~ /:/
|
if ( $change !~ /:/
|
||||||
@@ -199,7 +199,8 @@ sub RESIDENTS_Notify($$) {
|
|||||||
|
|
||||||
# update statistics
|
# update statistics
|
||||||
readingsBeginUpdate($hash);
|
readingsBeginUpdate($hash);
|
||||||
readingsBulkUpdate( $hash, "lastActivity", ReadingsVal($devName, "state", $change) );
|
readingsBulkUpdate( $hash, "lastActivity",
|
||||||
|
ReadingsVal( $devName, "state", $change ) );
|
||||||
readingsBulkUpdate( $hash, "lastActivityBy", $realname );
|
readingsBulkUpdate( $hash, "lastActivityBy", $realname );
|
||||||
readingsBulkUpdate( $hash, "lastActivityByDev", $devName );
|
readingsBulkUpdate( $hash, "lastActivityByDev", $devName );
|
||||||
readingsEndUpdate( $hash, 1 );
|
readingsEndUpdate( $hash, 1 );
|
||||||
@@ -258,10 +259,7 @@ sub RESIDENTS_Notify($$) {
|
|||||||
sub RESIDENTS_Set($@) {
|
sub RESIDENTS_Set($@) {
|
||||||
my ( $hash, @a ) = @_;
|
my ( $hash, @a ) = @_;
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
my $state =
|
my $state = ReadingsVal( $name, "state", "initialized" );
|
||||||
( defined( $hash->{READINGS}{state}{VAL} ) )
|
|
||||||
? $hash->{READINGS}{state}{VAL}
|
|
||||||
: "initialized";
|
|
||||||
my $roommates = ( $hash->{ROOMMATES} ? $hash->{ROOMMATES} : "" );
|
my $roommates = ( $hash->{ROOMMATES} ? $hash->{ROOMMATES} : "" );
|
||||||
my $guests = ( $hash->{GUESTS} ? $hash->{GUESTS} : "" );
|
my $guests = ( $hash->{GUESTS} ? $hash->{GUESTS} : "" );
|
||||||
|
|
||||||
@@ -350,11 +348,9 @@ sub RESIDENTS_Set($@) {
|
|||||||
split( /,/, $hash->{ROOMMATES} );
|
split( /,/, $hash->{ROOMMATES} );
|
||||||
|
|
||||||
foreach my $roommate (@registeredRoommates) {
|
foreach my $roommate (@registeredRoommates) {
|
||||||
if ( defined( $defs{$roommate} )
|
fhem "set $roommate silentSet state $newstate"
|
||||||
&& $defs{$roommate}{READINGS}{state} ne $newstate )
|
if ( ReadingsVal( $roommate, "state", "initialized" ) ne
|
||||||
{
|
$newstate );
|
||||||
fhem "set $roommate silentSet state $newstate";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -368,12 +364,9 @@ sub RESIDENTS_Set($@) {
|
|||||||
split( /,/, $hash->{GUESTS} );
|
split( /,/, $hash->{GUESTS} );
|
||||||
|
|
||||||
foreach my $guest (@registeredGuests) {
|
foreach my $guest (@registeredGuests) {
|
||||||
if ( defined( $defs{$guest} )
|
fhem "set $guest silentSet state $newstate"
|
||||||
&& $defs{$guest}{READINGS}{state}{VAL} ne "none"
|
if ( ReadingsVal( $guest, "state", "initialized" ) ne
|
||||||
&& $defs{$guest}{READINGS}{state}{VAL} ne $newstate )
|
$newstate );
|
||||||
{
|
|
||||||
fhem "set $guest silentSet state $newstate";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -642,14 +635,8 @@ sub RESIDENTS_Set($@) {
|
|||||||
sub RESIDENTS_UpdateReadings (@) {
|
sub RESIDENTS_UpdateReadings (@) {
|
||||||
my ($hash) = @_;
|
my ($hash) = @_;
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
my $state =
|
my $state = ReadingsVal( $name, "state", "none" );
|
||||||
( defined( $hash->{READINGS}{state}{VAL} ) )
|
my $presence = ReadingsVal( $name, "presence", "absent" );
|
||||||
? $hash->{READINGS}{state}{VAL}
|
|
||||||
: "none";
|
|
||||||
my $presence =
|
|
||||||
( defined( $hash->{READINGS}{presence}{VAL} ) )
|
|
||||||
? $hash->{READINGS}{presence}{VAL}
|
|
||||||
: "absent";
|
|
||||||
|
|
||||||
my $state_home = 0;
|
my $state_home = 0;
|
||||||
my $state_gotosleep = 0;
|
my $state_gotosleep = 0;
|
||||||
@@ -721,8 +708,7 @@ sub RESIDENTS_UpdateReadings (@) {
|
|||||||
Log3 $name, 5,
|
Log3 $name, 5,
|
||||||
"RESIDENTS $name: considering $roommate for state change";
|
"RESIDENTS $name: considering $roommate for state change";
|
||||||
|
|
||||||
if ( defined( $defs{$roommate}{READINGS}{state}{VAL} ) ) {
|
if ( ReadingsVal( $roommate, "state", "initialized" ) eq "home" ) {
|
||||||
if ( $defs{$roommate}{READINGS}{state}{VAL} eq "home" ) {
|
|
||||||
$state_home++;
|
$state_home++;
|
||||||
$residentsDevs_home .= "," . $roommate
|
$residentsDevs_home .= "," . $roommate
|
||||||
if ( $residentsDevs_home ne "-" );
|
if ( $residentsDevs_home ne "-" );
|
||||||
@@ -748,12 +734,16 @@ sub RESIDENTS_UpdateReadings (@) {
|
|||||||
$residents_totalPresent = $roommateName
|
$residents_totalPresent = $roommateName
|
||||||
if ( $roommateName ne "" && $residents_totalPresent eq "-" );
|
if ( $roommateName ne "" && $residents_totalPresent eq "-" );
|
||||||
$residents_totalPresentRoommates .= ", " . $roommateName
|
$residents_totalPresentRoommates .= ", " . $roommateName
|
||||||
if ( $roommateName ne "" && $residents_totalPresentRoommates ne "-" );
|
if ( $roommateName ne ""
|
||||||
|
&& $residents_totalPresentRoommates ne "-" );
|
||||||
$residents_totalPresentRoommates = $roommateName
|
$residents_totalPresentRoommates = $roommateName
|
||||||
if ( $roommateName ne "" && $residents_totalPresentRoommates eq "-" );
|
if ( $roommateName ne ""
|
||||||
|
&& $residents_totalPresentRoommates eq "-" );
|
||||||
}
|
}
|
||||||
|
|
||||||
elsif ( $defs{$roommate}{READINGS}{state}{VAL} eq "gotosleep" ) {
|
elsif (
|
||||||
|
ReadingsVal( $roommate, "state", "initialized" ) eq "gotosleep" )
|
||||||
|
{
|
||||||
$state_gotosleep++;
|
$state_gotosleep++;
|
||||||
$residentsDevs_gotosleep .= "," . $roommate
|
$residentsDevs_gotosleep .= "," . $roommate
|
||||||
if ( $residentsDevs_gotosleep ne "-" );
|
if ( $residentsDevs_gotosleep ne "-" );
|
||||||
@@ -779,12 +769,14 @@ sub RESIDENTS_UpdateReadings (@) {
|
|||||||
$residents_totalPresent = $roommateName
|
$residents_totalPresent = $roommateName
|
||||||
if ( $roommateName ne "" && $residents_totalPresent eq "-" );
|
if ( $roommateName ne "" && $residents_totalPresent eq "-" );
|
||||||
$residents_totalPresentRoommates .= ", " . $roommateName
|
$residents_totalPresentRoommates .= ", " . $roommateName
|
||||||
if ( $roommateName ne "" && $residents_totalPresentRoommates ne "-" );
|
if ( $roommateName ne ""
|
||||||
|
&& $residents_totalPresentRoommates ne "-" );
|
||||||
$residents_totalPresentRoommates = $roommateName
|
$residents_totalPresentRoommates = $roommateName
|
||||||
if ( $roommateName ne "" && $residents_totalPresentRoommates eq "-" );
|
if ( $roommateName ne ""
|
||||||
|
&& $residents_totalPresentRoommates eq "-" );
|
||||||
}
|
}
|
||||||
|
|
||||||
elsif ( $defs{$roommate}{READINGS}{state}{VAL} eq "asleep" ) {
|
elsif ( ReadingsVal( $roommate, "state", "initialized" ) eq "asleep" ) {
|
||||||
$state_asleep++;
|
$state_asleep++;
|
||||||
$residentsDevs_asleep .= "," . $roommate
|
$residentsDevs_asleep .= "," . $roommate
|
||||||
if ( $residentsDevs_asleep ne "-" );
|
if ( $residentsDevs_asleep ne "-" );
|
||||||
@@ -810,12 +802,14 @@ sub RESIDENTS_UpdateReadings (@) {
|
|||||||
$residents_totalPresent = $roommateName
|
$residents_totalPresent = $roommateName
|
||||||
if ( $roommateName ne "" && $residents_totalPresent eq "-" );
|
if ( $roommateName ne "" && $residents_totalPresent eq "-" );
|
||||||
$residents_totalPresentRoommates .= ", " . $roommateName
|
$residents_totalPresentRoommates .= ", " . $roommateName
|
||||||
if ( $roommateName ne "" && $residents_totalPresentRoommates ne "-" );
|
if ( $roommateName ne ""
|
||||||
|
&& $residents_totalPresentRoommates ne "-" );
|
||||||
$residents_totalPresentRoommates = $roommateName
|
$residents_totalPresentRoommates = $roommateName
|
||||||
if ( $roommateName ne "" && $residents_totalPresentRoommates eq "-" );
|
if ( $roommateName ne ""
|
||||||
|
&& $residents_totalPresentRoommates eq "-" );
|
||||||
}
|
}
|
||||||
|
|
||||||
elsif ( $defs{$roommate}{READINGS}{state}{VAL} eq "awoken" ) {
|
elsif ( ReadingsVal( $roommate, "state", "initialized" ) eq "awoken" ) {
|
||||||
$state_awoken++;
|
$state_awoken++;
|
||||||
$residentsDevs_awoken .= "," . $roommate
|
$residentsDevs_awoken .= "," . $roommate
|
||||||
if ( $residentsDevs_awoken ne "-" );
|
if ( $residentsDevs_awoken ne "-" );
|
||||||
@@ -841,12 +835,14 @@ sub RESIDENTS_UpdateReadings (@) {
|
|||||||
$residents_totalPresent = $roommateName
|
$residents_totalPresent = $roommateName
|
||||||
if ( $roommateName ne "" && $residents_totalPresent eq "-" );
|
if ( $roommateName ne "" && $residents_totalPresent eq "-" );
|
||||||
$residents_totalPresentRoommates .= ", " . $roommateName
|
$residents_totalPresentRoommates .= ", " . $roommateName
|
||||||
if ( $roommateName ne "" && $residents_totalPresentRoommates ne "-" );
|
if ( $roommateName ne ""
|
||||||
|
&& $residents_totalPresentRoommates ne "-" );
|
||||||
$residents_totalPresentRoommates = $roommateName
|
$residents_totalPresentRoommates = $roommateName
|
||||||
if ( $roommateName ne "" && $residents_totalPresentRoommates eq "-" );
|
if ( $roommateName ne ""
|
||||||
|
&& $residents_totalPresentRoommates eq "-" );
|
||||||
}
|
}
|
||||||
|
|
||||||
elsif ( $defs{$roommate}{READINGS}{state}{VAL} eq "absent" ) {
|
elsif ( ReadingsVal( $roommate, "state", "initialized" ) eq "absent" ) {
|
||||||
$state_absent++;
|
$state_absent++;
|
||||||
$residentsDevs_absent .= "," . $roommate
|
$residentsDevs_absent .= "," . $roommate
|
||||||
if ( $residentsDevs_absent ne "-" );
|
if ( $residentsDevs_absent ne "-" );
|
||||||
@@ -872,12 +868,14 @@ sub RESIDENTS_UpdateReadings (@) {
|
|||||||
$residents_totalAbsent = $roommateName
|
$residents_totalAbsent = $roommateName
|
||||||
if ( $roommateName ne "" && $residents_totalAbsent eq "-" );
|
if ( $roommateName ne "" && $residents_totalAbsent eq "-" );
|
||||||
$residents_totalAbsentRoommates .= ", " . $roommateName
|
$residents_totalAbsentRoommates .= ", " . $roommateName
|
||||||
if ( $roommateName ne "" && $residents_totalAbsentRoommates ne "-" );
|
if ( $roommateName ne ""
|
||||||
|
&& $residents_totalAbsentRoommates ne "-" );
|
||||||
$residents_totalAbsentRoommates = $roommateName
|
$residents_totalAbsentRoommates = $roommateName
|
||||||
if ( $roommateName ne "" && $residents_totalAbsentRoommates eq "-" );
|
if ( $roommateName ne ""
|
||||||
|
&& $residents_totalAbsentRoommates eq "-" );
|
||||||
}
|
}
|
||||||
|
|
||||||
elsif ( $defs{$roommate}{READINGS}{state}{VAL} eq "gone" ) {
|
elsif ( ReadingsVal( $roommate, "state", "initialized" ) eq "gone" ) {
|
||||||
$state_gone++;
|
$state_gone++;
|
||||||
$residentsDevs_gone .= "," . $roommate
|
$residentsDevs_gone .= "," . $roommate
|
||||||
if ( $residentsDevs_gone ne "-" );
|
if ( $residentsDevs_gone ne "-" );
|
||||||
@@ -903,16 +901,15 @@ sub RESIDENTS_UpdateReadings (@) {
|
|||||||
$residents_totalAbsent = $roommateName
|
$residents_totalAbsent = $roommateName
|
||||||
if ( $roommateName ne "" && $residents_totalAbsent eq "-" );
|
if ( $roommateName ne "" && $residents_totalAbsent eq "-" );
|
||||||
$residents_totalAbsentRoommates .= ", " . $roommateName
|
$residents_totalAbsentRoommates .= ", " . $roommateName
|
||||||
if ( $roommateName ne "" && $residents_totalAbsentRoommates ne "-" );
|
if ( $roommateName ne ""
|
||||||
|
&& $residents_totalAbsentRoommates ne "-" );
|
||||||
$residents_totalAbsentRoommates = $roommateName
|
$residents_totalAbsentRoommates = $roommateName
|
||||||
if ( $roommateName ne "" && $residents_totalAbsentRoommates eq "-" );
|
if ( $roommateName ne ""
|
||||||
}
|
&& $residents_totalAbsentRoommates eq "-" );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( defined( $defs{$roommate}{READINGS}{wakeup}{VAL} )
|
if ( ReadingsVal( $roommate, "wakeup", "0" ) > 0 ) {
|
||||||
&& $defs{$roommate}{READINGS}{wakeup}{VAL} > 0 )
|
$wakeup += ReadingsVal( $name, "wakeup", "0" );
|
||||||
{
|
|
||||||
$wakeup += $defs{$roommate}{READINGS}{wakeup}{VAL};
|
|
||||||
$residentsDevs_wakeup .= "," . $roommate
|
$residentsDevs_wakeup .= "," . $roommate
|
||||||
if ( $residentsDevs_wakeup ne "-" );
|
if ( $residentsDevs_wakeup ne "-" );
|
||||||
$residentsDevs_wakeup = $roommate
|
$residentsDevs_wakeup = $roommate
|
||||||
@@ -923,10 +920,8 @@ sub RESIDENTS_UpdateReadings (@) {
|
|||||||
if ( $roommateName ne "" && $residents_wakeup eq "-" );
|
if ( $roommateName ne "" && $residents_wakeup eq "-" );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( defined( $defs{$roommate}{READINGS}{wayhome}{VAL} )
|
if ( ReadingsVal( $roommate, "wayhome", "0" ) > 0 ) {
|
||||||
&& $defs{$roommate}{READINGS}{wayhome}{VAL} > 0 )
|
$wayhome += ReadingsVal( $name, "wayhome", "0" );
|
||||||
{
|
|
||||||
$wayhome += $defs{$roommate}{READINGS}{wayhome}{VAL};
|
|
||||||
$residents_wayhome .= "," . $roommate
|
$residents_wayhome .= "," . $roommate
|
||||||
if ( $residents_wayhome ne "-" );
|
if ( $residents_wayhome ne "-" );
|
||||||
$residents_wayhome = $roommate if ( $residents_wayhome eq "-" );
|
$residents_wayhome = $roommate if ( $residents_wayhome eq "-" );
|
||||||
@@ -946,8 +941,7 @@ sub RESIDENTS_UpdateReadings (@) {
|
|||||||
|
|
||||||
Log3 $name, 5, "RESIDENTS $name: considering $guest for state change";
|
Log3 $name, 5, "RESIDENTS $name: considering $guest for state change";
|
||||||
|
|
||||||
if ( defined( $defs{$guest}{READINGS}{state}{VAL} ) ) {
|
if ( ReadingsVal( $guest, "state", "initialized" ) eq "home" ) {
|
||||||
if ( $defs{$guest}{READINGS}{state}{VAL} eq "home" ) {
|
|
||||||
$state_home++;
|
$state_home++;
|
||||||
$state_totalPresent++;
|
$state_totalPresent++;
|
||||||
$state_totalGuestsPresent++;
|
$state_totalGuestsPresent++;
|
||||||
@@ -977,7 +971,7 @@ sub RESIDENTS_UpdateReadings (@) {
|
|||||||
&& $residents_totalPresent eq "-" );
|
&& $residents_totalPresent eq "-" );
|
||||||
}
|
}
|
||||||
|
|
||||||
elsif ( $defs{$guest}{READINGS}{state}{VAL} eq "gotosleep" ) {
|
elsif ( ReadingsVal( $guest, "state", "initialized" ) eq "gotosleep" ) {
|
||||||
$state_gotosleep++;
|
$state_gotosleep++;
|
||||||
$state_totalPresent++;
|
$state_totalPresent++;
|
||||||
$state_totalGuestsPresent++;
|
$state_totalGuestsPresent++;
|
||||||
@@ -1007,7 +1001,7 @@ sub RESIDENTS_UpdateReadings (@) {
|
|||||||
&& $residents_totalPresent eq "-" );
|
&& $residents_totalPresent eq "-" );
|
||||||
}
|
}
|
||||||
|
|
||||||
elsif ( $defs{$guest}{READINGS}{state}{VAL} eq "asleep" ) {
|
elsif ( ReadingsVal( $guest, "state", "initialized" ) eq "asleep" ) {
|
||||||
$state_asleep++;
|
$state_asleep++;
|
||||||
$state_totalPresent++;
|
$state_totalPresent++;
|
||||||
$state_totalGuestsPresent++;
|
$state_totalGuestsPresent++;
|
||||||
@@ -1037,7 +1031,7 @@ sub RESIDENTS_UpdateReadings (@) {
|
|||||||
&& $residents_totalPresent eq "-" );
|
&& $residents_totalPresent eq "-" );
|
||||||
}
|
}
|
||||||
|
|
||||||
elsif ( $defs{$guest}{READINGS}{state}{VAL} eq "awoken" ) {
|
elsif ( ReadingsVal( $guest, "state", "initialized" ) eq "awoken" ) {
|
||||||
$state_awoken++;
|
$state_awoken++;
|
||||||
$state_totalPresent++;
|
$state_totalPresent++;
|
||||||
$state_totalGuestsPresent++;
|
$state_totalGuestsPresent++;
|
||||||
@@ -1067,7 +1061,7 @@ sub RESIDENTS_UpdateReadings (@) {
|
|||||||
&& $residents_totalPresent eq "-" );
|
&& $residents_totalPresent eq "-" );
|
||||||
}
|
}
|
||||||
|
|
||||||
elsif ( $defs{$guest}{READINGS}{state}{VAL} eq "absent" ) {
|
elsif ( ReadingsVal( $guest, "state", "initialized" ) eq "absent" ) {
|
||||||
$state_absent++;
|
$state_absent++;
|
||||||
$state_totalAbsent++;
|
$state_totalAbsent++;
|
||||||
$state_totalGuestsAbsent++;
|
$state_totalGuestsAbsent++;
|
||||||
@@ -1096,12 +1090,9 @@ sub RESIDENTS_UpdateReadings (@) {
|
|||||||
if ( $guestName ne ""
|
if ( $guestName ne ""
|
||||||
&& $residents_totalAbsent eq "-" );
|
&& $residents_totalAbsent eq "-" );
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if ( defined( $defs{$guest}{READINGS}{wakeup}{VAL} )
|
if ( ReadingsVal( $guest, "wakeup", "0" ) > 0 ) {
|
||||||
&& $defs{$guest}{READINGS}{wakeup}{VAL} > 0 )
|
$wakeup += ReadingsVal( $guest, "wakeup", "0" );
|
||||||
{
|
|
||||||
$wakeup += $defs{$guest}{READINGS}{wakeup}{VAL};
|
|
||||||
$residentsDevs_wakeup .= "," . $guest
|
$residentsDevs_wakeup .= "," . $guest
|
||||||
if ( $residentsDevs_wakeup ne "-" );
|
if ( $residentsDevs_wakeup ne "-" );
|
||||||
$residentsDevs_wakeup = $guest
|
$residentsDevs_wakeup = $guest
|
||||||
@@ -1112,10 +1103,8 @@ sub RESIDENTS_UpdateReadings (@) {
|
|||||||
if ( $guestName ne "" && $residents_wakeup eq "-" );
|
if ( $guestName ne "" && $residents_wakeup eq "-" );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( defined( $defs{$guest}{READINGS}{wayhome}{VAL} )
|
if ( ReadingsVal( $guest, "wayhome", "0" ) > 0 ) {
|
||||||
&& $defs{$guest}{READINGS}{wayhome}{VAL} > 0 )
|
$wayhome += ReadingsVal( $guest, "wakeup", "0" );
|
||||||
{
|
|
||||||
$wayhome += $defs{$guest}{READINGS}{wayhome}{VAL};
|
|
||||||
$residents_wayhome .= "," . $guest
|
$residents_wayhome .= "," . $guest
|
||||||
if ( $residents_wayhome ne "-" );
|
if ( $residents_wayhome ne "-" );
|
||||||
$residents_wayhome = $guest if ( $residents_wayhome eq "-" );
|
$residents_wayhome = $guest if ( $residents_wayhome eq "-" );
|
||||||
@@ -1141,17 +1130,15 @@ sub RESIDENTS_UpdateReadings (@) {
|
|||||||
readingsBeginUpdate($hash);
|
readingsBeginUpdate($hash);
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "residentsTotal", $state_total )
|
readingsBulkUpdate( $hash, "residentsTotal", $state_total )
|
||||||
if ( !defined( $hash->{READINGS}{residentsTotal}{VAL} )
|
if ( ReadingsVal( $name, "residentsTotal", "" ) ne $state_total );
|
||||||
|| $hash->{READINGS}{residentsTotal}{VAL} ne $state_total );
|
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "residentsTotalGuests", $state_totalGuests )
|
readingsBulkUpdate( $hash, "residentsTotalGuests", $state_totalGuests )
|
||||||
if ( !defined( $hash->{READINGS}{residentsTotalGuests}{VAL} )
|
if ( ReadingsVal( $name, "residentsTotalGuests", "" ) ne
|
||||||
|| $hash->{READINGS}{residentsTotalGuests}{VAL} ne $state_totalGuests );
|
$state_totalGuests );
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "residentsTotalGuestsPresent",
|
readingsBulkUpdate( $hash, "residentsTotalGuestsPresent",
|
||||||
$state_totalGuestsPresent )
|
$state_totalGuestsPresent )
|
||||||
if ( !defined( $hash->{READINGS}{residentsTotalGuestsPresent}{VAL} )
|
if ( ReadingsVal( $name, "residentsTotalGuestsPresent", "" ) ne
|
||||||
|| $hash->{READINGS}{residentsTotalGuestsPresent}{VAL} ne
|
|
||||||
$state_totalGuestsPresent );
|
$state_totalGuestsPresent );
|
||||||
|
|
||||||
readingsBulkUpdate(
|
readingsBulkUpdate(
|
||||||
@@ -1159,20 +1146,17 @@ sub RESIDENTS_UpdateReadings (@) {
|
|||||||
"residentsTotalGuestsPresentDevs",
|
"residentsTotalGuestsPresentDevs",
|
||||||
$residentsDevs_totalPresentGuest
|
$residentsDevs_totalPresentGuest
|
||||||
)
|
)
|
||||||
if ( !defined( $hash->{READINGS}{residentsTotalGuestsPresentDevs}{VAL} )
|
if ( ReadingsVal( $name, "residentsTotalGuestsPresentDevs", "" ) ne
|
||||||
|| $hash->{READINGS}{residentsTotalGuestsPresentDevs}{VAL} ne
|
|
||||||
$residentsDevs_totalPresentGuest );
|
$residentsDevs_totalPresentGuest );
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "residentsTotalGuestsPresentNames",
|
readingsBulkUpdate( $hash, "residentsTotalGuestsPresentNames",
|
||||||
$residents_totalPresentGuest )
|
$residents_totalPresentGuest )
|
||||||
if ( !defined( $hash->{READINGS}{residentsTotalGuestsPresentNames}{VAL} )
|
if ( ReadingsVal( $name, "residentsTotalGuestsPresentNames", "" ) ne
|
||||||
|| $hash->{READINGS}{residentsTotalGuestsPresentNames}{VAL} ne
|
|
||||||
$residents_totalPresentGuest );
|
$residents_totalPresentGuest );
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "residentsTotalGuestsAbsent",
|
readingsBulkUpdate( $hash, "residentsTotalGuestsAbsent",
|
||||||
$state_totalGuestsAbsent )
|
$state_totalGuestsAbsent )
|
||||||
if ( !defined( $hash->{READINGS}{residentsTotalGuestsAbsent}{VAL} )
|
if ( ReadingsVal( $name, "residentsTotalGuestsAbsent", "" ) ne
|
||||||
|| $hash->{READINGS}{residentsTotalGuestsAbsent}{VAL} ne
|
|
||||||
$state_totalGuestsAbsent );
|
$state_totalGuestsAbsent );
|
||||||
|
|
||||||
readingsBulkUpdate(
|
readingsBulkUpdate(
|
||||||
@@ -1180,24 +1164,22 @@ sub RESIDENTS_UpdateReadings (@) {
|
|||||||
"residentsTotalGuestsAbsentDevs",
|
"residentsTotalGuestsAbsentDevs",
|
||||||
$residentsDevs_totalAbsentGuest
|
$residentsDevs_totalAbsentGuest
|
||||||
)
|
)
|
||||||
if ( !defined( $hash->{READINGS}{residentsTotalGuestsAbsentDevs}{VAL} )
|
if ( ReadingsVal( $name, "residentsTotalGuestsAbsentDevs", "" ) ne
|
||||||
|| $hash->{READINGS}{residentsTotalGuestsAbsentDevs}{VAL} ne
|
|
||||||
$residentsDevs_totalAbsentGuest );
|
$residentsDevs_totalAbsentGuest );
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "residentsTotalGuestsAbsentNames",
|
readingsBulkUpdate( $hash, "residentsTotalGuestsAbsentNames",
|
||||||
$residents_totalAbsentGuest )
|
$residents_totalAbsentGuest )
|
||||||
if ( !defined( $hash->{READINGS}{residentsTotalGuestsAbsentNames}{VAL} )
|
if ( ReadingsVal( $name, "residentsTotalGuestsAbsentNames", "" ) ne
|
||||||
|| $hash->{READINGS}{residentsTotalGuestsAbsentNames}{VAL} ne
|
|
||||||
$residents_totalAbsentGuest );
|
$residents_totalAbsentGuest );
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "residentsTotalRoommates", $state_totalRoommates )
|
readingsBulkUpdate( $hash, "residentsTotalRoommates",
|
||||||
if ( !defined( $hash->{READINGS}{residentsTotalRoommates}{VAL} )
|
$state_totalRoommates )
|
||||||
|| $hash->{READINGS}{residentsTotalRoommates}{VAL} ne $state_totalRoommates );
|
if ( ReadingsVal( $name, "residentsTotalRoommates", "" ) ne
|
||||||
|
$state_totalRoommates );
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "residentsTotalRoommatesPresent",
|
readingsBulkUpdate( $hash, "residentsTotalRoommatesPresent",
|
||||||
$state_totalRoommatesPresent )
|
$state_totalRoommatesPresent )
|
||||||
if ( !defined( $hash->{READINGS}{residentsTotalRoommatesPresent}{VAL} )
|
if ( ReadingsVal( $name, "residentsTotalRoommatesPresent", "" ) ne
|
||||||
|| $hash->{READINGS}{residentsTotalRoommatesPresent}{VAL} ne
|
|
||||||
$state_totalRoommatesPresent );
|
$state_totalRoommatesPresent );
|
||||||
|
|
||||||
readingsBulkUpdate(
|
readingsBulkUpdate(
|
||||||
@@ -1205,20 +1187,20 @@ sub RESIDENTS_UpdateReadings (@) {
|
|||||||
"residentsTotalRoommatesPresentDevs",
|
"residentsTotalRoommatesPresentDevs",
|
||||||
$residentsDevs_totalPresentRoommates
|
$residentsDevs_totalPresentRoommates
|
||||||
)
|
)
|
||||||
if ( !defined( $hash->{READINGS}{residentsTotalRoommatesPresentDevs}{VAL} )
|
if ( ReadingsVal( $name, "residentsTotalRoommatesPresentDevs", "" ) ne
|
||||||
|| $hash->{READINGS}{residentsTotalRoommatesPresentDevs}{VAL} ne
|
|
||||||
$residentsDevs_totalPresentRoommates );
|
$residentsDevs_totalPresentRoommates );
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "residentsTotalRoommatesPresentNames",
|
readingsBulkUpdate(
|
||||||
$residents_totalPresentRoommates )
|
$hash,
|
||||||
if ( !defined( $hash->{READINGS}{residentsTotalRoommatesPresentNames}{VAL} )
|
"residentsTotalRoommatesPresentNames",
|
||||||
|| $hash->{READINGS}{residentsTotalRoommatesPresentNames}{VAL} ne
|
$residents_totalPresentRoommates
|
||||||
|
)
|
||||||
|
if ( ReadingsVal( $name, "residentsTotalRoommatesPresentNames", "" ) ne
|
||||||
$residents_totalPresentRoommates );
|
$residents_totalPresentRoommates );
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "residentsTotalRoommatesAbsent",
|
readingsBulkUpdate( $hash, "residentsTotalRoommatesAbsent",
|
||||||
$state_totalRoommatesAbsent )
|
$state_totalRoommatesAbsent )
|
||||||
if ( !defined( $hash->{READINGS}{residentsTotalRoommatesAbsent}{VAL} )
|
if ( ReadingsVal( $name, "residentsTotalRoommatesAbsent", "" ) ne
|
||||||
|| $hash->{READINGS}{residentsTotalRoommatesAbsent}{VAL} ne
|
|
||||||
$state_totalRoommatesAbsent );
|
$state_totalRoommatesAbsent );
|
||||||
|
|
||||||
readingsBulkUpdate(
|
readingsBulkUpdate(
|
||||||
@@ -1226,156 +1208,133 @@ sub RESIDENTS_UpdateReadings (@) {
|
|||||||
"residentsTotalRoommatesAbsentDevs",
|
"residentsTotalRoommatesAbsentDevs",
|
||||||
$residentsDevs_totalAbsentRoommates
|
$residentsDevs_totalAbsentRoommates
|
||||||
)
|
)
|
||||||
if ( !defined( $hash->{READINGS}{residentsTotalRoommatesAbsentDevs}{VAL} )
|
if ( ReadingsVal( $name, "residentsTotalRoommatesAbsentDevs", "" ) ne
|
||||||
|| $hash->{READINGS}{residentsTotalRoommatesAbsentDevs}{VAL} ne
|
|
||||||
$residentsDevs_totalAbsentRoommates );
|
$residentsDevs_totalAbsentRoommates );
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "residentsTotalRoommatesAbsentNames",
|
readingsBulkUpdate(
|
||||||
$residents_totalAbsentRoommates )
|
$hash,
|
||||||
if ( !defined( $hash->{READINGS}{residentsTotalRoommatesAbsentNames}{VAL} )
|
"residentsTotalRoommatesAbsentNames",
|
||||||
|| $hash->{READINGS}{residentsTotalRoommatesAbsentNames}{VAL} ne
|
$residents_totalAbsentRoommates
|
||||||
|
)
|
||||||
|
if ( ReadingsVal( $name, "residentsTotalRoommatesAbsentNames", "" ) ne
|
||||||
$residents_totalAbsentRoommates );
|
$residents_totalAbsentRoommates );
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "residentsTotalPresent", $state_totalPresent )
|
readingsBulkUpdate( $hash, "residentsTotalPresent", $state_totalPresent )
|
||||||
if ( !defined( $hash->{READINGS}{residentsTotalPresent}{VAL} )
|
if ( ReadingsVal( $name, "residentsTotalPresent", "" ) ne
|
||||||
|| $hash->{READINGS}{residentsTotalPresent}{VAL} ne
|
|
||||||
$state_totalPresent );
|
$state_totalPresent );
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "residentsTotalPresentDevs",
|
readingsBulkUpdate( $hash, "residentsTotalPresentDevs",
|
||||||
$residentsDevs_totalPresent )
|
$residentsDevs_totalPresent )
|
||||||
if ( !defined( $hash->{READINGS}{residentsTotalPresentDevs}{VAL} )
|
if ( ReadingsVal( $name, "residentsTotalPresentDevs", "" ) ne
|
||||||
|| $hash->{READINGS}{residentsTotalPresentDevs}{VAL} ne
|
|
||||||
$residentsDevs_totalPresent );
|
$residentsDevs_totalPresent );
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "residentsTotalPresentNames",
|
readingsBulkUpdate( $hash, "residentsTotalPresentNames",
|
||||||
$residents_totalPresent )
|
$residents_totalPresent )
|
||||||
if ( !defined( $hash->{READINGS}{residentsTotalPresentNames}{VAL} )
|
if ( ReadingsVal( $name, "residentsTotalPresentNames", "" ) ne
|
||||||
|| $hash->{READINGS}{residentsTotalPresentNames}{VAL} ne
|
|
||||||
$residents_totalPresent );
|
$residents_totalPresent );
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "residentsTotalAbsent", $state_totalAbsent )
|
readingsBulkUpdate( $hash, "residentsTotalAbsent", $state_totalAbsent )
|
||||||
if ( !defined( $hash->{READINGS}{residentsTotalAbsent}{VAL} )
|
if ( ReadingsVal( $name, "residentsTotalAbsent", "" ) ne
|
||||||
|| $hash->{READINGS}{residentsTotalAbsent}{VAL} ne $state_totalAbsent );
|
$state_totalAbsent );
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "residentsTotalAbsentDevs",
|
readingsBulkUpdate( $hash, "residentsTotalAbsentDevs",
|
||||||
$residentsDevs_totalAbsent )
|
$residentsDevs_totalAbsent )
|
||||||
if ( !defined( $hash->{READINGS}{residentsTotalAbsentDevs}{VAL} )
|
if ( ReadingsVal( $name, "residentsTotalAbsentDevs", "" ) ne
|
||||||
|| $hash->{READINGS}{residentsTotalAbsentDevs}{VAL} ne
|
|
||||||
$residentsDevs_totalAbsent );
|
$residentsDevs_totalAbsent );
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "residentsTotalAbsentNames",
|
readingsBulkUpdate( $hash, "residentsTotalAbsentNames",
|
||||||
$residents_totalAbsent )
|
$residents_totalAbsent )
|
||||||
if ( !defined( $hash->{READINGS}{residentsTotalAbsentNames}{VAL} )
|
if ( ReadingsVal( $name, "residentsTotalAbsentNames", "" ) ne
|
||||||
|| $hash->{READINGS}{residentsTotalAbsentNames}{VAL} ne
|
|
||||||
$residents_totalAbsent );
|
$residents_totalAbsent );
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "residentsHome", $state_home )
|
readingsBulkUpdate( $hash, "residentsHome", $state_home )
|
||||||
if ( !defined( $hash->{READINGS}{residentsHome}{VAL} )
|
if ( ReadingsVal( $name, "residentsHome", "" ) ne $state_home );
|
||||||
|| $hash->{READINGS}{residentsHome}{VAL} ne $state_home );
|
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "residentsHomeDevs", $residentsDevs_home )
|
readingsBulkUpdate( $hash, "residentsHomeDevs", $residentsDevs_home )
|
||||||
if ( !defined( $hash->{READINGS}{residentsHomeDevs}{VAL} )
|
if (
|
||||||
|| $hash->{READINGS}{residentsHomeDevs}{VAL} ne $residentsDevs_home );
|
ReadingsVal( $name, "residentsHomeDevs", "" ) ne $residentsDevs_home );
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "residentsHomeNames", $residents_home )
|
readingsBulkUpdate( $hash, "residentsHomeNames", $residents_home )
|
||||||
if ( !defined( $hash->{READINGS}{residentsHomeNames}{VAL} )
|
if ( ReadingsVal( $name, "residentsHomeNames", "" ) ne $residents_home );
|
||||||
|| $hash->{READINGS}{residentsHomeNames}{VAL} ne $residents_home );
|
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "residentsGotosleep", $state_gotosleep )
|
readingsBulkUpdate( $hash, "residentsGotosleep", $state_gotosleep )
|
||||||
if ( !defined( $hash->{READINGS}{residentsGotosleep}{VAL} )
|
if ( ReadingsVal( $name, "residentsGotosleep", "" ) ne $state_gotosleep );
|
||||||
|| $hash->{READINGS}{residentsGotosleep}{VAL} ne $state_gotosleep );
|
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "residentsGotosleepDevs",
|
readingsBulkUpdate( $hash, "residentsGotosleepDevs",
|
||||||
$residentsDevs_gotosleep )
|
$residentsDevs_gotosleep )
|
||||||
if ( !defined( $hash->{READINGS}{residentsGotosleepDevs}{VAL} )
|
if ( ReadingsVal( $name, "residentsGotosleepDevs", "" ) ne
|
||||||
|| $hash->{READINGS}{residentsGotosleepDevs}{VAL} ne
|
|
||||||
$residentsDevs_gotosleep );
|
$residentsDevs_gotosleep );
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "residentsGotosleepNames", $residents_gotosleep )
|
readingsBulkUpdate( $hash, "residentsGotosleepNames", $residents_gotosleep )
|
||||||
if ( !defined( $hash->{READINGS}{residentsGotosleepNames}{VAL} )
|
if ( ReadingsVal( $name, "residentsGotosleepNames", "" ) ne
|
||||||
|| $hash->{READINGS}{residentsGotosleepNames}{VAL} ne
|
|
||||||
$residents_gotosleep );
|
$residents_gotosleep );
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "residentsAsleep", $state_asleep )
|
readingsBulkUpdate( $hash, "residentsAsleep", $state_asleep )
|
||||||
if ( !defined( $hash->{READINGS}{residentsAsleep}{VAL} )
|
if ( ReadingsVal( $name, "residentsAsleep", "" ) ne $state_asleep );
|
||||||
|| $hash->{READINGS}{residentsAsleep}{VAL} ne $state_asleep );
|
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "residentsAsleepDevs", $residentsDevs_asleep )
|
readingsBulkUpdate( $hash, "residentsAsleepDevs", $residentsDevs_asleep )
|
||||||
if ( !defined( $hash->{READINGS}{residentsAsleepDevs}{VAL} )
|
if ( ReadingsVal( $name, "residentsAsleepDevs", "" ) ne
|
||||||
|| $hash->{READINGS}{residentsAsleepDevs}{VAL} ne
|
|
||||||
$residentsDevs_asleep );
|
$residentsDevs_asleep );
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "residentsAsleepNames", $residents_asleep )
|
readingsBulkUpdate( $hash, "residentsAsleepNames", $residents_asleep )
|
||||||
if ( !defined( $hash->{READINGS}{residentsAsleepNames}{VAL} )
|
if (
|
||||||
|| $hash->{READINGS}{residentsAsleepNames}{VAL} ne $residents_asleep );
|
ReadingsVal( $name, "residentsAsleepNames", "" ) ne $residents_asleep );
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "residentsAwoken", $state_awoken )
|
readingsBulkUpdate( $hash, "residentsAwoken", $state_awoken )
|
||||||
if ( !defined( $hash->{READINGS}{residentsAwoken}{VAL} )
|
if ( ReadingsVal( $name, "residentsAwoken", "" ) ne $state_awoken );
|
||||||
|| $hash->{READINGS}{residentsAwoken}{VAL} ne $state_awoken );
|
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "residentsAwokenDevs", $residentsDevs_awoken )
|
readingsBulkUpdate( $hash, "residentsAwokenDevs", $residentsDevs_awoken )
|
||||||
if ( !defined( $hash->{READINGS}{residentsAwokenDevs}{VAL} )
|
if ( ReadingsVal( $name, "residentsAwokenDevs", "" ) ne
|
||||||
|| $hash->{READINGS}{residentsAwokenDevs}{VAL} ne
|
|
||||||
$residentsDevs_awoken );
|
$residentsDevs_awoken );
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "residentsAwokenNames", $residents_awoken )
|
readingsBulkUpdate( $hash, "residentsAwokenNames", $residents_awoken )
|
||||||
if ( !defined( $hash->{READINGS}{residentsAwokenNames}{VAL} )
|
if (
|
||||||
|| $hash->{READINGS}{residentsAwokenNames}{VAL} ne $residents_awoken );
|
ReadingsVal( $name, "residentsAwokenNames", "" ) ne $residents_awoken );
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "residentsAbsent", $state_absent )
|
readingsBulkUpdate( $hash, "residentsAbsent", $state_absent )
|
||||||
if ( !defined( $hash->{READINGS}{residentsAbsent}{VAL} )
|
if ( ReadingsVal( $name, "residentsAbsent", "" ) ne $state_absent );
|
||||||
|| $hash->{READINGS}{residentsAbsent}{VAL} ne $state_absent );
|
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "residentsAbsentDevs", $residentsDevs_absent )
|
readingsBulkUpdate( $hash, "residentsAbsentDevs", $residentsDevs_absent )
|
||||||
if ( !defined( $hash->{READINGS}{residentsAbsentDevs}{VAL} )
|
if ( ReadingsVal( $name, "residentsAbsentDevs", "" ) ne
|
||||||
|| $hash->{READINGS}{residentsAbsentDevs}{VAL} ne
|
|
||||||
$residentsDevs_absent );
|
$residentsDevs_absent );
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "residentsAbsentNames", $residents_absent )
|
readingsBulkUpdate( $hash, "residentsAbsentNames", $residents_absent )
|
||||||
if ( !defined( $hash->{READINGS}{residentsAbsentNames}{VAL} )
|
if (
|
||||||
|| $hash->{READINGS}{residentsAbsentNames}{VAL} ne $residents_absent );
|
ReadingsVal( $name, "residentsAbsentNames", "" ) ne $residents_absent );
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "residentsGone", $state_gone )
|
readingsBulkUpdate( $hash, "residentsGone", $state_gone )
|
||||||
if ( !defined( $hash->{READINGS}{residentsGone}{VAL} )
|
if ( ReadingsVal( $name, "residentsGone", "" ) ne $state_gone );
|
||||||
|| $hash->{READINGS}{residentsGone}{VAL} ne $state_gone );
|
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "residentsGoneDevs", $residentsDevs_gone )
|
readingsBulkUpdate( $hash, "residentsGoneDevs", $residentsDevs_gone )
|
||||||
if ( !defined( $hash->{READINGS}{residentsGoneDevs}{VAL} )
|
if (
|
||||||
|| $hash->{READINGS}{residentsGoneDevs}{VAL} ne $residentsDevs_gone );
|
ReadingsVal( $name, "residentsGoneDevs", "" ) ne $residentsDevs_gone );
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "residentsGoneNames", $residents_gone )
|
readingsBulkUpdate( $hash, "residentsGoneNames", $residents_gone )
|
||||||
if ( !defined( $hash->{READINGS}{residentsGoneNames}{VAL} )
|
if ( ReadingsVal( $name, "residentsGoneNames", "" ) ne $residents_gone );
|
||||||
|| $hash->{READINGS}{residentsGoneNames}{VAL} ne $residents_gone );
|
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "residentsTotalWakeup", $wakeup )
|
readingsBulkUpdate( $hash, "residentsTotalWakeup", $wakeup )
|
||||||
if ( !defined( $hash->{READINGS}{residentsTotalWakeup}{VAL} )
|
if ( ReadingsVal( $name, "residentsTotalWakeup", "" ) ne $wakeup );
|
||||||
|| $hash->{READINGS}{residentsTotalWakeup}{VAL} ne $wakeup );
|
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "residentsTotalWakeupDevs",
|
readingsBulkUpdate( $hash, "residentsTotalWakeupDevs",
|
||||||
$residentsDevs_wakeup )
|
$residentsDevs_wakeup )
|
||||||
if ( !defined( $hash->{READINGS}{residentsTotalWakeupDevs}{VAL} )
|
if ( ReadingsVal( $name, "residentsTotalWakeupDevs", "" ) ne
|
||||||
|| $hash->{READINGS}{residentsTotalWakeupDevs}{VAL} ne
|
|
||||||
$residentsDevs_wakeup );
|
$residentsDevs_wakeup );
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "residentsTotalWakeupNames", $residents_wakeup )
|
readingsBulkUpdate( $hash, "residentsTotalWakeupNames", $residents_wakeup )
|
||||||
if ( !defined( $hash->{READINGS}{residentsTotalWakeupNames}{VAL} )
|
if ( ReadingsVal( $name, "residentsTotalWakeupNames", "" ) ne
|
||||||
|| $hash->{READINGS}{residentsTotalWakeupNames}{VAL} ne
|
|
||||||
$residents_wakeup );
|
$residents_wakeup );
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "residentsTotalWayhome", $wayhome )
|
readingsBulkUpdate( $hash, "residentsTotalWayhome", $wayhome )
|
||||||
if ( !defined( $hash->{READINGS}{residentsTotalWayhome}{VAL} )
|
if ( ReadingsVal( $name, "residentsTotalWayhome", "" ) ne $wayhome );
|
||||||
|| $hash->{READINGS}{residentsTotalWayhome}{VAL} ne $wayhome );
|
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "residentsTotalWayhomeDevs",
|
readingsBulkUpdate( $hash, "residentsTotalWayhomeDevs",
|
||||||
$residentsDevs_wayhome )
|
$residentsDevs_wayhome )
|
||||||
if ( !defined( $hash->{READINGS}{residentsTotalWayhomeDevs}{VAL} )
|
if ( ReadingsVal( $name, "residentsTotalWayhomeDevs", "" ) ne
|
||||||
|| $hash->{READINGS}{residentsTotalWayhomeDevs}{VAL} ne
|
|
||||||
$residentsDevs_wayhome );
|
$residentsDevs_wayhome );
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "residentsTotalWayhomeNames",
|
readingsBulkUpdate( $hash, "residentsTotalWayhomeNames",
|
||||||
$residents_wayhome )
|
$residents_wayhome )
|
||||||
if ( !defined( $hash->{READINGS}{residentsTotalWayhomeNames}{VAL} )
|
if ( ReadingsVal( $name, "residentsTotalWayhomeNames", "" ) ne
|
||||||
|| $hash->{READINGS}{residentsTotalWayhomeNames}{VAL} ne
|
|
||||||
$residents_wayhome );
|
$residents_wayhome );
|
||||||
|
|
||||||
#
|
#
|
||||||
@@ -1499,27 +1458,28 @@ sub RESIDENTS_UpdateReadings (@) {
|
|||||||
if ( $newstate eq "asleep" );
|
if ( $newstate eq "asleep" );
|
||||||
|
|
||||||
# if prior state was asleep, update sleep statistics
|
# if prior state was asleep, update sleep statistics
|
||||||
if ( defined( $hash->{READINGS}{state}{VAL} )
|
if ( $state eq "asleep"
|
||||||
&& $state eq "asleep" )
|
&& ReadingsVal( $name, "lastSleep", "" ) ne "" )
|
||||||
{
|
{
|
||||||
readingsBulkUpdate( $hash, "lastAwake", $datetime );
|
readingsBulkUpdate( $hash, "lastAwake", $datetime );
|
||||||
readingsBulkUpdate(
|
readingsBulkUpdate(
|
||||||
$hash,
|
$hash,
|
||||||
"lastDurSleep",
|
"lastDurSleep",
|
||||||
RESIDENTStk_TimeDiff(
|
RESIDENTStk_TimeDiff(
|
||||||
$datetime, $hash->{READINGS}{lastSleep}{VAL}
|
$datetime, ReadingsVal( $name, "lastSleep", "" )
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
readingsBulkUpdate(
|
readingsBulkUpdate(
|
||||||
$hash,
|
$hash,
|
||||||
"lastDurSleep_cr",
|
"lastDurSleep_cr",
|
||||||
RESIDENTStk_TimeDiff(
|
RESIDENTStk_TimeDiff(
|
||||||
$datetime, $hash->{READINGS}{lastSleep}{VAL}, "min"
|
$datetime, ReadingsVal( $name, "lastSleep", "" ), "min"
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "lastState", $hash->{READINGS}{state}{VAL} );
|
readingsBulkUpdate( $hash, "lastState",
|
||||||
|
ReadingsVal( $name, "state", "initialized" ) );
|
||||||
readingsBulkUpdate( $hash, "state", $newstate );
|
readingsBulkUpdate( $hash, "state", $newstate );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1532,21 +1492,19 @@ sub RESIDENTS_UpdateReadings (@) {
|
|||||||
readingsBulkUpdate( $hash, "lastArrival", $datetime );
|
readingsBulkUpdate( $hash, "lastArrival", $datetime );
|
||||||
|
|
||||||
# absence duration
|
# absence duration
|
||||||
if ( defined( $hash->{READINGS}{lastDeparture}{VAL} )
|
if ( ReadingsVal( $name, "lastDeparture", "-" ) ne "-" ) {
|
||||||
&& $hash->{READINGS}{lastDeparture}{VAL} ne "-" )
|
|
||||||
{
|
|
||||||
readingsBulkUpdate(
|
readingsBulkUpdate(
|
||||||
$hash,
|
$hash,
|
||||||
"lastDurAbsence",
|
"lastDurAbsence",
|
||||||
RESIDENTStk_TimeDiff(
|
RESIDENTStk_TimeDiff(
|
||||||
$datetime, $hash->{READINGS}{lastDeparture}{VAL}
|
$datetime, ReadingsVal( $name, "lastDeparture", "-" )
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
readingsBulkUpdate(
|
readingsBulkUpdate(
|
||||||
$hash,
|
$hash,
|
||||||
"lastDurAbsence_cr",
|
"lastDurAbsence_cr",
|
||||||
RESIDENTStk_TimeDiff(
|
RESIDENTStk_TimeDiff(
|
||||||
$datetime, $hash->{READINGS}{lastDeparture}{VAL},
|
$datetime, ReadingsVal( $name, "lastDeparture", "-" ),
|
||||||
"min"
|
"min"
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@@ -1556,21 +1514,19 @@ sub RESIDENTS_UpdateReadings (@) {
|
|||||||
readingsBulkUpdate( $hash, "lastDeparture", $datetime );
|
readingsBulkUpdate( $hash, "lastDeparture", $datetime );
|
||||||
|
|
||||||
# presence duration
|
# presence duration
|
||||||
if ( defined( $hash->{READINGS}{lastArrival}{VAL} )
|
if ( ReadingsVal( $name, "lastArrival", "-" ) ne "-" ) {
|
||||||
&& $hash->{READINGS}{lastArrival}{VAL} ne "-" )
|
|
||||||
{
|
|
||||||
readingsBulkUpdate(
|
readingsBulkUpdate(
|
||||||
$hash,
|
$hash,
|
||||||
"lastDurPresence",
|
"lastDurPresence",
|
||||||
RESIDENTStk_TimeDiff(
|
RESIDENTStk_TimeDiff(
|
||||||
$datetime, $hash->{READINGS}{lastArrival}{VAL}
|
$datetime, ReadingsVal( $name, "lastArrival", "-" )
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
readingsBulkUpdate(
|
readingsBulkUpdate(
|
||||||
$hash,
|
$hash,
|
||||||
"lastDurPresence_cr",
|
"lastDurPresence_cr",
|
||||||
RESIDENTStk_TimeDiff(
|
RESIDENTStk_TimeDiff(
|
||||||
$datetime, $hash->{READINGS}{lastArrival}{VAL},
|
$datetime, ReadingsVal( $name, "lastArrival", "-" ),
|
||||||
"min"
|
"min"
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ sub GUEST_Define($$) {
|
|||||||
|
|
||||||
# trigger for modified objects
|
# trigger for modified objects
|
||||||
unless ( $modified == 0 ) {
|
unless ( $modified == 0 ) {
|
||||||
readingsBulkUpdate( $hash, "state", $hash->{READINGS}{state}{VAL} );
|
readingsBulkUpdate( $hash, "state", ReadingsVal( $name, "state", "" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
readingsEndUpdate( $hash, 1 );
|
readingsEndUpdate( $hash, 1 );
|
||||||
@@ -257,22 +257,10 @@ sub GUEST_Notify($$) {
|
|||||||
sub GUEST_Set($@) {
|
sub GUEST_Set($@) {
|
||||||
my ( $hash, @a ) = @_;
|
my ( $hash, @a ) = @_;
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
my $state =
|
my $state = ReadingsVal( $name, "state", "initialized" );
|
||||||
( defined( $hash->{READINGS}{state}{VAL} ) )
|
my $presence = ReadingsVal( $name, "presence", "undefined" );
|
||||||
? $hash->{READINGS}{state}{VAL}
|
my $mood = ReadingsVal( $name, "mood", "-" );
|
||||||
: "initialized";
|
my $location = ReadingsVal( $name, "location", "undefined" );
|
||||||
my $presence =
|
|
||||||
( defined( $hash->{READINGS}{presence}{VAL} ) )
|
|
||||||
? $hash->{READINGS}{presence}{VAL}
|
|
||||||
: "undefined";
|
|
||||||
my $mood =
|
|
||||||
( defined( $hash->{READINGS}{mood}{VAL} ) )
|
|
||||||
? $hash->{READINGS}{mood}{VAL}
|
|
||||||
: "-";
|
|
||||||
my $location =
|
|
||||||
( defined( $hash->{READINGS}{location}{VAL} ) )
|
|
||||||
? $hash->{READINGS}{location}{VAL}
|
|
||||||
: "undefined";
|
|
||||||
my $silent = 0;
|
my $silent = 0;
|
||||||
|
|
||||||
Log3 $name, 5, "GUEST $name: called function GUEST_Set()";
|
Log3 $name, 5, "GUEST $name: called function GUEST_Set()";
|
||||||
@@ -441,21 +429,22 @@ sub GUEST_Set($@) {
|
|||||||
|
|
||||||
# if prior state was asleep, update sleep statistics
|
# if prior state was asleep, update sleep statistics
|
||||||
if ( $state eq "asleep"
|
if ( $state eq "asleep"
|
||||||
&& defined( $hash->{READINGS}{lastSleep}{VAL} ) )
|
&& ReadingsVal( $name, "lastSleep", "" ) ne "" )
|
||||||
{
|
{
|
||||||
readingsBulkUpdate( $hash, "lastAwake", $datetime );
|
readingsBulkUpdate( $hash, "lastAwake", $datetime );
|
||||||
readingsBulkUpdate(
|
readingsBulkUpdate(
|
||||||
$hash,
|
$hash,
|
||||||
"lastDurSleep",
|
"lastDurSleep",
|
||||||
RESIDENTStk_TimeDiff(
|
RESIDENTStk_TimeDiff(
|
||||||
$datetime, $hash->{READINGS}{lastSleep}{VAL}
|
$datetime, ReadingsVal( $name, "lastSleep", "" )
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
readingsBulkUpdate(
|
readingsBulkUpdate(
|
||||||
$hash,
|
$hash,
|
||||||
"lastDurSleep_cr",
|
"lastDurSleep_cr",
|
||||||
RESIDENTStk_TimeDiff(
|
RESIDENTStk_TimeDiff(
|
||||||
$datetime, $hash->{READINGS}{lastSleep}{VAL}, "min"
|
$datetime, ReadingsVal( $name, "lastSleep", "" ),
|
||||||
|
"min"
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -517,7 +506,8 @@ sub GUEST_Set($@) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if ( !grep( m/^$searchstring$/, @location_underway )
|
if ( !$silent
|
||||||
|
&& !grep( m/^$searchstring$/, @location_underway )
|
||||||
&& $location ne $location_underway[0] )
|
&& $location ne $location_underway[0] )
|
||||||
{
|
{
|
||||||
Log3 $name, 4,
|
Log3 $name, 4,
|
||||||
@@ -529,9 +519,7 @@ sub GUEST_Set($@) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# reset wayhome
|
# reset wayhome
|
||||||
if ( !defined( $hash->{READINGS}{wayhome}{VAL} )
|
if ( ReadingsVal( $name, "wayhome", 1 ) > 0 ) {
|
||||||
|| $hash->{READINGS}{wayhome}{VAL} ne "0" )
|
|
||||||
{
|
|
||||||
readingsBulkUpdate( $hash, "wayhome", "0" );
|
readingsBulkUpdate( $hash, "wayhome", "0" );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -540,14 +528,13 @@ sub GUEST_Set($@) {
|
|||||||
readingsBulkUpdate( $hash, "lastArrival", $datetime );
|
readingsBulkUpdate( $hash, "lastArrival", $datetime );
|
||||||
|
|
||||||
# absence duration
|
# absence duration
|
||||||
if ( defined( $hash->{READINGS}{lastDeparture}{VAL} )
|
if ( ReadingsVal( $name, "lastDeparture", "-" ) ne "-" ) {
|
||||||
&& $hash->{READINGS}{lastDeparture}{VAL} ne "-" )
|
|
||||||
{
|
|
||||||
readingsBulkUpdate(
|
readingsBulkUpdate(
|
||||||
$hash,
|
$hash,
|
||||||
"lastDurAbsence",
|
"lastDurAbsence",
|
||||||
RESIDENTStk_TimeDiff(
|
RESIDENTStk_TimeDiff(
|
||||||
$datetime, $hash->{READINGS}{lastDeparture}{VAL}
|
$datetime,
|
||||||
|
ReadingsVal( $name, "lastDeparture", "-" )
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
readingsBulkUpdate(
|
readingsBulkUpdate(
|
||||||
@@ -555,7 +542,8 @@ sub GUEST_Set($@) {
|
|||||||
"lastDurAbsence_cr",
|
"lastDurAbsence_cr",
|
||||||
RESIDENTStk_TimeDiff(
|
RESIDENTStk_TimeDiff(
|
||||||
$datetime,
|
$datetime,
|
||||||
$hash->{READINGS}{lastDeparture}{VAL}, "min"
|
ReadingsVal( $name, "lastDeparture", "-" ),
|
||||||
|
"min"
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -564,22 +552,21 @@ sub GUEST_Set($@) {
|
|||||||
readingsBulkUpdate( $hash, "lastDeparture", $datetime );
|
readingsBulkUpdate( $hash, "lastDeparture", $datetime );
|
||||||
|
|
||||||
# presence duration
|
# presence duration
|
||||||
if ( defined( $hash->{READINGS}{lastArrival}{VAL} )
|
if ( ReadingsVal( $name, "lastArrival", "-" ) ne "-" ) {
|
||||||
&& $hash->{READINGS}{lastArrival}{VAL} ne "-" )
|
|
||||||
{
|
|
||||||
readingsBulkUpdate(
|
readingsBulkUpdate(
|
||||||
$hash,
|
$hash,
|
||||||
"lastDurPresence",
|
"lastDurPresence",
|
||||||
RESIDENTStk_TimeDiff(
|
RESIDENTStk_TimeDiff(
|
||||||
$datetime, $hash->{READINGS}{lastArrival}{VAL}
|
$datetime,
|
||||||
|
ReadingsVal( $name, "lastArrival", "-" )
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
readingsBulkUpdate(
|
readingsBulkUpdate(
|
||||||
$hash,
|
$hash,
|
||||||
"lastDurPresence_cr",
|
"lastDurPresence_cr",
|
||||||
RESIDENTStk_TimeDiff(
|
RESIDENTStk_TimeDiff(
|
||||||
$datetime, $hash->{READINGS}{lastArrival}{VAL},
|
$datetime,
|
||||||
"min"
|
ReadingsVal( $name, "lastArrival", "-" ), "min"
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -599,9 +586,8 @@ sub GUEST_Set($@) {
|
|||||||
&& defined( $defs{$object}{TYPE} )
|
&& defined( $defs{$object}{TYPE} )
|
||||||
&& ( $defs{$object}{TYPE} eq "ROOMMATE"
|
&& ( $defs{$object}{TYPE} eq "ROOMMATE"
|
||||||
|| $defs{$object}{TYPE} eq "GUEST" )
|
|| $defs{$object}{TYPE} eq "GUEST" )
|
||||||
&& defined( $defs{$object}{READINGS}{state}{VAL} )
|
&& ReadingsVal( $object, "state", "" ) ne "gone"
|
||||||
&& $defs{$object}{READINGS}{state}{VAL} ne "gone"
|
&& ReadingsVal( $object, "state", "" ) ne "none"
|
||||||
&& $defs{$object}{READINGS}{state}{VAL} ne "none"
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
fhem("set $object $newstate");
|
fhem("set $object $newstate");
|
||||||
@@ -613,23 +599,23 @@ sub GUEST_Set($@) {
|
|||||||
# clear readings if guest is gone
|
# clear readings if guest is gone
|
||||||
if ( $newstate eq "none" ) {
|
if ( $newstate eq "none" ) {
|
||||||
readingsBulkUpdate( $hash, "lastArrival", "-" )
|
readingsBulkUpdate( $hash, "lastArrival", "-" )
|
||||||
if ( defined( $hash->{READINGS}{lastArrival}{VAL} ) );
|
if ( ReadingsVal( $name, "lastArrival", "-" ) ne "-" );
|
||||||
readingsBulkUpdate( $hash, "lastAwake", "-" )
|
readingsBulkUpdate( $hash, "lastAwake", "-" )
|
||||||
if ( defined( $hash->{READINGS}{lastAwake}{VAL} ) );
|
if ( ReadingsVal( $name, "lastAwake", "-" ) ne "-" );
|
||||||
readingsBulkUpdate( $hash, "lastDurAbsence", "-" )
|
readingsBulkUpdate( $hash, "lastDurAbsence", "-" )
|
||||||
if ( defined( $hash->{READINGS}{lastDurAbsence}{VAL} ) );
|
if ( ReadingsVal( $name, "lastDurAbsence", "-" ) ne "-" );
|
||||||
readingsBulkUpdate( $hash, "lastDurSleep", "-" )
|
readingsBulkUpdate( $hash, "lastDurSleep", "-" )
|
||||||
if ( defined( $hash->{READINGS}{lastDurSleep}{VAL} ) );
|
if ( ReadingsVal( $name, "lastDurSleep", "-" ) ne "-" );
|
||||||
readingsBulkUpdate( $hash, "lastLocation", "-" )
|
readingsBulkUpdate( $hash, "lastLocation", "-" )
|
||||||
if ( defined( $hash->{READINGS}{lastLocation}{VAL} ) );
|
if ( ReadingsVal( $name, "lastLocation", "-" ) ne "-" );
|
||||||
readingsBulkUpdate( $hash, "lastSleep", "-" )
|
readingsBulkUpdate( $hash, "lastSleep", "-" )
|
||||||
if ( defined( $hash->{READINGS}{lastSleep}{VAL} ) );
|
if ( ReadingsVal( $name, "lastSleep", "-" ) ne "-" );
|
||||||
readingsBulkUpdate( $hash, "lastMood", "-" )
|
readingsBulkUpdate( $hash, "lastMood", "-" )
|
||||||
if ( defined( $hash->{READINGS}{lastMood}{VAL} ) );
|
if ( ReadingsVal( $name, "lastMood", "-" ) ne "-" );
|
||||||
readingsBulkUpdate( $hash, "location", "-" )
|
readingsBulkUpdate( $hash, "location", "-" )
|
||||||
if ( defined( $hash->{READINGS}{location}{VAL} ) );
|
if ( ReadingsVal( $name, "location", "-" ) ne "-" );
|
||||||
readingsBulkUpdate( $hash, "mood", "-" )
|
readingsBulkUpdate( $hash, "mood", "-" )
|
||||||
if ( defined( $hash->{READINGS}{mood}{VAL} ) );
|
if ( ReadingsVal( $name, "mood", "-" ) ne "-" );
|
||||||
}
|
}
|
||||||
|
|
||||||
# calculate duration timers
|
# calculate duration timers
|
||||||
@@ -653,13 +639,13 @@ sub GUEST_Set($@) {
|
|||||||
Log3 $name, 2, "GUEST set $name mood " . $a[2] if ( !$silent );
|
Log3 $name, 2, "GUEST set $name mood " . $a[2] if ( !$silent );
|
||||||
readingsBeginUpdate($hash) if ( !$silent );
|
readingsBeginUpdate($hash) if ( !$silent );
|
||||||
|
|
||||||
if ( $a[2] eq "toggle" ) {
|
if ( $a[2] eq "toggle"
|
||||||
if ( defined( $hash->{READINGS}{lastMood}{VAL} ) ) {
|
&& ReadingsVal( $name, "lastMood", "" ) ne "" )
|
||||||
|
{
|
||||||
readingsBulkUpdate( $hash, "mood",
|
readingsBulkUpdate( $hash, "mood",
|
||||||
$hash->{READINGS}{lastMood}{VAL} );
|
ReadingsVal( $name, "lastMood", "" ) );
|
||||||
readingsBulkUpdate( $hash, "lastMood", $mood );
|
readingsBulkUpdate( $hash, "lastMood", $mood );
|
||||||
}
|
}
|
||||||
}
|
|
||||||
elsif ( $mood ne $a[2] ) {
|
elsif ( $mood ne $a[2] ) {
|
||||||
readingsBulkUpdate( $hash, "lastMood", $mood )
|
readingsBulkUpdate( $hash, "lastMood", $mood )
|
||||||
if ( $mood ne "-" );
|
if ( $mood ne "-" );
|
||||||
@@ -676,13 +662,91 @@ sub GUEST_Set($@) {
|
|||||||
# location
|
# location
|
||||||
elsif ( $a[1] eq "location" ) {
|
elsif ( $a[1] eq "location" ) {
|
||||||
if ( defined( $a[2] ) && $a[2] ne "" ) {
|
if ( defined( $a[2] ) && $a[2] ne "" ) {
|
||||||
shift @a;
|
Log3 $name, 2, "GUEST set $name location " . $a[2] if ( !$silent );
|
||||||
shift @a;
|
|
||||||
my $location = join( " ", @a );
|
|
||||||
Log3 $name, 2, "ROOMMATE set $name location " . $location
|
|
||||||
if ( !$silent );
|
|
||||||
|
|
||||||
GUEST_SetLocation( $name, $location, 1, undef );
|
if ( $location ne $a[2] ) {
|
||||||
|
my $searchstring;
|
||||||
|
|
||||||
|
readingsBeginUpdate($hash) if ( !$silent );
|
||||||
|
|
||||||
|
# read attributes
|
||||||
|
my @location_home =
|
||||||
|
( defined( $attr{$name}{"rg_locationHome"} ) )
|
||||||
|
? split( ' ', $attr{$name}{"rg_locationHome"} )
|
||||||
|
: ("home");
|
||||||
|
|
||||||
|
my @location_underway =
|
||||||
|
( defined( $attr{$name}{"rg_locationUnderway"} ) )
|
||||||
|
? split( ' ', $attr{$name}{"rg_locationUnderway"} )
|
||||||
|
: ("underway");
|
||||||
|
|
||||||
|
my @location_wayhome =
|
||||||
|
( defined( $attr{$name}{"rg_locationWayhome"} ) )
|
||||||
|
? split( ' ', $attr{$name}{"rg_locationWayhome"} )
|
||||||
|
: ("wayhome");
|
||||||
|
|
||||||
|
$searchstring = quotemeta($location);
|
||||||
|
readingsBulkUpdate( $hash, "lastLocation", $location )
|
||||||
|
if ( $location ne "wayhome"
|
||||||
|
&& !grep( m/^$searchstring$/, @location_underway ) );
|
||||||
|
readingsBulkUpdate( $hash, "location", $a[2] )
|
||||||
|
if ( $a[2] ne "wayhome" );
|
||||||
|
|
||||||
|
# wayhome detection
|
||||||
|
$searchstring = quotemeta($location);
|
||||||
|
if (
|
||||||
|
(
|
||||||
|
$a[2] eq "wayhome"
|
||||||
|
|| grep( m/^$searchstring$/, @location_wayhome )
|
||||||
|
)
|
||||||
|
&& ( $presence eq "absent" )
|
||||||
|
)
|
||||||
|
{
|
||||||
|
Log3 $name, 3,
|
||||||
|
"GUEST $name: on way back home from $location";
|
||||||
|
readingsBulkUpdate( $hash, "wayhome", "1" )
|
||||||
|
if ( !defined( $hash->{READINGS}{wayhome}{VAL} )
|
||||||
|
|| $hash->{READINGS}{wayhome}{VAL} ne "1" );
|
||||||
|
}
|
||||||
|
|
||||||
|
readingsEndUpdate( $hash, 1 ) if ( !$silent );
|
||||||
|
|
||||||
|
# auto-updates
|
||||||
|
$searchstring = quotemeta( $a[2] );
|
||||||
|
if (
|
||||||
|
(
|
||||||
|
$a[2] eq "home"
|
||||||
|
|| grep( m/^$searchstring$/, @location_home )
|
||||||
|
)
|
||||||
|
&& $state ne "home"
|
||||||
|
&& $state ne "gotosleep"
|
||||||
|
&& $state ne "asleep"
|
||||||
|
&& $state ne "awoken"
|
||||||
|
&& $state ne "initialized"
|
||||||
|
)
|
||||||
|
{
|
||||||
|
Log3 $name, 4,
|
||||||
|
"GUEST $name: implicit state change caused by location "
|
||||||
|
. $a[2];
|
||||||
|
GUEST_Set( $hash, $name, "silentSet", "state", "home" );
|
||||||
|
}
|
||||||
|
elsif (
|
||||||
|
(
|
||||||
|
$a[2] eq "underway"
|
||||||
|
|| grep( m/^$searchstring$/, @location_underway )
|
||||||
|
)
|
||||||
|
&& $state ne "gone"
|
||||||
|
&& $state ne "none"
|
||||||
|
&& $state ne "absent"
|
||||||
|
&& $state ne "initialized"
|
||||||
|
)
|
||||||
|
{
|
||||||
|
Log3 $name, 4,
|
||||||
|
"GUEST $name: implicit state change caused by location "
|
||||||
|
. $a[2];
|
||||||
|
GUEST_Set( $hash, $name, "silentSet", "state", "absent" );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return "Invalid 2nd argument, choose one of location ";
|
return "Invalid 2nd argument, choose one of location ";
|
||||||
@@ -774,9 +838,7 @@ sub GUEST_AutoGone($;$) {
|
|||||||
|
|
||||||
RESIDENTStk_RemoveInternalTimer( "AutoGone", $hash );
|
RESIDENTStk_RemoveInternalTimer( "AutoGone", $hash );
|
||||||
|
|
||||||
if ( defined( $hash->{READINGS}{state}{VAL} )
|
if ( ReadingsVal( $name, "state", "home" ) eq "absent" ) {
|
||||||
&& $hash->{READINGS}{state}{VAL} eq "absent" )
|
|
||||||
{
|
|
||||||
my ( $date, $time, $y, $m, $d, $hour, $min, $sec, $timestamp,
|
my ( $date, $time, $y, $m, $d, $hour, $min, $sec, $timestamp,
|
||||||
$timeDiff );
|
$timeDiff );
|
||||||
my $timestampNow = gettimeofday();
|
my $timestampNow = gettimeofday();
|
||||||
@@ -814,10 +876,7 @@ sub GUEST_DurationTimer($;$) {
|
|||||||
my ( $mHash, @a ) = @_;
|
my ( $mHash, @a ) = @_;
|
||||||
my $hash = ( $mHash->{HASH} ) ? $mHash->{HASH} : $mHash;
|
my $hash = ( $mHash->{HASH} ) ? $mHash->{HASH} : $mHash;
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
my $state =
|
my $state = ReadingsVal( $name, "state", "initialized" );
|
||||||
( $hash->{READINGS}{state}{VAL} )
|
|
||||||
? $hash->{READINGS}{state}{VAL}
|
|
||||||
: "initialized";
|
|
||||||
my $silent = ( defined( $a[0] ) && $a[0] eq "1" ) ? 1 : 0;
|
my $silent = ( defined( $a[0] ) && $a[0] eq "1" ) ? 1 : 0;
|
||||||
my $timestampNow = gettimeofday();
|
my $timestampNow = gettimeofday();
|
||||||
my $diff;
|
my $diff;
|
||||||
@@ -832,47 +891,33 @@ sub GUEST_DurationTimer($;$) {
|
|||||||
{
|
{
|
||||||
|
|
||||||
# presence timer
|
# presence timer
|
||||||
if ( defined( $hash->{READINGS}{presence}{VAL} )
|
if ( ReadingsVal( $name, "presence", "absent" ) eq "present"
|
||||||
&& $hash->{READINGS}{presence}{VAL} eq "present" )
|
&& ReadingsVal( $name, "lastArrival", "-" ) ne "-" )
|
||||||
{
|
|
||||||
if ( defined( $hash->{READINGS}{lastArrival}{VAL} )
|
|
||||||
&& $hash->{READINGS}{lastArrival}{VAL} ne "-" )
|
|
||||||
{
|
{
|
||||||
$durPresence =
|
$durPresence =
|
||||||
$timestampNow -
|
$timestampNow -
|
||||||
RESIDENTStk_Datetime2Timestamp(
|
RESIDENTStk_Datetime2Timestamp(
|
||||||
$hash->{READINGS}{lastArrival}{VAL} );
|
ReadingsVal( $name, "lastArrival", "-" ) );
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# absence timer
|
# absence timer
|
||||||
if ( defined( $hash->{READINGS}{presence}{VAL} )
|
if ( ReadingsVal( $name, "presence", "present" ) eq "absent"
|
||||||
&& $hash->{READINGS}{presence}{VAL} eq "absent"
|
&& ReadingsVal( $name, "lastDeparture", "-" ) ne "-" )
|
||||||
&& defined( $hash->{READINGS}{state}{VAL} )
|
|
||||||
&& $hash->{READINGS}{state}{VAL} eq "absent" )
|
|
||||||
{
|
|
||||||
if ( defined( $hash->{READINGS}{lastDeparture}{VAL} )
|
|
||||||
&& $hash->{READINGS}{lastDeparture}{VAL} ne "-" )
|
|
||||||
{
|
{
|
||||||
$durAbsence =
|
$durAbsence =
|
||||||
$timestampNow -
|
$timestampNow -
|
||||||
RESIDENTStk_Datetime2Timestamp(
|
RESIDENTStk_Datetime2Timestamp(
|
||||||
$hash->{READINGS}{lastDeparture}{VAL} );
|
ReadingsVal( $name, "lastDeparture", "-" ) );
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# sleep timer
|
# sleep timer
|
||||||
if ( defined( $hash->{READINGS}{state}{VAL} )
|
if ( ReadingsVal( $name, "state", "home" ) eq "asleep"
|
||||||
&& $hash->{READINGS}{state}{VAL} eq "asleep" )
|
&& ReadingsVal( $name, "lastSleep", "-" ) ne "-" )
|
||||||
{
|
|
||||||
if ( defined( $hash->{READINGS}{lastSleep}{VAL} )
|
|
||||||
&& $hash->{READINGS}{lastSleep}{VAL} ne "-" )
|
|
||||||
{
|
{
|
||||||
$durSleep =
|
$durSleep =
|
||||||
$timestampNow -
|
$timestampNow -
|
||||||
RESIDENTStk_Datetime2Timestamp(
|
RESIDENTStk_Datetime2Timestamp(
|
||||||
$hash->{READINGS}{lastSleep}{VAL} );
|
ReadingsVal( $name, "lastSleep", "-" ) );
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
my $durPresence_hr =
|
my $durPresence_hr =
|
||||||
@@ -891,23 +936,20 @@ sub GUEST_DurationTimer($;$) {
|
|||||||
|
|
||||||
readingsBeginUpdate($hash) if ( !$silent );
|
readingsBeginUpdate($hash) if ( !$silent );
|
||||||
readingsBulkUpdate( $hash, "durTimerPresence_cr", $durPresence_cr )
|
readingsBulkUpdate( $hash, "durTimerPresence_cr", $durPresence_cr )
|
||||||
if ( !defined( $hash->{READINGS}{durTimerPresence_cr}{VAL} )
|
if ( ReadingsVal( $name, "durTimerPresence_cr", "" ) ne
|
||||||
|| $hash->{READINGS}{durTimerPresence_cr}{VAL} ne $durPresence_cr );
|
$durPresence_cr );
|
||||||
readingsBulkUpdate( $hash, "durTimerPresence", $durPresence_hr )
|
readingsBulkUpdate( $hash, "durTimerPresence", $durPresence_hr )
|
||||||
if ( !defined( $hash->{READINGS}{durTimerPresence}{VAL} )
|
if (
|
||||||
|| $hash->{READINGS}{durTimerPresence}{VAL} ne $durPresence_hr );
|
ReadingsVal( $name, "durTimerPresence", "" ) ne $durPresence_hr );
|
||||||
readingsBulkUpdate( $hash, "durTimerAbsence_cr", $durAbsence_cr )
|
readingsBulkUpdate( $hash, "durTimerAbsence_cr", $durAbsence_cr )
|
||||||
if ( !defined( $hash->{READINGS}{durTimerAbsence_cr}{VAL} )
|
if (
|
||||||
|| $hash->{READINGS}{durTimerAbsence_cr}{VAL} ne $durAbsence_cr );
|
ReadingsVal( $name, "durTimerAbsence_cr", "" ) ne $durAbsence_cr );
|
||||||
readingsBulkUpdate( $hash, "durTimerAbsence", $durAbsence_hr )
|
readingsBulkUpdate( $hash, "durTimerAbsence", $durAbsence_hr )
|
||||||
if ( !defined( $hash->{READINGS}{durTimerAbsence}{VAL} )
|
if ( ReadingsVal( $name, "durTimerAbsence", "" ) ne $durAbsence_hr );
|
||||||
|| $hash->{READINGS}{durTimerAbsence}{VAL} ne $durAbsence_hr );
|
|
||||||
readingsBulkUpdate( $hash, "durTimerSleep_cr", $durSleep_cr )
|
readingsBulkUpdate( $hash, "durTimerSleep_cr", $durSleep_cr )
|
||||||
if ( !defined( $hash->{READINGS}{durTimerSleep_cr}{VAL} )
|
if ( ReadingsVal( $name, "durTimerSleep_cr", "" ) ne $durSleep_cr );
|
||||||
|| $hash->{READINGS}{durTimerSleep_cr}{VAL} ne $durSleep_cr );
|
|
||||||
readingsBulkUpdate( $hash, "durTimerSleep", $durSleep_hr )
|
readingsBulkUpdate( $hash, "durTimerSleep", $durSleep_hr )
|
||||||
if ( !defined( $hash->{READINGS}{durTimerSleep}{VAL} )
|
if ( ReadingsVal( $name, "durTimerSleep", "" ) ne $durSleep_hr );
|
||||||
|| $hash->{READINGS}{durTimerSleep}{VAL} ne $durSleep_hr );
|
|
||||||
readingsEndUpdate( $hash, 1 ) if ( !$silent );
|
readingsEndUpdate( $hash, 1 ) if ( !$silent );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -933,7 +975,8 @@ sub GUEST_SetLocation($$$;$$$$$$) {
|
|||||||
$lat = "-" if ( !$lat || $lat eq "" );
|
$lat = "-" if ( !$lat || $lat eq "" );
|
||||||
$long = "-" if ( !$long || $long eq "" );
|
$long = "-" if ( !$long || $long eq "" );
|
||||||
$address = "-" if ( !$address || $address eq "" );
|
$address = "-" if ( !$address || $address eq "" );
|
||||||
$location = "underway" if ( $trigger eq "0" );
|
$time = "" if ( !$time );
|
||||||
|
$device = "" if ( !$device );
|
||||||
|
|
||||||
Log3 $name, 5,
|
Log3 $name, 5,
|
||||||
"GUEST $name: received location information: id=$id name=$location trig=$trigger date=$time lat=$lat long=$long address:$address device=$device";
|
"GUEST $name: received location information: id=$id name=$location trig=$trigger date=$time lat=$lat long=$long address:$address device=$device";
|
||||||
@@ -944,63 +987,41 @@ sub GUEST_SetLocation($$$;$$$$$$) {
|
|||||||
|
|
||||||
# read attributes
|
# read attributes
|
||||||
my @location_home =
|
my @location_home =
|
||||||
split( ' ', AttrVal( $name, "rr_locationHome", "home" ) );
|
split( ' ', AttrVal( $name, "rg_locationHome", "home" ) );
|
||||||
my @location_underway =
|
my @location_underway =
|
||||||
split( ' ', AttrVal( $name, "rr_locationUnderway", "underway" ) );
|
split( ' ', AttrVal( $name, "rg_locationUnderway", "underway" ) );
|
||||||
my @location_wayhome =
|
my @location_wayhome =
|
||||||
split( ' ', AttrVal( $name, "rr_locationWayhome", "wayhome" ) );
|
split( ' ', AttrVal( $name, "rg_locationWayhome", "wayhome" ) );
|
||||||
|
|
||||||
$searchstring = quotemeta($location);
|
$searchstring = quotemeta($location);
|
||||||
if ( $location ne "wayhome" ) {
|
|
||||||
if (
|
|
||||||
!grep( m/^$searchstring$/, @location_underway )
|
|
||||||
&& ( $currLocation ne $location
|
|
||||||
|| $currLat ne $lat
|
|
||||||
|| $currLong ne $long
|
|
||||||
|| $currAddr ne $address )
|
|
||||||
)
|
|
||||||
{
|
|
||||||
readingsBulkUpdate( $hash, "lastLocation", $currLocation );
|
|
||||||
readingsBulkUpdate( $hash, "lastLocationLat", $currLat );
|
|
||||||
readingsBulkUpdate( $hash, "lastLocationLong", $currLong );
|
|
||||||
readingsBulkUpdate( $hash, "lastLocationAddr", $currAddr );
|
|
||||||
}
|
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "location", $location );
|
# check for implicit state change
|
||||||
readingsBulkUpdate( $hash, "locationLat", $lat );
|
#
|
||||||
readingsBulkUpdate( $hash, "locationLong", $long );
|
my $stateChange = 0;
|
||||||
readingsBulkUpdate( $hash, "locationAddr", $address );
|
|
||||||
}
|
|
||||||
|
|
||||||
# wayhome detection
|
# home/1
|
||||||
$searchstring = quotemeta($location);
|
|
||||||
if (
|
|
||||||
(
|
|
||||||
$location eq "wayhome"
|
|
||||||
|| grep( m/^$searchstring$/, @location_wayhome )
|
|
||||||
)
|
|
||||||
&& ( $presence eq "absent" )
|
|
||||||
)
|
|
||||||
{
|
|
||||||
Log3 $name, 3, "GUEST $name: on way back home from $location";
|
|
||||||
readingsBulkUpdate( $hash, "wayhome", "1" )
|
|
||||||
if ( ReadingsVal( $name, "wayhome", "0" ) ne "1" );
|
|
||||||
}
|
|
||||||
|
|
||||||
readingsEndUpdate( $hash, 1 );
|
|
||||||
|
|
||||||
# auto-updates
|
|
||||||
$searchstring = quotemeta($location);
|
|
||||||
if ( ( $location eq "home" || grep( m/^$searchstring$/, @location_home ) )
|
if ( ( $location eq "home" || grep( m/^$searchstring$/, @location_home ) )
|
||||||
&& $state ne "home"
|
&& $state ne "home"
|
||||||
&& $state ne "gotosleep"
|
&& $state ne "gotosleep"
|
||||||
&& $state ne "asleep"
|
&& $state ne "asleep"
|
||||||
&& $state ne "awoken" )
|
&& $state ne "awoken"
|
||||||
|
&& $trigger eq "1" )
|
||||||
{
|
{
|
||||||
Log3 $name, 4,
|
$stateChange = 1;
|
||||||
"GUEST $name: implicit state change caused by location " . $location;
|
|
||||||
GUEST_Set( $hash, $name, "silentSet", "state", "home" );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# home/0
|
||||||
|
elsif (
|
||||||
|
( $location eq "home" || grep( m/^$searchstring$/, @location_home ) )
|
||||||
|
&& $state ne "gone"
|
||||||
|
&& $state ne "none"
|
||||||
|
&& $state ne "absent"
|
||||||
|
&& $trigger eq "0" )
|
||||||
|
{
|
||||||
|
$stateChange = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
# absent
|
||||||
elsif (
|
elsif (
|
||||||
(
|
(
|
||||||
$location eq "underway"
|
$location eq "underway"
|
||||||
@@ -1011,9 +1032,87 @@ sub GUEST_SetLocation($$$;$$$$$$) {
|
|||||||
&& $state ne "absent"
|
&& $state ne "absent"
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
$stateChange = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
# wayhome
|
||||||
|
my $wayhome;
|
||||||
|
if (
|
||||||
|
(
|
||||||
|
$location eq "wayhome"
|
||||||
|
|| ( grep( m/^$searchstring$/, @location_wayhome )
|
||||||
|
&& $trigger eq "0" )
|
||||||
|
)
|
||||||
|
&& $presence eq "absent"
|
||||||
|
)
|
||||||
|
{
|
||||||
|
Log3 $name, 5, "GUEST $name: wayhome signal received";
|
||||||
|
if (
|
||||||
|
(
|
||||||
|
( $location eq "wayhome" && $trigger eq "1" )
|
||||||
|
|| ( $location ne "wayhome" && $trigger eq "0" )
|
||||||
|
)
|
||||||
|
&& ReadingsVal( $name, "wayhome", "0" ) ne "1"
|
||||||
|
)
|
||||||
|
{
|
||||||
|
Log3 $name, 3, "GUEST $name: on way back home from $location";
|
||||||
|
readingsBulkUpdate( $hash, "wayhome", "1" );
|
||||||
|
$wayhome = 1;
|
||||||
|
}
|
||||||
|
elsif ($location eq "wayhome"
|
||||||
|
&& $trigger eq "0"
|
||||||
|
&& ReadingsVal( $name, "wayhome", "0" ) ne "0" )
|
||||||
|
{
|
||||||
|
Log3 $name, 3,
|
||||||
|
"GUEST $name: seems not to be on way back home anymore";
|
||||||
|
readingsBulkUpdate( $hash, "wayhome", "0" );
|
||||||
|
$wayhome = 1;
|
||||||
|
$location = "underway";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !grep( m/^$searchstring$/, @location_underway )
|
||||||
|
&& ( $stateChange > 0 || $currLocation ne $location ) )
|
||||||
|
{
|
||||||
|
Log3 $name, 5, "GUEST $name: archiving last known location";
|
||||||
|
readingsBulkUpdate( $hash, "lastLocationLat", $currLat );
|
||||||
|
readingsBulkUpdate( $hash, "lastLocationLong", $currLong );
|
||||||
|
readingsBulkUpdate( $hash, "lastLocationAddr", $currAddr );
|
||||||
|
readingsBulkUpdate( $hash, "lastLocation", $currLocation );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $wayhome
|
||||||
|
|| $stateChange > 0
|
||||||
|
|| ( $lat ne "-" && $long ne "-" ) )
|
||||||
|
{
|
||||||
|
Log3 $name, 5, "GUEST $name: Using new lat/long/addr information";
|
||||||
|
readingsBulkUpdate( $hash, "locationLat", $lat );
|
||||||
|
readingsBulkUpdate( $hash, "locationLong", $long );
|
||||||
|
readingsBulkUpdate( $hash, "locationAddr", $address );
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
Log3 $name, 5,
|
||||||
|
"GUEST $name: keeping last known lat/long/addr information";
|
||||||
|
readingsBulkUpdate( $hash, "locationLat", $currLat );
|
||||||
|
readingsBulkUpdate( $hash, "locationLong", $currLong );
|
||||||
|
readingsBulkUpdate( $hash, "locationAddr", $currAddr );
|
||||||
|
}
|
||||||
|
|
||||||
|
readingsBulkUpdate( $hash, "location", $location )
|
||||||
|
if ( $location ne "wayhome" );
|
||||||
|
|
||||||
|
readingsEndUpdate( $hash, 1 );
|
||||||
|
|
||||||
|
# trigger state change
|
||||||
|
if ( $stateChange > 0 ) {
|
||||||
Log3 $name, 4,
|
Log3 $name, 4,
|
||||||
"GUEST $name: implicit state change caused by location " . $location;
|
"GUEST $name: implicit state change caused by location " . $location;
|
||||||
GUEST_Set( $hash, $name, "silentSet", "state", "absent" );
|
|
||||||
|
GUEST_Set( $hash, $name, "silentSet", "state", "home" )
|
||||||
|
if $stateChange == 1;
|
||||||
|
GUEST_Set( $hash, $name, "silentSet", "state", "absent" )
|
||||||
|
if $stateChange == 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -145,7 +145,7 @@ sub ROOMMATE_Define($$) {
|
|||||||
|
|
||||||
# trigger for modified objects
|
# trigger for modified objects
|
||||||
unless ( $modified == 0 ) {
|
unless ( $modified == 0 ) {
|
||||||
readingsBulkUpdate( $hash, "state", $hash->{READINGS}{state}{VAL} );
|
readingsBulkUpdate( $hash, "state", ReadingsVal( $name, "state", "" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
readingsEndUpdate( $hash, 1 );
|
readingsEndUpdate( $hash, 1 );
|
||||||
@@ -262,22 +262,10 @@ sub ROOMMATE_Notify($$) {
|
|||||||
sub ROOMMATE_Set($@) {
|
sub ROOMMATE_Set($@) {
|
||||||
my ( $hash, @a ) = @_;
|
my ( $hash, @a ) = @_;
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
my $state =
|
my $state = ReadingsVal( $name, "state", "initialized" );
|
||||||
( defined( $hash->{READINGS}{state}{VAL} ) )
|
my $presence = ReadingsVal( $name, "presence", "undefined" );
|
||||||
? $hash->{READINGS}{state}{VAL}
|
my $mood = ReadingsVal( $name, "mood", "-" );
|
||||||
: "initialized";
|
my $location = ReadingsVal( $name, "location", "undefined" );
|
||||||
my $presence =
|
|
||||||
( defined( $hash->{READINGS}{presence}{VAL} ) )
|
|
||||||
? $hash->{READINGS}{presence}{VAL}
|
|
||||||
: "undefined";
|
|
||||||
my $mood =
|
|
||||||
( defined( $hash->{READINGS}{mood}{VAL} ) )
|
|
||||||
? $hash->{READINGS}{mood}{VAL}
|
|
||||||
: "-";
|
|
||||||
my $location =
|
|
||||||
( defined( $hash->{READINGS}{location}{VAL} ) )
|
|
||||||
? $hash->{READINGS}{location}{VAL}
|
|
||||||
: "undefined";
|
|
||||||
my $silent = 0;
|
my $silent = 0;
|
||||||
|
|
||||||
Log3 $name, 5, "ROOMMATE $name: called function ROOMMATE_Set()";
|
Log3 $name, 5, "ROOMMATE $name: called function ROOMMATE_Set()";
|
||||||
@@ -443,21 +431,22 @@ sub ROOMMATE_Set($@) {
|
|||||||
|
|
||||||
# if prior state was asleep, update sleep statistics
|
# if prior state was asleep, update sleep statistics
|
||||||
if ( $state eq "asleep"
|
if ( $state eq "asleep"
|
||||||
&& defined( $hash->{READINGS}{lastSleep}{VAL} ) )
|
&& ReadingsVal( $name, "lastSleep", "" ) ne "" )
|
||||||
{
|
{
|
||||||
readingsBulkUpdate( $hash, "lastAwake", $datetime );
|
readingsBulkUpdate( $hash, "lastAwake", $datetime );
|
||||||
readingsBulkUpdate(
|
readingsBulkUpdate(
|
||||||
$hash,
|
$hash,
|
||||||
"lastDurSleep",
|
"lastDurSleep",
|
||||||
RESIDENTStk_TimeDiff(
|
RESIDENTStk_TimeDiff(
|
||||||
$datetime, $hash->{READINGS}{lastSleep}{VAL}
|
$datetime, ReadingsVal( $name, "lastSleep", "" )
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
readingsBulkUpdate(
|
readingsBulkUpdate(
|
||||||
$hash,
|
$hash,
|
||||||
"lastDurSleep_cr",
|
"lastDurSleep_cr",
|
||||||
RESIDENTStk_TimeDiff(
|
RESIDENTStk_TimeDiff(
|
||||||
$datetime, $hash->{READINGS}{lastSleep}{VAL}, "min"
|
$datetime, ReadingsVal( $name, "lastSleep", "" ),
|
||||||
|
"min"
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -507,7 +496,7 @@ sub ROOMMATE_Set($@) {
|
|||||||
: ("underway");
|
: ("underway");
|
||||||
my $searchstring = quotemeta($location);
|
my $searchstring = quotemeta($location);
|
||||||
|
|
||||||
if ( $newpresence eq "present" ) {
|
if ( !$silent && $newpresence eq "present" ) {
|
||||||
if ( !grep( m/^$searchstring$/, @location_home )
|
if ( !grep( m/^$searchstring$/, @location_home )
|
||||||
&& $location ne $location_home[0] )
|
&& $location ne $location_home[0] )
|
||||||
{
|
{
|
||||||
@@ -519,7 +508,8 @@ sub ROOMMATE_Set($@) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if ( !grep( m/^$searchstring$/, @location_underway )
|
if ( !$silent
|
||||||
|
&& !grep( m/^$searchstring$/, @location_underway )
|
||||||
&& $location ne $location_underway[0] )
|
&& $location ne $location_underway[0] )
|
||||||
{
|
{
|
||||||
Log3 $name, 4,
|
Log3 $name, 4,
|
||||||
@@ -531,9 +521,7 @@ sub ROOMMATE_Set($@) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# reset wayhome
|
# reset wayhome
|
||||||
if ( !defined( $hash->{READINGS}{wayhome}{VAL} )
|
if ( ReadingsVal( $name, "wayhome", 1 ) > 0 ) {
|
||||||
|| $hash->{READINGS}{wayhome}{VAL} ne "0" )
|
|
||||||
{
|
|
||||||
readingsBulkUpdate( $hash, "wayhome", "0" );
|
readingsBulkUpdate( $hash, "wayhome", "0" );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -542,14 +530,13 @@ sub ROOMMATE_Set($@) {
|
|||||||
readingsBulkUpdate( $hash, "lastArrival", $datetime );
|
readingsBulkUpdate( $hash, "lastArrival", $datetime );
|
||||||
|
|
||||||
# absence duration
|
# absence duration
|
||||||
if ( defined( $hash->{READINGS}{lastDeparture}{VAL} )
|
if ( ReadingsVal( $name, "lastDeparture", "-" ) ne "-" ) {
|
||||||
&& $hash->{READINGS}{lastDeparture}{VAL} ne "-" )
|
|
||||||
{
|
|
||||||
readingsBulkUpdate(
|
readingsBulkUpdate(
|
||||||
$hash,
|
$hash,
|
||||||
"lastDurAbsence",
|
"lastDurAbsence",
|
||||||
RESIDENTStk_TimeDiff(
|
RESIDENTStk_TimeDiff(
|
||||||
$datetime, $hash->{READINGS}{lastDeparture}{VAL}
|
$datetime,
|
||||||
|
ReadingsVal( $name, "lastDeparture", "-" )
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
readingsBulkUpdate(
|
readingsBulkUpdate(
|
||||||
@@ -557,7 +544,8 @@ sub ROOMMATE_Set($@) {
|
|||||||
"lastDurAbsence_cr",
|
"lastDurAbsence_cr",
|
||||||
RESIDENTStk_TimeDiff(
|
RESIDENTStk_TimeDiff(
|
||||||
$datetime,
|
$datetime,
|
||||||
$hash->{READINGS}{lastDeparture}{VAL}, "min"
|
ReadingsVal( $name, "lastDeparture", "-" ),
|
||||||
|
"min"
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -566,22 +554,21 @@ sub ROOMMATE_Set($@) {
|
|||||||
readingsBulkUpdate( $hash, "lastDeparture", $datetime );
|
readingsBulkUpdate( $hash, "lastDeparture", $datetime );
|
||||||
|
|
||||||
# presence duration
|
# presence duration
|
||||||
if ( defined( $hash->{READINGS}{lastArrival}{VAL} )
|
if ( ReadingsVal( $name, "lastArrival", "-" ) ne "-" ) {
|
||||||
&& $hash->{READINGS}{lastArrival}{VAL} ne "-" )
|
|
||||||
{
|
|
||||||
readingsBulkUpdate(
|
readingsBulkUpdate(
|
||||||
$hash,
|
$hash,
|
||||||
"lastDurPresence",
|
"lastDurPresence",
|
||||||
RESIDENTStk_TimeDiff(
|
RESIDENTStk_TimeDiff(
|
||||||
$datetime, $hash->{READINGS}{lastArrival}{VAL}
|
$datetime,
|
||||||
|
ReadingsVal( $name, "lastArrival", "-" )
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
readingsBulkUpdate(
|
readingsBulkUpdate(
|
||||||
$hash,
|
$hash,
|
||||||
"lastDurPresence_cr",
|
"lastDurPresence_cr",
|
||||||
RESIDENTStk_TimeDiff(
|
RESIDENTStk_TimeDiff(
|
||||||
$datetime, $hash->{READINGS}{lastArrival}{VAL},
|
$datetime,
|
||||||
"min"
|
ReadingsVal( $name, "lastArrival", "-" ), "min"
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -601,9 +588,8 @@ sub ROOMMATE_Set($@) {
|
|||||||
&& defined( $defs{$object}{TYPE} )
|
&& defined( $defs{$object}{TYPE} )
|
||||||
&& ( $defs{$object}{TYPE} eq "ROOMMATE"
|
&& ( $defs{$object}{TYPE} eq "ROOMMATE"
|
||||||
|| $defs{$object}{TYPE} eq "GUEST" )
|
|| $defs{$object}{TYPE} eq "GUEST" )
|
||||||
&& defined( $defs{$object}{READINGS}{state}{VAL} )
|
&& ReadingsVal( $object, "state", "" ) ne "gone"
|
||||||
&& $defs{$object}{READINGS}{state}{VAL} ne "gone"
|
&& ReadingsVal( $object, "state", "" ) ne "none"
|
||||||
&& $defs{$object}{READINGS}{state}{VAL} ne "none"
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
fhem("set $object $newstate");
|
fhem("set $object $newstate");
|
||||||
@@ -633,13 +619,13 @@ sub ROOMMATE_Set($@) {
|
|||||||
Log3 $name, 2, "ROOMMATE set $name mood " . $a[2] if ( !$silent );
|
Log3 $name, 2, "ROOMMATE set $name mood " . $a[2] if ( !$silent );
|
||||||
readingsBeginUpdate($hash) if ( !$silent );
|
readingsBeginUpdate($hash) if ( !$silent );
|
||||||
|
|
||||||
if ( $a[2] eq "toggle" ) {
|
if ( $a[2] eq "toggle"
|
||||||
if ( defined( $hash->{READINGS}{lastMood}{VAL} ) ) {
|
&& ReadingsVal( $name, "lastMood", "" ) ne "" )
|
||||||
|
{
|
||||||
readingsBulkUpdate( $hash, "mood",
|
readingsBulkUpdate( $hash, "mood",
|
||||||
$hash->{READINGS}{lastMood}{VAL} );
|
ReadingsVal( $name, "lastMood", "" ) );
|
||||||
readingsBulkUpdate( $hash, "lastMood", $mood );
|
readingsBulkUpdate( $hash, "lastMood", $mood );
|
||||||
}
|
}
|
||||||
}
|
|
||||||
elsif ( $mood ne $a[2] ) {
|
elsif ( $mood ne $a[2] ) {
|
||||||
readingsBulkUpdate( $hash, "lastMood", $mood )
|
readingsBulkUpdate( $hash, "lastMood", $mood )
|
||||||
if ( $mood ne "-" );
|
if ( $mood ne "-" );
|
||||||
@@ -656,13 +642,93 @@ sub ROOMMATE_Set($@) {
|
|||||||
# location
|
# location
|
||||||
elsif ( $a[1] eq "location" ) {
|
elsif ( $a[1] eq "location" ) {
|
||||||
if ( defined( $a[2] ) && $a[2] ne "" ) {
|
if ( defined( $a[2] ) && $a[2] ne "" ) {
|
||||||
shift @a;
|
Log3 $name, 2, "ROOMMATE set $name location " . $a[2]
|
||||||
shift @a;
|
|
||||||
my $location = join( " ", @a );
|
|
||||||
Log3 $name, 2, "ROOMMATE set $name location " . $location
|
|
||||||
if ( !$silent );
|
if ( !$silent );
|
||||||
|
|
||||||
ROOMMATE_SetLocation( $name, $location, 1, undef );
|
if ( $location ne $a[2] ) {
|
||||||
|
my $searchstring;
|
||||||
|
|
||||||
|
readingsBeginUpdate($hash) if ( !$silent );
|
||||||
|
|
||||||
|
# read attributes
|
||||||
|
my @location_home =
|
||||||
|
( defined( $attr{$name}{"rr_locationHome"} ) )
|
||||||
|
? split( ' ', $attr{$name}{"rr_locationHome"} )
|
||||||
|
: ("home");
|
||||||
|
|
||||||
|
my @location_underway =
|
||||||
|
( defined( $attr{$name}{"rr_locationUnderway"} ) )
|
||||||
|
? split( ' ', $attr{$name}{"rr_locationUnderway"} )
|
||||||
|
: ("underway");
|
||||||
|
|
||||||
|
my @location_wayhome =
|
||||||
|
( defined( $attr{$name}{"rr_locationWayhome"} ) )
|
||||||
|
? split( ' ', $attr{$name}{"rr_locationWayhome"} )
|
||||||
|
: ("wayhome");
|
||||||
|
|
||||||
|
$searchstring = quotemeta($location);
|
||||||
|
readingsBulkUpdate( $hash, "lastLocation", $location )
|
||||||
|
if ( $location ne "wayhome"
|
||||||
|
&& !grep( m/^$searchstring$/, @location_underway ) );
|
||||||
|
readingsBulkUpdate( $hash, "location", $a[2] )
|
||||||
|
if ( $a[2] ne "wayhome" );
|
||||||
|
|
||||||
|
# wayhome detection
|
||||||
|
$searchstring = quotemeta($location);
|
||||||
|
if (
|
||||||
|
(
|
||||||
|
$a[2] eq "wayhome"
|
||||||
|
|| grep( m/^$searchstring$/, @location_wayhome )
|
||||||
|
)
|
||||||
|
&& ( $presence eq "absent" )
|
||||||
|
)
|
||||||
|
{
|
||||||
|
Log3 $name, 3,
|
||||||
|
"ROOMMATE $name: on way back home from $location";
|
||||||
|
readingsBulkUpdate( $hash, "wayhome", "1" )
|
||||||
|
if ( !defined( $hash->{READINGS}{wayhome}{VAL} )
|
||||||
|
|| $hash->{READINGS}{wayhome}{VAL} ne "1" );
|
||||||
|
}
|
||||||
|
|
||||||
|
readingsEndUpdate( $hash, 1 ) if ( !$silent );
|
||||||
|
|
||||||
|
# auto-updates
|
||||||
|
$searchstring = quotemeta( $a[2] );
|
||||||
|
if (
|
||||||
|
(
|
||||||
|
$a[2] eq "home"
|
||||||
|
|| grep( m/^$searchstring$/, @location_home )
|
||||||
|
)
|
||||||
|
&& $state ne "home"
|
||||||
|
&& $state ne "gotosleep"
|
||||||
|
&& $state ne "asleep"
|
||||||
|
&& $state ne "awoken"
|
||||||
|
&& $state ne "initialized"
|
||||||
|
)
|
||||||
|
{
|
||||||
|
Log3 $name, 4,
|
||||||
|
"ROOMMATE $name: implicit state change caused by location "
|
||||||
|
. $a[2];
|
||||||
|
ROOMMATE_Set( $hash, $name, "silentSet", "state", "home" );
|
||||||
|
}
|
||||||
|
elsif (
|
||||||
|
(
|
||||||
|
$a[2] eq "underway"
|
||||||
|
|| grep( m/^$searchstring$/, @location_underway )
|
||||||
|
)
|
||||||
|
&& $state ne "gone"
|
||||||
|
&& $state ne "none"
|
||||||
|
&& $state ne "absent"
|
||||||
|
&& $state ne "initialized"
|
||||||
|
)
|
||||||
|
{
|
||||||
|
Log3 $name, 4,
|
||||||
|
"ROOMMATE $name: implicit state change caused by location "
|
||||||
|
. $a[2];
|
||||||
|
ROOMMATE_Set( $hash, $name, "silentSet", "state",
|
||||||
|
"absent" );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return "Invalid 2nd argument, choose one of location ";
|
return "Invalid 2nd argument, choose one of location ";
|
||||||
@@ -754,9 +820,7 @@ sub ROOMMATE_AutoGone($;$) {
|
|||||||
|
|
||||||
RESIDENTStk_RemoveInternalTimer( "AutoGone", $hash );
|
RESIDENTStk_RemoveInternalTimer( "AutoGone", $hash );
|
||||||
|
|
||||||
if ( defined( $hash->{READINGS}{state}{VAL} )
|
if ( ReadingsVal( $name, "state", "home" ) eq "absent" ) {
|
||||||
&& $hash->{READINGS}{state}{VAL} eq "absent" )
|
|
||||||
{
|
|
||||||
my ( $date, $time, $y, $m, $d, $hour, $min, $sec, $timestamp,
|
my ( $date, $time, $y, $m, $d, $hour, $min, $sec, $timestamp,
|
||||||
$timeDiff );
|
$timeDiff );
|
||||||
my $timestampNow = gettimeofday();
|
my $timestampNow = gettimeofday();
|
||||||
@@ -808,45 +872,33 @@ sub ROOMMATE_DurationTimer($;$) {
|
|||||||
{
|
{
|
||||||
|
|
||||||
# presence timer
|
# presence timer
|
||||||
if ( defined( $hash->{READINGS}{presence}{VAL} )
|
if ( ReadingsVal( $name, "presence", "absent" ) eq "present"
|
||||||
&& $hash->{READINGS}{presence}{VAL} eq "present" )
|
&& ReadingsVal( $name, "lastArrival", "-" ) ne "-" )
|
||||||
{
|
|
||||||
if ( defined( $hash->{READINGS}{lastArrival}{VAL} )
|
|
||||||
&& $hash->{READINGS}{lastArrival}{VAL} ne "-" )
|
|
||||||
{
|
{
|
||||||
$durPresence =
|
$durPresence =
|
||||||
$timestampNow -
|
$timestampNow -
|
||||||
RESIDENTStk_Datetime2Timestamp(
|
RESIDENTStk_Datetime2Timestamp(
|
||||||
$hash->{READINGS}{lastArrival}{VAL} );
|
ReadingsVal( $name, "lastArrival", "-" ) );
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# absence timer
|
# absence timer
|
||||||
if ( defined( $hash->{READINGS}{presence}{VAL} )
|
if ( ReadingsVal( $name, "presence", "present" ) eq "absent"
|
||||||
&& $hash->{READINGS}{presence}{VAL} eq "absent" )
|
&& ReadingsVal( $name, "lastDeparture", "-" ) ne "-" )
|
||||||
{
|
|
||||||
if ( defined( $hash->{READINGS}{lastDeparture}{VAL} )
|
|
||||||
&& $hash->{READINGS}{lastDeparture}{VAL} ne "-" )
|
|
||||||
{
|
{
|
||||||
$durAbsence =
|
$durAbsence =
|
||||||
$timestampNow -
|
$timestampNow -
|
||||||
RESIDENTStk_Datetime2Timestamp(
|
RESIDENTStk_Datetime2Timestamp(
|
||||||
$hash->{READINGS}{lastDeparture}{VAL} );
|
ReadingsVal( $name, "lastDeparture", "-" ) );
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# sleep timer
|
# sleep timer
|
||||||
if ( defined( $hash->{READINGS}{state}{VAL} )
|
if ( ReadingsVal( $name, "state", "home" ) eq "asleep"
|
||||||
&& $hash->{READINGS}{state}{VAL} eq "asleep" )
|
&& ReadingsVal( $name, "lastSleep", "-" ) ne "-" )
|
||||||
{
|
|
||||||
if ( defined( $hash->{READINGS}{lastSleep}{VAL} )
|
|
||||||
&& $hash->{READINGS}{lastSleep}{VAL} ne "-" )
|
|
||||||
{
|
{
|
||||||
$durSleep =
|
$durSleep =
|
||||||
$timestampNow -
|
$timestampNow -
|
||||||
RESIDENTStk_Datetime2Timestamp(
|
RESIDENTStk_Datetime2Timestamp(
|
||||||
$hash->{READINGS}{lastSleep}{VAL} );
|
ReadingsVal( $name, "lastSleep", "-" ) );
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
my $durPresence_hr =
|
my $durPresence_hr =
|
||||||
@@ -865,23 +917,20 @@ sub ROOMMATE_DurationTimer($;$) {
|
|||||||
|
|
||||||
readingsBeginUpdate($hash) if ( !$silent );
|
readingsBeginUpdate($hash) if ( !$silent );
|
||||||
readingsBulkUpdate( $hash, "durTimerPresence_cr", $durPresence_cr )
|
readingsBulkUpdate( $hash, "durTimerPresence_cr", $durPresence_cr )
|
||||||
if ( !defined( $hash->{READINGS}{durTimerPresence_cr}{VAL} )
|
if ( ReadingsVal( $name, "durTimerPresence_cr", "" ) ne
|
||||||
|| $hash->{READINGS}{durTimerPresence_cr}{VAL} ne $durPresence_cr );
|
$durPresence_cr );
|
||||||
readingsBulkUpdate( $hash, "durTimerPresence", $durPresence_hr )
|
readingsBulkUpdate( $hash, "durTimerPresence", $durPresence_hr )
|
||||||
if ( !defined( $hash->{READINGS}{durTimerPresence}{VAL} )
|
if (
|
||||||
|| $hash->{READINGS}{durTimerPresence}{VAL} ne $durPresence_hr );
|
ReadingsVal( $name, "durTimerPresence", "" ) ne $durPresence_hr );
|
||||||
readingsBulkUpdate( $hash, "durTimerAbsence_cr", $durAbsence_cr )
|
readingsBulkUpdate( $hash, "durTimerAbsence_cr", $durAbsence_cr )
|
||||||
if ( !defined( $hash->{READINGS}{durTimerAbsence_cr}{VAL} )
|
if (
|
||||||
|| $hash->{READINGS}{durTimerAbsence_cr}{VAL} ne $durAbsence_cr );
|
ReadingsVal( $name, "durTimerAbsence_cr", "" ) ne $durAbsence_cr );
|
||||||
readingsBulkUpdate( $hash, "durTimerAbsence", $durAbsence_hr )
|
readingsBulkUpdate( $hash, "durTimerAbsence", $durAbsence_hr )
|
||||||
if ( !defined( $hash->{READINGS}{durTimerAbsence}{VAL} )
|
if ( ReadingsVal( $name, "durTimerAbsence", "" ) ne $durAbsence_hr );
|
||||||
|| $hash->{READINGS}{durTimerAbsence}{VAL} ne $durAbsence_hr );
|
|
||||||
readingsBulkUpdate( $hash, "durTimerSleep_cr", $durSleep_cr )
|
readingsBulkUpdate( $hash, "durTimerSleep_cr", $durSleep_cr )
|
||||||
if ( !defined( $hash->{READINGS}{durTimerSleep_cr}{VAL} )
|
if ( ReadingsVal( $name, "durTimerSleep_cr", "" ) ne $durSleep_cr );
|
||||||
|| $hash->{READINGS}{durTimerSleep_cr}{VAL} ne $durSleep_cr );
|
|
||||||
readingsBulkUpdate( $hash, "durTimerSleep", $durSleep_hr )
|
readingsBulkUpdate( $hash, "durTimerSleep", $durSleep_hr )
|
||||||
if ( !defined( $hash->{READINGS}{durTimerSleep}{VAL} )
|
if ( ReadingsVal( $name, "durTimerSleep", "" ) ne $durSleep_hr );
|
||||||
|| $hash->{READINGS}{durTimerSleep}{VAL} ne $durSleep_hr );
|
|
||||||
readingsEndUpdate( $hash, 1 ) if ( !$silent );
|
readingsEndUpdate( $hash, 1 ) if ( !$silent );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -906,7 +955,8 @@ sub ROOMMATE_SetLocation($$$;$$$$$$) {
|
|||||||
$lat = "-" if ( !$lat || $lat eq "" );
|
$lat = "-" if ( !$lat || $lat eq "" );
|
||||||
$long = "-" if ( !$long || $long eq "" );
|
$long = "-" if ( !$long || $long eq "" );
|
||||||
$address = "-" if ( !$address || $address eq "" );
|
$address = "-" if ( !$address || $address eq "" );
|
||||||
$location = "underway" if ( $trigger eq "0" );
|
$time = "" if ( !$time );
|
||||||
|
$device = "" if ( !$device );
|
||||||
|
|
||||||
Log3 $name, 5,
|
Log3 $name, 5,
|
||||||
"ROOMMATE $name: received location information: id=$id name=$location trig=$trigger date=$time lat=$lat long=$long address:$address device=$device";
|
"ROOMMATE $name: received location information: id=$id name=$location trig=$trigger date=$time lat=$lat long=$long address:$address device=$device";
|
||||||
@@ -924,57 +974,34 @@ sub ROOMMATE_SetLocation($$$;$$$$$$) {
|
|||||||
split( ' ', AttrVal( $name, "rr_locationWayhome", "wayhome" ) );
|
split( ' ', AttrVal( $name, "rr_locationWayhome", "wayhome" ) );
|
||||||
|
|
||||||
$searchstring = quotemeta($location);
|
$searchstring = quotemeta($location);
|
||||||
if ( $location ne "wayhome" ) {
|
|
||||||
if (
|
|
||||||
!grep( m/^$searchstring$/, @location_underway )
|
|
||||||
&& ( $currLocation ne $location
|
|
||||||
|| $currLat ne $lat
|
|
||||||
|| $currLong ne $long
|
|
||||||
|| $currAddr ne $address )
|
|
||||||
)
|
|
||||||
{
|
|
||||||
readingsBulkUpdate( $hash, "lastLocation", $currLocation );
|
|
||||||
readingsBulkUpdate( $hash, "lastLocationLat", $currLat );
|
|
||||||
readingsBulkUpdate( $hash, "lastLocationLong", $currLong );
|
|
||||||
readingsBulkUpdate( $hash, "lastLocationAddr", $currAddr );
|
|
||||||
}
|
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "location", $location );
|
# check for implicit state change
|
||||||
readingsBulkUpdate( $hash, "locationLat", $lat );
|
#
|
||||||
readingsBulkUpdate( $hash, "locationLong", $long );
|
my $stateChange = 0;
|
||||||
readingsBulkUpdate( $hash, "locationAddr", $address );
|
|
||||||
}
|
|
||||||
|
|
||||||
# wayhome detection
|
# home/1
|
||||||
$searchstring = quotemeta($location);
|
|
||||||
if (
|
|
||||||
(
|
|
||||||
$location eq "wayhome"
|
|
||||||
|| grep( m/^$searchstring$/, @location_wayhome )
|
|
||||||
)
|
|
||||||
&& ( $presence eq "absent" )
|
|
||||||
)
|
|
||||||
{
|
|
||||||
Log3 $name, 3, "ROOMMATE $name: on way back home from $location";
|
|
||||||
readingsBulkUpdate( $hash, "wayhome", "1" )
|
|
||||||
if ( ReadingsVal( $name, "wayhome", "0" ) ne "1" );
|
|
||||||
}
|
|
||||||
|
|
||||||
readingsEndUpdate( $hash, 1 );
|
|
||||||
|
|
||||||
# auto-updates
|
|
||||||
$searchstring = quotemeta($location);
|
|
||||||
if ( ( $location eq "home" || grep( m/^$searchstring$/, @location_home ) )
|
if ( ( $location eq "home" || grep( m/^$searchstring$/, @location_home ) )
|
||||||
&& $state ne "home"
|
&& $state ne "home"
|
||||||
&& $state ne "gotosleep"
|
&& $state ne "gotosleep"
|
||||||
&& $state ne "asleep"
|
&& $state ne "asleep"
|
||||||
&& $state ne "awoken" )
|
&& $state ne "awoken"
|
||||||
|
&& $trigger eq "1" )
|
||||||
{
|
{
|
||||||
Log3 $name, 4,
|
$stateChange = 1;
|
||||||
"ROOMMATE $name: implicit state change caused by location "
|
|
||||||
. $location;
|
|
||||||
ROOMMATE_Set( $hash, $name, "silentSet", "state", "home" );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# home/0
|
||||||
|
elsif (
|
||||||
|
( $location eq "home" || grep( m/^$searchstring$/, @location_home ) )
|
||||||
|
&& $state ne "gone"
|
||||||
|
&& $state ne "none"
|
||||||
|
&& $state ne "absent"
|
||||||
|
&& $trigger eq "0" )
|
||||||
|
{
|
||||||
|
$stateChange = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
# absent
|
||||||
elsif (
|
elsif (
|
||||||
(
|
(
|
||||||
$location eq "underway"
|
$location eq "underway"
|
||||||
@@ -985,10 +1012,88 @@ sub ROOMMATE_SetLocation($$$;$$$$$$) {
|
|||||||
&& $state ne "absent"
|
&& $state ne "absent"
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
$stateChange = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
# wayhome
|
||||||
|
my $wayhome;
|
||||||
|
if (
|
||||||
|
(
|
||||||
|
$location eq "wayhome"
|
||||||
|
|| ( grep( m/^$searchstring$/, @location_wayhome )
|
||||||
|
&& $trigger eq "0" )
|
||||||
|
)
|
||||||
|
&& $presence eq "absent"
|
||||||
|
)
|
||||||
|
{
|
||||||
|
Log3 $name, 5, "ROOMMATE $name: wayhome signal received";
|
||||||
|
if (
|
||||||
|
(
|
||||||
|
( $location eq "wayhome" && $trigger eq "1" )
|
||||||
|
|| ( $location ne "wayhome" && $trigger eq "0" )
|
||||||
|
)
|
||||||
|
&& ReadingsVal( $name, "wayhome", "0" ) ne "1"
|
||||||
|
)
|
||||||
|
{
|
||||||
|
Log3 $name, 3, "ROOMMATE $name: on way back home from $location";
|
||||||
|
readingsBulkUpdate( $hash, "wayhome", "1" );
|
||||||
|
$wayhome = 1;
|
||||||
|
}
|
||||||
|
elsif ($location eq "wayhome"
|
||||||
|
&& $trigger eq "0"
|
||||||
|
&& ReadingsVal( $name, "wayhome", "0" ) ne "0" )
|
||||||
|
{
|
||||||
|
Log3 $name, 3,
|
||||||
|
"ROOMMATE $name: seems not to be on way back home anymore";
|
||||||
|
readingsBulkUpdate( $hash, "wayhome", "0" );
|
||||||
|
$wayhome = 1;
|
||||||
|
$location = "underway";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !grep( m/^$searchstring$/, @location_underway )
|
||||||
|
&& ( $stateChange > 0 || $currLocation ne $location ) )
|
||||||
|
{
|
||||||
|
Log3 $name, 5, "ROOMMATE $name: archiving last known location";
|
||||||
|
readingsBulkUpdate( $hash, "lastLocationLat", $currLat );
|
||||||
|
readingsBulkUpdate( $hash, "lastLocationLong", $currLong );
|
||||||
|
readingsBulkUpdate( $hash, "lastLocationAddr", $currAddr );
|
||||||
|
readingsBulkUpdate( $hash, "lastLocation", $currLocation );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $wayhome
|
||||||
|
|| $stateChange > 0
|
||||||
|
|| ( $lat ne "-" && $long ne "-" ) )
|
||||||
|
{
|
||||||
|
Log3 $name, 5, "ROOMMATE $name: Using new lat/long/addr information";
|
||||||
|
readingsBulkUpdate( $hash, "locationLat", $lat );
|
||||||
|
readingsBulkUpdate( $hash, "locationLong", $long );
|
||||||
|
readingsBulkUpdate( $hash, "locationAddr", $address );
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
Log3 $name, 5,
|
||||||
|
"ROOMMATE $name: keeping last known lat/long/addr information";
|
||||||
|
readingsBulkUpdate( $hash, "locationLat", $currLat );
|
||||||
|
readingsBulkUpdate( $hash, "locationLong", $currLong );
|
||||||
|
readingsBulkUpdate( $hash, "locationAddr", $currAddr );
|
||||||
|
}
|
||||||
|
|
||||||
|
readingsBulkUpdate( $hash, "location", $location )
|
||||||
|
if ( $location ne "wayhome" );
|
||||||
|
|
||||||
|
readingsEndUpdate( $hash, 1 );
|
||||||
|
|
||||||
|
# trigger state change
|
||||||
|
if ( $stateChange > 0 ) {
|
||||||
Log3 $name, 4,
|
Log3 $name, 4,
|
||||||
"ROOMMATE $name: implicit state change caused by location "
|
"ROOMMATE $name: implicit state change caused by location "
|
||||||
. $location;
|
. $location;
|
||||||
ROOMMATE_Set( $hash, $name, "silentSet", "state", "absent" );
|
|
||||||
|
ROOMMATE_Set( $hash, $name, "silentSet", "state", "home" )
|
||||||
|
if $stateChange == 1;
|
||||||
|
ROOMMATE_Set( $hash, $name, "silentSet", "state", "absent" )
|
||||||
|
if $stateChange == 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user