2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-20 07:16:03 +00:00

RESIDENTStk wakeuptimer: improved update of user device for nextWakeup* readings; log messages to include current user state

git-svn-id: https://svn.fhem.de/fhem/trunk@8671 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
jpawlowski 2015-05-31 11:17:09 +00:00
parent aa7299090e
commit 6548da185b

View File

@ -80,6 +80,7 @@ sub RESIDENTStk_wakeupSet($$) {
my $lastRun = ReadingsVal( $NAME, "lastRun", "07:00" ); my $lastRun = ReadingsVal( $NAME, "lastRun", "07:00" );
my $nextRun = ReadingsVal( $NAME, "nextRun", "07:00" ); my $nextRun = ReadingsVal( $NAME, "nextRun", "07:00" );
my $running = ReadingsVal( $NAME, "running", 0 ); my $running = ReadingsVal( $NAME, "running", 0 );
my $wakeupUserdeviceState = ReadingsVal( $wakeupUserdevice, "state", 0 );
my $atName = "at_" . $NAME; my $atName = "at_" . $NAME;
my $wdNameGotosleep = "wd_" . $wakeupUserdevice . "_gotosleep"; my $wdNameGotosleep = "wd_" . $wakeupUserdevice . "_gotosleep";
my $wdNameAsleep = "wd_" . $wakeupUserdevice . "_asleep"; my $wdNameAsleep = "wd_" . $wakeupUserdevice . "_asleep";
@ -140,6 +141,7 @@ sub RESIDENTStk_wakeupSet($$) {
## 3. \$EVTPART2 -> wake-up begin time considering wakeupOffset attribute\ ## 3. \$EVTPART2 -> wake-up begin time considering wakeupOffset attribute\
## 4. \$EVTPART3 -> enforced wakeup yes=1,no=0 from wakeupEnforced attribute\ ## 4. \$EVTPART3 -> enforced wakeup yes=1,no=0 from wakeupEnforced attribute\
## 5. \$EVTPART4 -> device name of the user which called this macro\ ## 5. \$EVTPART4 -> device name of the user which called this macro\
## 6. \$EVTPART5 -> current state of user\
##=============================================================================\ ##=============================================================================\
\ \
##-----------------------------------------------------------------------------\ ##-----------------------------------------------------------------------------\
@ -158,7 +160,7 @@ for (my \$i=1;; \$i <= 10;; \$i++) {\
## Run first automation commands and create temp. at-devices for lagging actions.\ ## Run first automation commands and create temp. at-devices for lagging actions.\
##\ ##\
if (\$EVTPART0 eq \"start\") {\ if (\$EVTPART0 eq \"start\") {\
Log3 \$NAME, 3, \"\$NAME: Wake-up program started for \$EVTPART4 with target time \$EVTPART1\";;\ Log3 \$NAME, 3, \"\$NAME: Wake-up program started for \$EVTPART4 with target time \$EVTPART1. Current state: \$EVTPART5\";;\
\ \
# fhem \"set BR_FloorLamp:FILTER=onoff=0 pct 1 : ct 2000 : transitiontime 0;; set BR_FloorLamp:FILTER=pct=1 pct 90 : ct 5600 : transitiontime 17700\";;\ # fhem \"set BR_FloorLamp:FILTER=onoff=0 pct 1 : ct 2000 : transitiontime 0;; set BR_FloorLamp:FILTER=pct=1 pct 90 : ct 5600 : transitiontime 17700\";;\
\ \
@ -186,7 +188,7 @@ if (\$EVTPART0 eq \"start\") {\
## assuming the user does not want any further automation activities.\ ## assuming the user does not want any further automation activities.\
##\ ##\
if (\$EVTPART0 eq \"stop\") {\ if (\$EVTPART0 eq \"stop\") {\
Log3 \$NAME, 3, \"\$NAME: Wake-up program ended for \$EVTPART4 with target time \$EVTPART1\";;\ Log3 \$NAME, 3, \"\$NAME: Wake-up program ended for \$EVTPART4 with target time \$EVTPART1. Current state: \$EVTPART5\";;\
\ \
# if wake-up should be enforced, auto-change user state from 'asleep' to 'awoken'\ # if wake-up should be enforced, auto-change user state from 'asleep' to 'awoken'\
# after a small additional nap to kick you out of bed if user did not confirm to be awake :-)\ # after a small additional nap to kick you out of bed if user did not confirm to be awake :-)\
@ -731,15 +733,15 @@ if (\$EVTPART0 eq \"stop\") {\
if ( defined( $notify[1] ) || $VALUE eq "end" ) { if ( defined( $notify[1] ) || $VALUE eq "end" ) {
Log3 $NAME, 4, Log3 $NAME, 4,
"RESIDENTStk $NAME: trigger $wakeupMacro stop $lastRun $wakeupOffset $wakeupEnforced $wakeupUserdevice"; "RESIDENTStk $NAME: trigger $wakeupMacro stop $lastRun $wakeupOffset $wakeupEnforced $wakeupUserdevice $wakeupUserdeviceState";
fhem fhem
"trigger $wakeupMacro stop $lastRun $wakeupOffset $wakeupEnforced $wakeupUserdevice"; "trigger $wakeupMacro stop $lastRun $wakeupOffset $wakeupEnforced $wakeupUserdevice $wakeupUserdeviceState";
} }
else { else {
Log3 $NAME, 4, Log3 $NAME, 4,
"RESIDENTStk $NAME: trigger $wakeupMacro forced-stop $lastRun $wakeupOffset $wakeupEnforced $wakeupUserdevice"; "RESIDENTStk $NAME: trigger $wakeupMacro forced-stop $lastRun $wakeupOffset $wakeupEnforced $wakeupUserdevice $wakeupUserdeviceState";
fhem fhem
"trigger $wakeupMacro forced-stop $lastRun $wakeupOffset $wakeupEnforced $wakeupUserdevice"; "trigger $wakeupMacro forced-stop $lastRun $wakeupOffset $wakeupEnforced $wakeupUserdevice $wakeupUserdeviceState";
fhem "set $wakeupUserdevice:FILTER=state=asleep awoken"; fhem "set $wakeupUserdevice:FILTER=state=asleep awoken";
} }
@ -781,6 +783,8 @@ if (\$EVTPART0 eq \"stop\") {\
&& defined( $defs{$wakeupAtdevice} ) && defined( $defs{$wakeupAtdevice} )
&& $defs{$wakeupAtdevice}{TYPE} eq "at" ) && $defs{$wakeupAtdevice}{TYPE} eq "at" )
{ {
# Update wakeuptimer device
#
readingsBeginUpdate( $defs{$NAME} ); readingsBeginUpdate( $defs{$NAME} );
if ( ReadingsVal( $NAME, "nextRun", 0 ) ne $VALUE ) { if ( ReadingsVal( $NAME, "nextRun", 0 ) ne $VALUE ) {
Log3 $NAME, 4, "RESIDENTStk $NAME: New wake-up time: $VALUE"; Log3 $NAME, 4, "RESIDENTStk $NAME: New wake-up time: $VALUE";
@ -800,24 +804,22 @@ if (\$EVTPART0 eq \"stop\") {\
# Update user device # Update user device
# #
readingsBeginUpdate( $defs{$wakeupUserdevice} );
my ( $nextWakeupDev, $nextWakeup ) = my ( $nextWakeupDev, $nextWakeup ) =
RESIDENTStk_wakeupGetNext($wakeupUserdevice); RESIDENTStk_wakeupGetNext($wakeupUserdevice);
if ( $nextWakeupDev && $nextWakeup ) { if ( !$nextWakeupDev || !$nextWakeup ) {
fhem $nextWakeupDev = "none";
"setreading $wakeupUserdevice:FILTER=nextWakeupDev!=$nextWakeupDev nextWakeupDev $nextWakeupDev"; $nextWakeup = "OFF";
fhem
"setreading $wakeupUserdevice:FILTER=nextWakeup!=$nextWakeup nextWakeup $nextWakeup";
}
else {
fhem
"setreading $wakeupUserdevice:FILTER=nextWakeupDev!=none nextWakeupDev none";
fhem
"setreading $wakeupUserdevice:FILTER=nextWakeup!=OFF nextWakeup OFF";
}
if ( !$running ) {
fhem "setreading $wakeupUserdevice:FILTER=wakeup!=0 wakeup 0";
} }
readingsBulkUpdate( $defs{$wakeupUserdevice},
"nextWakeupDev", $nextWakeupDev )
if ( ReadingsVal( $defs{$wakeupUserdevice}, "nextWakeupDev", 0 ) ne
$nextWakeupDev );
readingsBulkUpdate( $defs{$wakeupUserdevice},
"nextWakeup", $nextWakeup )
if ( ReadingsVal( $defs{$wakeupUserdevice}, "nextWakeup", 0 ) ne
$nextWakeup );
readingsEndUpdate( $defs{$wakeupUserdevice}, 1 );
} }
@ -923,6 +925,7 @@ sub RESIDENTStk_wakeupRun($;$) {
my $nextRun = ReadingsVal( $NAME, "nextRun", "06:00" ); my $nextRun = ReadingsVal( $NAME, "nextRun", "06:00" );
my $nextRunTimestamp = my $nextRunTimestamp =
ReadingsTimestamp( $NAME, "nextRun", "1970-01-01 00:00:00" ); ReadingsTimestamp( $NAME, "nextRun", "1970-01-01 00:00:00" );
my $wakeupUserdeviceState = ReadingsVal( $wakeupUserdevice, "state", 0 );
my $wakeupUserdeviceWakeup = ReadingsVal( $wakeupUserdevice, "wakeup", 0 ); my $wakeupUserdeviceWakeup = ReadingsVal( $wakeupUserdevice, "wakeup", 0 );
my $room = AttrVal( $NAME, "room", 0 ); my $room = AttrVal( $NAME, "room", 0 );
my $running = 0; my $running = 0;
@ -1017,7 +1020,7 @@ sub RESIDENTStk_wakeupRun($;$) {
"$NAME: device $wakeupUserdevice is not of type RESIDENTS, ROOMMATE or GUEST"; "$NAME: device $wakeupUserdevice is not of type RESIDENTS, ROOMMATE or GUEST";
} }
elsif ($defs{$wakeupUserdevice}{TYPE} eq "GUEST" elsif ($defs{$wakeupUserdevice}{TYPE} eq "GUEST"
&& ReadingsVal( $wakeupUserdevice, "state", "" ) eq "none" ) && $wakeupUserdeviceState eq "none" )
{ {
Log3 $NAME, 4, Log3 $NAME, 4,
"RESIDENTStk $NAME: GUEST device $wakeupUserdevice has status value 'none' so let's disable this alarm timer"; "RESIDENTStk $NAME: GUEST device $wakeupUserdevice has status value 'none' so let's disable this alarm timer";
@ -1058,14 +1061,14 @@ sub RESIDENTStk_wakeupRun($;$) {
Log3 $NAME, 4, Log3 $NAME, 4,
"RESIDENTStk $NAME: weekday restriction in conjunction with $wakeupHolidays in use - not triggering wake-up program this time"; "RESIDENTStk $NAME: weekday restriction in conjunction with $wakeupHolidays in use - not triggering wake-up program this time";
} }
elsif (ReadingsVal( $wakeupUserdevice, "state", "" ) eq "absent" elsif ($wakeupUserdeviceState eq "absent"
|| ReadingsVal( $wakeupUserdevice, "state", "" ) eq "gone" || $wakeupUserdeviceState eq "gone"
|| ReadingsVal( $wakeupUserdevice, "state", "" ) eq "gotosleep" || $wakeupUserdeviceState eq "gotosleep"
|| ReadingsVal( $wakeupUserdevice, "state", "" ) eq "awoken" ) || $wakeupUserdeviceState eq "awoken" )
{ {
Log3 $NAME, 4, Log3 $NAME, 4,
"RESIDENTStk $NAME: we should not start any wake-up program for resident device $wakeupUserdevice being in state '" "RESIDENTStk $NAME: we should not start any wake-up program for resident device $wakeupUserdevice being in state '"
. ReadingsVal( $wakeupUserdevice, "state", "" ) . $wakeupUserdeviceState
. "' - not triggering wake-up program this time"; . "' - not triggering wake-up program this time";
} }
@ -1106,8 +1109,10 @@ sub RESIDENTStk_wakeupRun($;$) {
Log3 $NAME, 4, Log3 $NAME, 4,
"RESIDENTStk $NAME: trigger $wakeupMacro (running=1)"; "RESIDENTStk $NAME: trigger $wakeupMacro (running=1)";
fhem fhem
"trigger $wakeupMacro start $lastRun $wakeupOffset $wakeupEnforced $wakeupUserdevice"; "trigger $wakeupMacro start $lastRun $wakeupOffset $wakeupEnforced $wakeupUserdevice $wakeupUserdeviceState";
# Update user device with last wakeup details
#
readingsBeginUpdate( $defs{$wakeupUserdevice} ); readingsBeginUpdate( $defs{$wakeupUserdevice} );
readingsBulkUpdate( $defs{$wakeupUserdevice}, readingsBulkUpdate( $defs{$wakeupUserdevice},
"lastWakeup", $lastRun ); "lastWakeup", $lastRun );
@ -1142,6 +1147,24 @@ sub RESIDENTStk_wakeupRun($;$) {
} }
} }
# Update user device with next wakeup details
#
readingsBeginUpdate( $defs{$wakeupUserdevice} );
my ( $nextWakeupDev, $nextWakeup ) =
RESIDENTStk_wakeupGetNext($wakeupUserdevice);
if ( !$nextWakeupDev || !$nextWakeup ) {
$nextWakeupDev = "none";
$nextWakeup = "OFF";
}
readingsBulkUpdate( $defs{$wakeupUserdevice},
"nextWakeupDev", $nextWakeupDev )
if ( ReadingsVal( $defs{$wakeupUserdevice}, "nextWakeupDev", 0 ) ne
$nextWakeupDev );
readingsBulkUpdate( $defs{$wakeupUserdevice}, "nextWakeup", $nextWakeup )
if ( ReadingsVal( $defs{$wakeupUserdevice}, "nextWakeup", 0 ) ne
$nextWakeup );
readingsEndUpdate( $defs{$wakeupUserdevice}, 1 );
if ( $running && $wakeupOffset > 0 ) { if ( $running && $wakeupOffset > 0 ) {
readingsBeginUpdate( $defs{$NAME} ); readingsBeginUpdate( $defs{$NAME} );
readingsBulkUpdate( $defs{$NAME}, "running", "1" ) readingsBulkUpdate( $defs{$NAME}, "running", "1" )