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