diff --git a/fhem/CHANGED b/fhem/CHANGED
index 47cf4073a..d09341bc2 100644
--- a/fhem/CHANGED
+++ b/fhem/CHANGED
@@ -1,5 +1,8 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
# Do not insert empty lines here, update check depends on it.
+ - feature: 20_ROOMMATE,20_GUEST: introduce new attribute r*_presenceDevices
+ to allow easy status synchronisation with
+ other FHEM devices (e.g. PRESENCE module)
- bugfix: 93_DbLog.pm: is now version 2.8.6, some small bugfixes
(thanks a lot to DS_Starter)
- update: 55_InfoPanel.pm: attribute mobileApp added
diff --git a/fhem/FHEM/20_GUEST.pm b/fhem/FHEM/20_GUEST.pm
index c53e903ea..c06739164 100644
--- a/fhem/FHEM/20_GUEST.pm
+++ b/fhem/FHEM/20_GUEST.pm
@@ -50,7 +50,7 @@ sub GUEST_Initialize($) {
$hash->{NotifyFn} = "GUEST_Notify";
$hash->{UndefFn} = "GUEST_Undefine";
$hash->{AttrList} =
-"rg_locationHome rg_locationWayhome rg_locationUnderway rg_autoGoneAfter:12,16,24,26,28,30,36,48,60 rg_showAllStates:0,1 rg_realname:group,alias rg_states:multiple-strict,home,gotosleep,asleep,awoken,absent,gone rg_locations rg_moods rg_moodDefault rg_moodSleepy rg_noDuration:0,1 rg_wakeupDevice rg_geofenceUUIDs "
+"rg_locationHome rg_locationWayhome rg_locationUnderway rg_autoGoneAfter:12,16,24,26,28,30,36,48,60 rg_showAllStates:0,1 rg_realname:group,alias rg_states:multiple-strict,home,gotosleep,asleep,awoken,absent,gone rg_locations rg_moods rg_moodDefault rg_moodSleepy rg_noDuration:0,1 rg_wakeupDevice rg_geofenceUUIDs rg_presenceDevices "
. $readingFnAttributes;
}
@@ -243,9 +243,9 @@ sub GUEST_Notify($$) {
# process child notifies
elsif ( $devName ne $hashName ) {
my @registeredWakeupdevs =
- split( /,/, $attr{$hashName}{rg_wakeupDevice} )
- if ( defined( $attr{$hashName}{rg_wakeupDevice} )
- && $attr{$hashName}{rg_wakeupDevice} ne "" );
+ split( ',', AttrVal( $hashName, "rg_wakeupDevice", "" ) );
+ my @presenceDevices =
+ split( ',', AttrVal( $hashName, "rg_presenceDevices", "" ) );
# if we have registered wakeup devices
if (@registeredWakeupdevs) {
@@ -287,6 +287,39 @@ sub GUEST_Notify($$) {
}
}
}
+
+ # process PRESENCE
+ elsif (@presenceDevices) {
+ my $counter = {
+ absent => 0,
+ present => 0,
+ };
+
+ foreach (@presenceDevices) {
+ next unless ( $_ eq $devName );
+ my $presenceState =
+ ReadingsVal( $_, "presence", ReadingsVal( $_, "state", "" ) );
+ next
+ unless ( $presenceState =~
+/^((absent|disappeared|unavailable)|(present|appeared|available|))$/i
+ );
+
+ $counter->{absent}++ if ($2);
+ $counter->{present}++ if ($3);
+ last;
+ }
+
+ if ( $counter->{absent} && !$counter->{present} ) {
+ Log3 $hashName, 4,
+ "GUEST $hashName: Syncing status with $devName = absent";
+ fhem "set $hashName:FILTER=presence=present absent";
+ }
+ elsif ( !$counter->{absent} && $counter->{present} ) {
+ Log3 $hashName, 4,
+ "GUEST $hashName: Syncing status with $devName = present";
+ fhem "set $hashName:FILTER=presence=absent home";
+ }
+ }
}
return;
@@ -1409,6 +1442,9 @@ sub GUEST_StartInternalTimers($$) {
rg_passPresenceTo - synchronize presence state with other GUEST or GUEST devices; separte devices by space
+
+ rg_presenceDevices - take over presence state from any other FHEM device. Separate more than one device with comma meaning ALL of them need to be either present or absent to trigger update of this ROOMMATE device.
+
rg_realname - whenever GUEST wants to use the realname it uses the value of attribute alias or group; defaults to group
@@ -1707,6 +1743,9 @@ sub GUEST_StartInternalTimers($$) {
rg_passPresenceTo - synchronisiere die Anwesenheit mit anderen GUEST oder ROOMMATE Devices; mehrere Devices durch Leerzeichen trennen
+
+ rg_presenceDevices - übernehmen des presence Status von einem anderen FHEM Device. Bei mehreren Devices diese mit Komma trennen, um ein Update des GUEST Devices auszulösen, sobald ALLE Devices entweder absent oder present sind.
+
rg_realname - wo immer GUEST den richtigen Namen verwenden möchte nutzt es den Wert des Attributs alias oder group; Standard ist group
diff --git a/fhem/FHEM/20_ROOMMATE.pm b/fhem/FHEM/20_ROOMMATE.pm
index 8da0beb74..f9c485f2e 100644
--- a/fhem/FHEM/20_ROOMMATE.pm
+++ b/fhem/FHEM/20_ROOMMATE.pm
@@ -50,7 +50,7 @@ sub ROOMMATE_Initialize($) {
$hash->{NotifyFn} = "ROOMMATE_Notify";
$hash->{UndefFn} = "ROOMMATE_Undefine";
$hash->{AttrList} =
-"rr_locationHome rr_locationWayhome rr_locationUnderway rr_autoGoneAfter:12,16,24,26,28,30,36,48,60 rr_showAllStates:0,1 rr_realname:group,alias rr_states:multiple-strict,home,gotosleep,asleep,awoken,absent,gone rr_locations rr_moods rr_moodDefault rr_moodSleepy rr_passPresenceTo rr_noDuration:0,1 rr_wakeupDevice rr_geofenceUUIDs "
+"rr_locationHome rr_locationWayhome rr_locationUnderway rr_autoGoneAfter:12,16,24,26,28,30,36,48,60 rr_showAllStates:0,1 rr_realname:group,alias rr_states:multiple-strict,home,gotosleep,asleep,awoken,absent,gone rr_locations rr_moods rr_moodDefault rr_moodSleepy rr_passPresenceTo rr_noDuration:0,1 rr_wakeupDevice rr_geofenceUUIDs rr_presenceDevices "
. $readingFnAttributes;
}
@@ -248,9 +248,9 @@ sub ROOMMATE_Notify($$) {
# process child notifies
elsif ( $devName ne $hashName ) {
my @registeredWakeupdevs =
- split( /,/, $attr{$hashName}{rr_wakeupDevice} )
- if ( defined( $attr{$hashName}{rr_wakeupDevice} )
- && $attr{$hashName}{rr_wakeupDevice} ne "" );
+ split( ',', AttrVal( $hashName, "rr_wakeupDevice", "" ) );
+ my @presenceDevices =
+ split( ',', AttrVal( $hashName, "rr_presenceDevices", "" ) );
# if we have registered wakeup devices
if (@registeredWakeupdevs) {
@@ -292,6 +292,41 @@ sub ROOMMATE_Notify($$) {
}
}
}
+
+ # process PRESENCE
+ elsif (@presenceDevices) {
+ my $counter = {
+ absent => 0,
+ present => 0,
+ };
+
+ foreach (@presenceDevices) {
+ next unless ( $_ eq $devName );
+ my $presenceState =
+ ReadingsVal( $_, "presence", ReadingsVal( $_, "state", "" ) );
+ next
+ unless ( $presenceState =~
+/^((absent|disappeared|unavailable)|(present|appeared|available|))$/i
+ );
+
+ $counter->{absent}++ if ($2);
+ $counter->{present}++ if ($3);
+ last;
+ }
+
+ if ( $counter->{absent} && !$counter->{present} ) {
+ Log3 $hashName, 4,
+ "ROOMMATE $hashName: "
+ . "Syncing status with $devName = absent";
+ fhem "set $hashName:FILTER=presence=present absent";
+ }
+ elsif ( !$counter->{absent} && $counter->{present} ) {
+ Log3 $hashName, 4,
+ "ROOMMATE $hashName: "
+ . "Syncing status with $devName = present";
+ fhem "set $hashName:FILTER=presence=absent home";
+ }
+ }
}
return;
@@ -1397,6 +1432,9 @@ sub ROOMMATE_StartInternalTimers($$) {
rr_passPresenceTo - synchronize presence state with other ROOMMATE or GUEST devices; separte devices by space
+
+ rr_presenceDevices - take over presence state from any other FHEM device. Separate more than one device with comma meaning ALL of them need to be either present or absent to trigger update of this ROOMMATE device.
+
rr_realname - whenever ROOMMATE wants to use the realname it uses the value of attribute alias or group; defaults to group
@@ -1695,6 +1733,9 @@ sub ROOMMATE_StartInternalTimers($$) {
rr_passPresenceTo - synchronisiere die Anwesenheit mit anderen ROOMMATE oder GUEST Devices; mehrere Devices durch Leerzeichen trennen
+
+ rr_presenceDevices - übernehmen des presence Status von einem anderen FHEM Device. Bei mehreren Devices diese mit Komma trennen, um ein Update des ROOMMATE Devices auszulösen, sobald ALLE Devices entweder absent oder present sind.
+
rr_realname - wo immer ROOMMATE den richtigen Namen verwenden möchte nutzt es den Wert des Attributs alias oder group; Standard ist group