RESIDENTS,ROOMMATE,GUEST: allow wakeup attributes to be used as readings

git-svn-id: https://svn.fhem.de/fhem/trunk@13997 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
jpawlowski 2017-04-15 10:58:10 +00:00
parent 9075adab17
commit cdd17c8e13
4 changed files with 135 additions and 113 deletions

View File

@ -569,7 +569,11 @@ sub RESIDENTS_Set($@) {
# create # create
elsif ( $a[1] eq "create" ) { elsif ( $a[1] eq "create" ) {
if ( defined( $a[2] ) && $a[2] eq "wakeuptimer" ) { if ( !defined( $a[2] ) || $a[2] !~ /^(wakeuptimer)$/i ) {
return
"Invalid 2nd argument, choose one of wakeuptimer ";
}
elsif ( $a[2] eq "wakeuptimer" ) {
my $i = "1"; my $i = "1";
my $wakeuptimerName = $name . "_wakeuptimer" . $i; my $wakeuptimerName = $name . "_wakeuptimer" . $i;
my $created = 0; my $created = 0;
@ -596,7 +600,7 @@ sub RESIDENTS_Set($@) {
fhem "attr $wakeuptimerName room " . $attr{$name}{room} fhem "attr $wakeuptimerName room " . $attr{$name}{room}
if ( defined( $attr{$name}{room} ) ); if ( defined( $attr{$name}{room} ) );
fhem fhem
"attr $wakeuptimerName setList nextRun:OFF,00:00,00:15,00:30,00:45,01:00,01:15,01:30,01:45,02:00,02:15,02:30,02:45,03:00,03:15,03:30,03:45,04:00,04:15,04:30,04:45,05:00,05:15,05:30,05:45,06:00,06:15,06:30,06:45,07:00,07:15,07:30,07:45,08:00,08:15,08:30,08:45,09:00,09:15,09:30,09:45,10:00,10:15,10:30,10:45,11:00,11:15,11:30,11:45,12:00,12:15,12:30,12:45,13:00,13:15,13:30,13:45,14:00,14:15,14:30,14:45,15:00,15:15,15:30,15:45,16:00,16:15,16:30,16:45,17:00,17:15,17:30,17:45,18:00,18:15,18:30,18:45,19:00,19:15,19:30,19:45,20:00,20:15,20:30,20:45,21:00,21:15,21:30,21:45,22:00,22:15,22:30,22:45,23:00,23:15,23:30,23:45 reset:noArg trigger:noArg start:noArg stop:noArg end:noArg"; "attr $wakeuptimerName setList nextRun:OFF,00:00,00:15,00:30,00:45,01:00,01:15,01:30,01:45,02:00,02:15,02:30,02:45,03:00,03:15,03:30,03:45,04:00,04:15,04:30,04:45,05:00,05:15,05:30,05:45,06:00,06:15,06:30,06:45,07:00,07:15,07:30,07:45,08:00,08:15,08:30,08:45,09:00,09:15,09:30,09:45,10:00,10:15,10:30,10:45,11:00,11:15,11:30,11:45,12:00,12:15,12:30,12:45,13:00,13:15,13:30,13:45,14:00,14:15,14:30,14:45,15:00,15:15,15:30,15:45,16:00,16:15,16:30,16:45,17:00,17:15,17:30,17:45,18:00,18:15,18:30,18:45,19:00,19:15,19:30,19:45,20:00,20:15,20:30,20:45,21:00,21:15,21:30,21:45,22:00,22:15,22:30,22:45,23:00,23:15,23:30,23:45 reset:noArg trigger:noArg start:noArg stop:noArg end:noArg wakeupDefaultTime:OFF,00:00,00:15,00:30,00:45,01:00,01:15,01:30,01:45,02:00,02:15,02:30,02:45,03:00,03:15,03:30,03:45,04:00,04:15,04:30,04:45,05:00,05:15,05:30,05:45,06:00,06:15,06:30,06:45,07:00,07:15,07:30,07:45,08:00,08:15,08:30,08:45,09:00,09:15,09:30,09:45,10:00,10:15,10:30,10:45,11:00,11:15,11:30,11:45,12:00,12:15,12:30,12:45,13:00,13:15,13:30,13:45,14:00,14:15,14:30,14:45,15:00,15:15,15:30,15:45,16:00,16:15,16:30,16:45,17:00,17:15,17:30,17:45,18:00,18:15,18:30,18:45,19:00,19:15,19:30,19:45,20:00,20:15,20:30,20:45,21:00,21:15,21:30,21:45,22:00,22:15,22:30,22:45,23:00,23:15,23:30,23:45 wakeupResetdays:multiple-strict,0,1,2,3,4,5,6 wakeupDays:multiple-strict,0,1,2,3,4,5,6 wakeupHolidays:,andHoliday,orHoliday,andNoHoliday,orNoHoliday wakeupEnforced:0,1,2,3";
fhem "attr $wakeuptimerName userattr wakeupUserdevice"; fhem "attr $wakeuptimerName userattr wakeupUserdevice";
fhem "attr $wakeuptimerName sortby " . $sortby fhem "attr $wakeuptimerName sortby " . $sortby
if ($sortby); if ($sortby);
@ -625,9 +629,6 @@ sub RESIDENTS_Set($@) {
return return
"Dummy $wakeuptimerName and other pending devices created and pre-configured.\nYou may edit Macro_$wakeuptimerName to define your wake-up actions\nand at_$wakeuptimerName for optional at-device adjustments."; "Dummy $wakeuptimerName and other pending devices created and pre-configured.\nYou may edit Macro_$wakeuptimerName to define your wake-up actions\nand at_$wakeuptimerName for optional at-device adjustments.";
} }
else {
return "Invalid 2nd argument, choose one of wakeuptimer ";
}
} }
# return usage hint # return usage hint

View File

@ -857,7 +857,7 @@ sub GUEST_Set($@) {
# create # create
elsif ( lc( $a[1] ) eq "create" ) { elsif ( lc( $a[1] ) eq "create" ) {
if ( !defined( $a[2] ) ) { if ( !defined( $a[2] ) || $a[2] !~ /^(wakeuptimer|locationMap)$/i ) {
return return
"Invalid 2nd argument, choose one of wakeuptimer locationMap "; "Invalid 2nd argument, choose one of wakeuptimer locationMap ";
} }
@ -888,7 +888,7 @@ sub GUEST_Set($@) {
fhem "attr $wakeuptimerName room " . $attr{$name}{room} fhem "attr $wakeuptimerName room " . $attr{$name}{room}
if ( defined( $attr{$name}{room} ) ); if ( defined( $attr{$name}{room} ) );
fhem fhem
"attr $wakeuptimerName setList nextRun:OFF,00:00,00:15,00:30,00:45,01:00,01:15,01:30,01:45,02:00,02:15,02:30,02:45,03:00,03:15,03:30,03:45,04:00,04:15,04:30,04:45,05:00,05:15,05:30,05:45,06:00,06:15,06:30,06:45,07:00,07:15,07:30,07:45,08:00,08:15,08:30,08:45,09:00,09:15,09:30,09:45,10:00,10:15,10:30,10:45,11:00,11:15,11:30,11:45,12:00,12:15,12:30,12:45,13:00,13:15,13:30,13:45,14:00,14:15,14:30,14:45,15:00,15:15,15:30,15:45,16:00,16:15,16:30,16:45,17:00,17:15,17:30,17:45,18:00,18:15,18:30,18:45,19:00,19:15,19:30,19:45,20:00,20:15,20:30,20:45,21:00,21:15,21:30,21:45,22:00,22:15,22:30,22:45,23:00,23:15,23:30,23:45 reset:noArg trigger:noArg start:noArg stop:noArg end:noArg"; "attr $wakeuptimerName setList nextRun:OFF,00:00,00:15,00:30,00:45,01:00,01:15,01:30,01:45,02:00,02:15,02:30,02:45,03:00,03:15,03:30,03:45,04:00,04:15,04:30,04:45,05:00,05:15,05:30,05:45,06:00,06:15,06:30,06:45,07:00,07:15,07:30,07:45,08:00,08:15,08:30,08:45,09:00,09:15,09:30,09:45,10:00,10:15,10:30,10:45,11:00,11:15,11:30,11:45,12:00,12:15,12:30,12:45,13:00,13:15,13:30,13:45,14:00,14:15,14:30,14:45,15:00,15:15,15:30,15:45,16:00,16:15,16:30,16:45,17:00,17:15,17:30,17:45,18:00,18:15,18:30,18:45,19:00,19:15,19:30,19:45,20:00,20:15,20:30,20:45,21:00,21:15,21:30,21:45,22:00,22:15,22:30,22:45,23:00,23:15,23:30,23:45 reset:noArg trigger:noArg start:noArg stop:noArg end:noArg wakeupDefaultTime:OFF,00:00,00:15,00:30,00:45,01:00,01:15,01:30,01:45,02:00,02:15,02:30,02:45,03:00,03:15,03:30,03:45,04:00,04:15,04:30,04:45,05:00,05:15,05:30,05:45,06:00,06:15,06:30,06:45,07:00,07:15,07:30,07:45,08:00,08:15,08:30,08:45,09:00,09:15,09:30,09:45,10:00,10:15,10:30,10:45,11:00,11:15,11:30,11:45,12:00,12:15,12:30,12:45,13:00,13:15,13:30,13:45,14:00,14:15,14:30,14:45,15:00,15:15,15:30,15:45,16:00,16:15,16:30,16:45,17:00,17:15,17:30,17:45,18:00,18:15,18:30,18:45,19:00,19:15,19:30,19:45,20:00,20:15,20:30,20:45,21:00,21:15,21:30,21:45,22:00,22:15,22:30,22:45,23:00,23:15,23:30,23:45 wakeupResetdays:multiple-strict,0,1,2,3,4,5,6 wakeupDays:multiple-strict,0,1,2,3,4,5,6 wakeupHolidays:,andHoliday,orHoliday,andNoHoliday,orNoHoliday wakeupEnforced:0,1,2,3";
fhem "attr $wakeuptimerName userattr wakeupUserdevice"; fhem "attr $wakeuptimerName userattr wakeupUserdevice";
fhem "attr $wakeuptimerName sortby " . $sortby fhem "attr $wakeuptimerName sortby " . $sortby
if ($sortby); if ($sortby);

View File

@ -839,7 +839,7 @@ sub ROOMMATE_Set($@) {
# create # create
elsif ( lc( $a[1] ) eq "create" ) { elsif ( lc( $a[1] ) eq "create" ) {
if ( !defined( $a[2] ) ) { if ( !defined( $a[2] ) || $a[2] !~ /^(wakeuptimer|locationMap)$/i ) {
return return
"Invalid 2nd argument, choose one of wakeuptimer locationMap "; "Invalid 2nd argument, choose one of wakeuptimer locationMap ";
} }
@ -870,7 +870,7 @@ sub ROOMMATE_Set($@) {
fhem "attr $wakeuptimerName room " . $attr{$name}{room} fhem "attr $wakeuptimerName room " . $attr{$name}{room}
if ( defined( $attr{$name}{room} ) ); if ( defined( $attr{$name}{room} ) );
fhem fhem
"attr $wakeuptimerName setList nextRun:OFF,00:00,00:15,00:30,00:45,01:00,01:15,01:30,01:45,02:00,02:15,02:30,02:45,03:00,03:15,03:30,03:45,04:00,04:15,04:30,04:45,05:00,05:15,05:30,05:45,06:00,06:15,06:30,06:45,07:00,07:15,07:30,07:45,08:00,08:15,08:30,08:45,09:00,09:15,09:30,09:45,10:00,10:15,10:30,10:45,11:00,11:15,11:30,11:45,12:00,12:15,12:30,12:45,13:00,13:15,13:30,13:45,14:00,14:15,14:30,14:45,15:00,15:15,15:30,15:45,16:00,16:15,16:30,16:45,17:00,17:15,17:30,17:45,18:00,18:15,18:30,18:45,19:00,19:15,19:30,19:45,20:00,20:15,20:30,20:45,21:00,21:15,21:30,21:45,22:00,22:15,22:30,22:45,23:00,23:15,23:30,23:45 reset:noArg trigger:noArg start:noArg stop:noArg end:noArg"; "attr $wakeuptimerName setList nextRun:OFF,00:00,00:15,00:30,00:45,01:00,01:15,01:30,01:45,02:00,02:15,02:30,02:45,03:00,03:15,03:30,03:45,04:00,04:15,04:30,04:45,05:00,05:15,05:30,05:45,06:00,06:15,06:30,06:45,07:00,07:15,07:30,07:45,08:00,08:15,08:30,08:45,09:00,09:15,09:30,09:45,10:00,10:15,10:30,10:45,11:00,11:15,11:30,11:45,12:00,12:15,12:30,12:45,13:00,13:15,13:30,13:45,14:00,14:15,14:30,14:45,15:00,15:15,15:30,15:45,16:00,16:15,16:30,16:45,17:00,17:15,17:30,17:45,18:00,18:15,18:30,18:45,19:00,19:15,19:30,19:45,20:00,20:15,20:30,20:45,21:00,21:15,21:30,21:45,22:00,22:15,22:30,22:45,23:00,23:15,23:30,23:45 reset:noArg trigger:noArg start:noArg stop:noArg end:noArg wakeupDefaultTime:OFF,00:00,00:15,00:30,00:45,01:00,01:15,01:30,01:45,02:00,02:15,02:30,02:45,03:00,03:15,03:30,03:45,04:00,04:15,04:30,04:45,05:00,05:15,05:30,05:45,06:00,06:15,06:30,06:45,07:00,07:15,07:30,07:45,08:00,08:15,08:30,08:45,09:00,09:15,09:30,09:45,10:00,10:15,10:30,10:45,11:00,11:15,11:30,11:45,12:00,12:15,12:30,12:45,13:00,13:15,13:30,13:45,14:00,14:15,14:30,14:45,15:00,15:15,15:30,15:45,16:00,16:15,16:30,16:45,17:00,17:15,17:30,17:45,18:00,18:15,18:30,18:45,19:00,19:15,19:30,19:45,20:00,20:15,20:30,20:45,21:00,21:15,21:30,21:45,22:00,22:15,22:30,22:45,23:00,23:15,23:30,23:45 wakeupResetdays:multiple-strict,0,1,2,3,4,5,6 wakeupDays:multiple-strict,0,1,2,3,4,5,6 wakeupHolidays:,andHoliday,orHoliday,andNoHoliday,orNoHoliday wakeupEnforced:0,1,2,3";
fhem "attr $wakeuptimerName userattr wakeupUserdevice"; fhem "attr $wakeuptimerName userattr wakeupUserdevice";
fhem "attr $wakeuptimerName sortby " . $sortby fhem "attr $wakeuptimerName sortby " . $sortby
if ($sortby); if ($sortby);

View File

@ -36,45 +36,50 @@ sub RESIDENTStk_Initialize() {
# Enslave DUMMY device to be used for alarm clock # Enslave DUMMY device to be used for alarm clock
# #
sub RESIDENTStk_wakeupSet($$) { sub RESIDENTStk_wakeupSet($$) {
my ( $NAME, $notifyValue ) = @_; my ( $NAME, $n ) = @_;
my $VALUE; my ( $a, $h ) = parseParams($n);
my $cmd = shift @$a;
my $VALUE = join( " ", @$a );
my $nextRun = ReadingsVal( $NAME, "nextRun", "07:00" );
# filter non-registered notifies # filter non-registered notifies
my @notify = split / /, $notifyValue; if ( $cmd !~
if ( $notify[0] !~ m/^((?:next[rR]un)?\s*(off|OFF|([\+\-])?(([0-9]{2}):([0-9]{2})|([1-9]+[0-9]*)))?|trigger|start|stop|end|reset|auto|wakeupResetdays|wakeupDays|wakeupHolidays|wakeupEnforced|wakeupDefaultTime)$/i
m/^(off|nextrun|trigger|start|stop|end|reset|auto|[\+\-][1-9]*[0-9]*|[\+\-]?[0-9]{2}:[0-9]{2})$/i
) )
{ {
Log3 $NAME, 6, Log3 $NAME, 6,
"RESIDENTStk $NAME: " "RESIDENTStk $NAME: "
. "received unspecified notify '" . "received unspecified notify '"
. $notify[0] . $cmd
. "' - nothing to do"; . "' - nothing to do";
fhem "set $NAME nextRun $nextRun";
return; return;
} }
elsif ( lc( $notify[0] ) eq "nextrun" ) {
return if ( !defined( $notify[1] ) );
$VALUE = $notify[1];
}
else {
$VALUE = $notify[0];
}
my $wakeupMacro = AttrVal( $NAME, "wakeupMacro", 0 ); my $wakeupMacro = AttrVal( $NAME, "wakeupMacro", 0 );
my $wakeupDefaultTime = AttrVal( $NAME, "wakeupDefaultTime", 0 ); my $wakeupDefaultTime =
my $wakeupAtdevice = AttrVal( $NAME, "wakeupAtdevice", 0 ); ReadingsVal( $NAME, "wakeupDefaultTime",
my $wakeupUserdevice = AttrVal( $NAME, "wakeupUserdevice", 0 ); AttrVal( $NAME, "wakeupDefaultTime", 0 ) );
my $wakeupDays = AttrVal( $NAME, "wakeupDays", "" ); my $wakeupAtdevice = AttrVal( $NAME, "wakeupAtdevice", 0 );
my $wakeupHolidays = AttrVal( $NAME, "wakeupHolidays", 0 ); my $wakeupUserdevice = AttrVal( $NAME, "wakeupUserdevice", 0 );
my $wakeupResetdays = AttrVal( $NAME, "wakeupResetdays", "" ); my $wakeupDays =
my $wakeupOffset = AttrVal( $NAME, "wakeupOffset", 0 ); ReadingsVal( $NAME, "wakeupDays", AttrVal( $NAME, "wakeupDays", "" ) );
my $wakeupEnforced = AttrVal( $NAME, "wakeupEnforced", 0 ); my $wakeupHolidays =
ReadingsVal( $NAME, "wakeupHolidays",
AttrVal( $NAME, "wakeupHolidays", "" ) );
my $wakeupResetdays =
ReadingsVal( $NAME, "wakeupResetdays",
AttrVal( $NAME, "wakeupResetdays", "" ) );
my $wakeupOffset = AttrVal( $NAME, "wakeupOffset", 0 );
my $wakeupEnforced =
ReadingsVal( $NAME, "wakeupEnforced",
AttrVal( $NAME, "wakeupEnforced", 0 ) );
my $wakeupResetSwitcher = AttrVal( $NAME, "wakeupResetSwitcher", 0 ); my $wakeupResetSwitcher = AttrVal( $NAME, "wakeupResetSwitcher", 0 );
my $holidayDevice = AttrVal( "global", "holiday2we", 0 ); my $holidayDevice = AttrVal( "global", "holiday2we", 0 );
my $room = AttrVal( $NAME, "room", 0 ); my $room = AttrVal( $NAME, "room", 0 );
my $userattr = AttrVal( $NAME, "userattr", 0 ); my $userattr = AttrVal( $NAME, "userattr", 0 );
my $lastRun = ReadingsVal( $NAME, "lastRun", "07:00" ); my $lastRun = ReadingsVal( $NAME, "lastRun", "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 $wakeupUserdeviceState = ReadingsVal( $wakeupUserdevice, "state", 0 );
my $atName = "at_" . $NAME; my $atName = "at_" . $NAME;
@ -718,7 +723,7 @@ return;;\
} }
# verify holiday2we attribute # verify holiday2we attribute
if ($wakeupHolidays) { if ( $wakeupHolidays ne "" ) {
if ( !$holidayDevice ) { if ( !$holidayDevice ) {
Log3 $NAME, 3, Log3 $NAME, 3,
"RESIDENTStk $NAME: " "RESIDENTStk $NAME: "
@ -744,22 +749,26 @@ return;;\
# start # start
# #
if ( $VALUE eq "start" ) { if ( $cmd eq "start" ) {
RESIDENTStk_wakeupRun( $NAME, 1 ); RESIDENTStk_wakeupRun( $NAME, 1 );
} }
# trigger # trigger
# #
elsif ( $VALUE eq "trigger" ) { elsif ( $cmd eq "trigger" ) {
RESIDENTStk_wakeupRun($NAME); RESIDENTStk_wakeupRun($NAME);
} }
# stop | end # stop | end
# #
elsif ( ( $VALUE eq "stop" || $VALUE eq "end" ) && $running ) { elsif ( $cmd eq "stop" || $cmd eq "end" ) {
Log3 $NAME, 4, "RESIDENTStk $NAME: " . "stopping wake-up program"; if ($running) {
readingsSingleUpdate( $defs{$NAME}, "running", "0", 1 ); Log3 $NAME, 4, "RESIDENTStk $NAME: " . "stopping wake-up program";
readingsSingleUpdate( $defs{$NAME}, "running", "0", 1 );
}
fhem "set $NAME nextRun $nextRun"; fhem "set $NAME nextRun $nextRun";
return unless ($running);
# trigger macro again so it may clean up it's stuff. # trigger macro again so it may clean up it's stuff.
# use $EVTPART1 to check # use $EVTPART1 to check
@ -791,7 +800,7 @@ return;;\
$wakeupEnforced = 0; $wakeupEnforced = 0;
} }
if ( defined( $notify[1] ) || $VALUE eq "end" ) { if ( $VALUE ne "" || $cmd eq "end" ) {
Log3 $NAME, 4, Log3 $NAME, 4,
"RESIDENTStk $NAME: " "RESIDENTStk $NAME: "
. "trigger $wakeupMacro stop $lastRun $wakeupOffset $wakeupEnforced $wakeupUserdevice $wakeupUserdeviceState"; . "trigger $wakeupMacro stop $lastRun $wakeupOffset $wakeupEnforced $wakeupUserdevice $wakeupUserdeviceState";
@ -819,21 +828,18 @@ return;;\
# auto or reset # auto or reset
# #
elsif ($VALUE eq "auto" elsif ( $cmd eq "auto" || $cmd eq "reset" ) {
|| $VALUE eq "reset"
|| $VALUE =~ /^NaN:|:NaN$/ )
{
my $resetTime = ReadingsVal( $NAME, "lastRun", 0 ); my $resetTime = ReadingsVal( $NAME, "lastRun", 0 );
if ($wakeupDefaultTime) { if ($wakeupDefaultTime) {
$resetTime = $wakeupDefaultTime; $resetTime = $wakeupDefaultTime;
} }
if ( $resetTime if ( $resetTime
&& !( $VALUE eq "auto" && lc($resetTime) eq "off" ) ) && !( $cmd eq "auto" && lc($resetTime) eq "off" ) )
{ {
fhem "set $NAME:FILTER=state!=$resetTime nextRun $resetTime"; fhem "set $NAME:FILTER=state!=$resetTime nextRun $resetTime";
} }
elsif ( $VALUE eq "reset" ) { elsif ( $cmd eq "reset" ) {
Log3 $NAME, 4, Log3 $NAME, 4,
"RESIDENTStk $NAME: " "RESIDENTStk $NAME: "
. "no default value specified in attribute wakeupDefaultTime, just keeping setting OFF"; . "no default value specified in attribute wakeupDefaultTime, just keeping setting OFF";
@ -843,21 +849,34 @@ return;;\
return; return;
} }
# set new wakeup value # wakeup attributes
elsif ( #
( elsif ( $cmd =~
lc($VALUE) eq "off" m/^(wakeupResetdays|wakeupDays|wakeupHolidays|wakeupEnforced|wakeupDefaultTime)$/
|| $VALUE =~ /^[\+\-][1-9]*[0-9]*$/
|| $VALUE =~ /^[\+\-]?([0-9]{2}):([0-9]{2})$/
)
&& IsDevice( $wakeupAtdevice, "at" )
) )
{ {
Log3 $NAME, 4, "RESIDENTStk $NAME: " . "setting $1 to '$VALUE'";
if ( $VALUE =~ /^[\+\-]/ ) { readingsBeginUpdate( $defs{$NAME} );
$VALUE = readingsBulkUpdate( $defs{$NAME}, $1, $VALUE );
RESIDENTStk_TimeSum( ReadingsVal( $NAME, "nextRun", 0 ), $VALUE ); readingsEndUpdate( $defs{$NAME}, 1 );
}
fhem "set $NAME nextRun $nextRun";
return;
}
# set new wakeup value
elsif ( IsDevice( $wakeupAtdevice, "at" )
&& $cmd =~
m/^(?:nextRun)?\s*(OFF|([\+\-])?(([0-9]{2}):([0-9]{2})|([1-9]+[0-9]*)))?$/i
)
{
$VALUE = $1 if ( $1 && $1 ne "" );
$VALUE =
RESIDENTStk_TimeSum( ReadingsVal( $NAME, "nextRun", 0 ), $VALUE )
if ($2);
# Update wakeuptimer device # Update wakeuptimer device
# #
@ -908,9 +927,11 @@ return;;\
sub RESIDENTStk_wakeupGetBegin($;$) { sub RESIDENTStk_wakeupGetBegin($;$) {
my ( $NAME, $wakeupAtdevice ) = @_; my ( $NAME, $wakeupAtdevice ) = @_;
my $nextRun = ReadingsVal( $NAME, "nextRun", 0 ); my $nextRun = ReadingsVal( $NAME, "nextRun", 0 );
my $wakeupDefaultTime = AttrVal( $NAME, "wakeupDefaultTime", 0 ); my $wakeupDefaultTime =
my $wakeupOffset = AttrVal( $NAME, "wakeupOffset", 0 ); ReadingsVal( $NAME, "wakeupDefaultTime",
my $wakeupInitTime = ( AttrVal( $NAME, "wakeupDefaultTime", 0 ) );
my $wakeupOffset = AttrVal( $NAME, "wakeupOffset", 0 );
my $wakeupInitTime = (
$wakeupDefaultTime && lc($wakeupDefaultTime) ne "off" $wakeupDefaultTime && lc($wakeupDefaultTime) ne "off"
? $wakeupDefaultTime ? $wakeupDefaultTime
: "05:00" : "05:00"
@ -992,15 +1013,24 @@ sub RESIDENTStk_wakeupGetBegin($;$) {
sub RESIDENTStk_wakeupRun($;$) { sub RESIDENTStk_wakeupRun($;$) {
my ( $NAME, $forceRun ) = @_; my ( $NAME, $forceRun ) = @_;
my $wakeupMacro = AttrVal( $NAME, "wakeupMacro", 0 ); my $wakeupMacro = AttrVal( $NAME, "wakeupMacro", 0 );
my $wakeupDefaultTime = AttrVal( $NAME, "wakeupDefaultTime", 0 ); my $wakeupDefaultTime =
my $wakeupAtdevice = AttrVal( $NAME, "wakeupAtdevice", 0 ); ReadingsVal( $NAME, "wakeupDefaultTime",
my $wakeupUserdevice = AttrVal( $NAME, "wakeupUserdevice", 0 ); AttrVal( $NAME, "wakeupDefaultTime", 0 ) );
my $wakeupDays = AttrVal( $NAME, "wakeupDays", "" ); my $wakeupAtdevice = AttrVal( $NAME, "wakeupAtdevice", 0 );
my $wakeupHolidays = AttrVal( $NAME, "wakeupHolidays", 0 ); my $wakeupUserdevice = AttrVal( $NAME, "wakeupUserdevice", 0 );
my $wakeupResetdays = AttrVal( $NAME, "wakeupResetdays", "" ); my $wakeupDays =
my $wakeupOffset = AttrVal( $NAME, "wakeupOffset", 0 ); ReadingsVal( $NAME, "wakeupDays", AttrVal( $NAME, "wakeupDays", "" ) );
my $wakeupEnforced = AttrVal( $NAME, "wakeupEnforced", 0 ); my $wakeupHolidays =
ReadingsVal( $NAME, "wakeupHolidays",
AttrVal( $NAME, "wakeupHolidays", "" ) );
my $wakeupResetdays =
ReadingsVal( $NAME, "wakeupResetdays",
AttrVal( $NAME, "wakeupResetdays", "" ) );
my $wakeupOffset = AttrVal( $NAME, "wakeupOffset", 0 );
my $wakeupEnforced =
ReadingsVal( $NAME, "wakeupEnforced",
AttrVal( $NAME, "wakeupEnforced", 0 ) );
my $wakeupResetSwitcher = AttrVal( $NAME, "wakeupResetSwitcher", 0 ); my $wakeupResetSwitcher = AttrVal( $NAME, "wakeupResetSwitcher", 0 );
my $wakeupWaitPeriod = AttrVal( $NAME, "wakeupWaitPeriod", 360 ); my $wakeupWaitPeriod = AttrVal( $NAME, "wakeupWaitPeriod", 360 );
my $holidayDevice = AttrVal( "global", "holiday2we", 0 ); my $holidayDevice = AttrVal( "global", "holiday2we", 0 );
@ -1011,20 +1041,16 @@ sub RESIDENTStk_wakeupRun($;$) {
my $room = AttrVal( $NAME, "room", 0 ); my $room = AttrVal( $NAME, "room", 0 );
my $running = 0; my $running = 0;
my $preventRun = 0; my $preventRun = 0;
my $holidayToday = ""; my $holidayToday = 0;
if ( $wakeupHolidays if ( $wakeupHolidays ne ""
&& IsDevice( $holidayDevice, "holiday" ) ) && IsDevice( $holidayDevice, "holiday" ) )
{ {
my $hdayTod = ReadingsVal( $holidayDevice, "state", "" ); $holidayToday = 1
unless ( ReadingsVal( $holidayDevice, "state", "none" ) eq "none" );
if ( $hdayTod ne "none" && $hdayTod ne "" ) {
$holidayToday = 1;
}
else { $holidayToday = 0 }
} }
else { else {
$wakeupHolidays = 0; $wakeupHolidays = "";
} }
my ( $sec, $min, $hour, $mday, $mon, $year, $today, $yday, $isdst ) = my ( $sec, $min, $hour, $mday, $mon, $year, $today, $yday, $isdst ) =
@ -1098,14 +1124,16 @@ sub RESIDENTStk_wakeupRun($;$) {
fhem "set $NAME nextRun OFF"; fhem "set $NAME nextRun OFF";
return; return;
} }
elsif ( !$wakeupHolidays && !$days{$today} && !$forceRun ) { elsif ($wakeupHolidays eq ""
&& !$days{$today}
&& !$forceRun )
{
Log3 $NAME, 4, Log3 $NAME, 4,
"RESIDENTStk $NAME: " "RESIDENTStk $NAME: "
. "weekday restriction in use - not triggering wake-up program this time"; . "weekday restriction in use - not triggering wake-up program this time";
} }
elsif ( elsif (
$wakeupHolidays !$forceRun
&& !$forceRun
&& ( $wakeupHolidays eq "orHoliday" && ( $wakeupHolidays eq "orHoliday"
|| $wakeupHolidays eq "orNoHoliday" ) || $wakeupHolidays eq "orNoHoliday" )
&& ( && (
@ -1123,8 +1151,7 @@ sub RESIDENTStk_wakeupRun($;$) {
. "neither weekday nor holiday restriction matched - not triggering wake-up program this time"; . "neither weekday nor holiday restriction matched - not triggering wake-up program this time";
} }
elsif ( elsif (
$wakeupHolidays !$forceRun
&& !$forceRun
&& ( $wakeupHolidays eq "andHoliday" && ( $wakeupHolidays eq "andHoliday"
|| $wakeupHolidays eq "andNoHoliday" ) || $wakeupHolidays eq "andNoHoliday" )
&& ( && (
@ -1400,8 +1427,6 @@ sub RESIDENTStk_wakeupGetNext($;$) {
my $definitiveNextTomorrowDev = 0; my $definitiveNextTomorrowDev = 0;
my $holidayDevice = AttrVal( "global", "holiday2we", 0 ); my $holidayDevice = AttrVal( "global", "holiday2we", 0 );
my $hdayTod = ReadingsVal( $holidayDevice, "state", "" );
my $hdayTom = ReadingsVal( $holidayDevice, "tomorrow", "" );
# check for each registered wake-up device # check for each registered wake-up device
for my $wakeupDevice ( split /,/, $wakeupDeviceList ) { for my $wakeupDevice ( split /,/, $wakeupDeviceList ) {
@ -1449,22 +1474,26 @@ sub RESIDENTStk_wakeupGetNext($;$) {
? substr( $defs{$wakeupAtdevice}{NTM}, 0, -3 ) ? substr( $defs{$wakeupAtdevice}{NTM}, 0, -3 )
: 0 : 0
); );
my $wakeupDays = AttrVal( $wakeupDevice, "wakeupDays", "" ); my $wakeupDays =
my $wakeupHolidays = AttrVal( $wakeupDevice, "wakeupHolidays", 0 ); ReadingsVal( $wakeupDevice, "wakeupDays",
my $holidayToday = 0; AttrVal( $wakeupDevice, "wakeupDays", "" ) );
my $wakeupHolidays =
ReadingsVal( $wakeupDevice, "wakeupHolidays",
AttrVal( $wakeupDevice, "wakeupHolidays", "" ) );
my $holidayToday = 0;
my $holidayTomorrow = 0; my $holidayTomorrow = 0;
my $nextRunSrc; my $nextRunSrc;
# get holiday status for today and tomorrow # get holiday status for today and tomorrow
if ( $wakeupHolidays if ( $wakeupHolidays ne ""
&& IsDevice( $holidayDevice, "holiday" ) ) && IsDevice( $holidayDevice, "holiday" ) )
{ {
if ( $hdayTod ne "none" && $hdayTod ne "" ) { $holidayToday = 1
$holidayToday = 1; unless (
} ReadingsVal( $holidayDevice, "state", "none" ) eq "none" );
if ( $hdayTom ne "none" && $hdayTom ne "" ) { $holidayTomorrow = 1
$holidayTomorrow = 1; unless (
} ReadingsVal( $holidayDevice, "tomorrow", "none" ) eq "none" );
Log3 $name, 4, Log3 $name, 4,
"RESIDENTStk $wakeupDevice: " "RESIDENTStk $wakeupDevice: "
@ -1560,8 +1589,7 @@ sub RESIDENTStk_wakeupGetNext($;$) {
# if we need to consider holidays in addition # if we need to consider holidays in addition
if ( if (
$wakeupHolidays && ( $wakeupHolidays eq "andHoliday" ( $wakeupHolidays eq "andHoliday" && !$holidayToday )
&& !$holidayToday )
|| ( $wakeupHolidays eq "andNoHoliday" || ( $wakeupHolidays eq "andNoHoliday"
&& $holidayToday ) && $holidayToday )
) )
@ -1592,14 +1620,8 @@ sub RESIDENTStk_wakeupGetNext($;$) {
} }
# if we need to consider holidays in parallel to weekdays # if we need to consider holidays in parallel to weekdays
if ( if ( ( $wakeupHolidays eq "orHoliday" && $holidayToday )
$wakeupHolidays || ( $wakeupHolidays eq "orNoHoliday" && !$holidayToday ) )
&& (
( $wakeupHolidays eq "orHoliday" && $holidayToday )
|| ( $wakeupHolidays eq "orNoHoliday"
&& !$holidayToday )
)
)
{ {
Log3 $name, 4, Log3 $name, 4,
@ -1632,8 +1654,10 @@ sub RESIDENTStk_wakeupGetNext($;$) {
# if we need to consider holidays in addition # if we need to consider holidays in addition
if ( if (
$wakeupHolidays && ( $wakeupHolidays eq "andHoliday" (
&& !$holidayTomorrow ) $wakeupHolidays eq "andHoliday"
&& !$holidayTomorrow
)
|| ( $wakeupHolidays eq "andNoHoliday" || ( $wakeupHolidays eq "andNoHoliday"
&& $holidayTomorrow ) && $holidayTomorrow )
) )
@ -1665,12 +1689,9 @@ sub RESIDENTStk_wakeupGetNext($;$) {
# if we need to consider holidays in parallel to weekdays # if we need to consider holidays in parallel to weekdays
if ( if (
$wakeupHolidays ( $wakeupHolidays eq "orHoliday" && $holidayTomorrow )
&& ( || ( $wakeupHolidays eq "orNoHoliday"
( $wakeupHolidays eq "orHoliday" && $holidayTomorrow ) && !$holidayTomorrow )
|| ( $wakeupHolidays eq "orNoHoliday"
&& !$holidayTomorrow )
)
) )
{ {
Log3 $name, 4, Log3 $name, 4,