mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-03 16:56:54 +00:00
98_alarmclock.pm: new readings
git-svn-id: https://svn.fhem.de/fhem/trunk@14491 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
e42f5dd7d9
commit
ddeee003f8
@ -75,6 +75,7 @@ my %alarmday =
|
||||
"0" => "AlarmTime7_Sunday",
|
||||
"8" => "AlarmTime8_Holiday",
|
||||
"9" => "AlarmTime9_Vacation"
|
||||
|
||||
);
|
||||
|
||||
|
||||
@ -172,6 +173,8 @@ sub alarmclock_Define($$)
|
||||
$hash->{helper}{Repeat1} = 0;
|
||||
$hash->{helper}{Repeat2} = 0;
|
||||
$hash->{helper}{Repeat3} = 0;
|
||||
$hash->{helper}{Today} = 0;
|
||||
$hash->{helper}{Tomorrow} = 0;
|
||||
|
||||
return undef;
|
||||
|
||||
@ -515,9 +518,19 @@ sub alarmclock_createtimer($)
|
||||
|
||||
my ($hash) = @_;
|
||||
|
||||
|
||||
my ($SecNow, $MinNow, $HourNow, $DayNow, $MonthNow, $YearNow, $WDayNow, $YDNow, $SumTimeNow) = localtime(time);
|
||||
my $alarmtimetoday = $alarmday{$WDayNow};
|
||||
|
||||
$hash->{helper}{Today} = $WDayNow;
|
||||
|
||||
if ($WDayNow =~ /^(0|1|2|3|4|5)/)
|
||||
{
|
||||
$hash->{helper}{Tomorrow} = $WDayNow + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$hash->{helper}{Tomorrow} = 0;
|
||||
}
|
||||
|
||||
my $HourinSec = $HourNow * 3600;
|
||||
my $MininSec = $MinNow * 60;
|
||||
my $NowinSec = $HourinSec + $MininSec + $SecNow;
|
||||
@ -529,16 +542,13 @@ if ((AttrVal($hash->{NAME}, "disable", 0 ) ne "1" ) && (ReadingsVal($hash->{NAME
|
||||
|
||||
|
||||
### Vacation ###
|
||||
if (alarmclock_vacation_check($hash))
|
||||
{
|
||||
$alarmtimetoday = $alarmday{9};
|
||||
}
|
||||
alarmclock_vacation_check($hash);
|
||||
|
||||
### Holiday ###
|
||||
if (alarmclock_holiday_check($hash))
|
||||
{
|
||||
$alarmtimetoday = $alarmday{8};
|
||||
}
|
||||
alarmclock_holiday_check($hash);
|
||||
|
||||
my $alarmtimetoday = $alarmday{$hash->{helper}{Today}};
|
||||
my $alarmtimetommorow = $alarmday{$hash->{helper}{Tomorrow}};
|
||||
|
||||
|
||||
if ((ReadingsVal($hash->{NAME},$alarmtimetoday,"NONE")) =~ /^([0-1]?[0-9]|2[0-3]):[0-5][0-9]$/)
|
||||
@ -645,12 +655,21 @@ if ((AttrVal($hash->{NAME}, "disable", 0 ) ne "1" ) && (ReadingsVal($hash->{NAME
|
||||
|
||||
### End OffDefaultTime ###
|
||||
|
||||
|
||||
else
|
||||
{
|
||||
alarmclock_midnight_timer($hash);
|
||||
Log3 $hash->{NAME}, 5, "alarmclock: $hash->{NAME} - no alarm today => midnight-timer started";
|
||||
}
|
||||
|
||||
### Alarm Reading ###
|
||||
|
||||
my $AlarmToday = ReadingsVal($hash->{NAME},$alarmtimetoday," ");
|
||||
my $AlarmTomorrow = ReadingsVal($hash->{NAME},$alarmtimetommorow," ");
|
||||
readingsBeginUpdate($hash);
|
||||
readingsBulkUpdate( $hash, "AlarmToday", $AlarmToday);
|
||||
readingsBulkUpdate( $hash, "AlarmTomorrow", $AlarmTomorrow);
|
||||
readingsEndUpdate($hash,1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1084,86 +1103,92 @@ sub alarmclock_holiday_check($)
|
||||
|
||||
my ($hash) = @_;
|
||||
my ($SecNow, $MinNow, $HourNow, $DayNow, $MonthNow, $YearNow, $WDayNow, $YDNow, $SumTimeNow) = localtime(time);
|
||||
|
||||
if ($WDayNow == 0)
|
||||
my $WDayToday = $WDayNow;
|
||||
my $WDayTomorrow = $WDayNow + 1;
|
||||
if ($WDayToday == 0)
|
||||
{
|
||||
$WDayNow = 7;
|
||||
$WDayToday = 7;
|
||||
}
|
||||
|
||||
if ((AttrVal($hash->{NAME}, "HolidayDevice", "NONE" ) ne "NONE" ) && (AttrVal($hash->{NAME}, "HolidayCheck", "1" ) ne "0" ))
|
||||
{
|
||||
my @HolidayDays = split(/\|/, AttrVal($hash->{NAME},"HolidayDays","1|2|3|4|5|6|7"));
|
||||
my $Day = grep {$_==$WDayNow;} @HolidayDays;
|
||||
my $DayToday = grep {$_==$WDayToday;} @HolidayDays;
|
||||
my $DayTomorrow = grep {$_==$WDayTomorrow;} @HolidayDays;
|
||||
my @Holiday = split(/\|/, AttrVal($hash->{NAME},"HolidayDevice",""));
|
||||
my $a = 0;
|
||||
my $b = scalar(@Holiday);
|
||||
|
||||
if ($Day == 1)
|
||||
while ($a < $b)
|
||||
{
|
||||
my @Holiday = split(/\|/, AttrVal($hash->{NAME},"HolidayDevice",""));
|
||||
my @HolidayDevice = split(/:/,$Holiday[$a]);
|
||||
|
||||
my $a = 0;
|
||||
my $b = scalar(@Holiday);
|
||||
|
||||
while ($a < $b)
|
||||
if (scalar(@HolidayDevice) eq "1")
|
||||
{
|
||||
my @HolidayDevice = split(/:/,$Holiday[$a]);
|
||||
|
||||
if (scalar(@HolidayDevice) eq "1")
|
||||
if( IsDevice( $HolidayDevice[0], "holiday" ))
|
||||
{
|
||||
if( IsDevice( $HolidayDevice[0], "holiday" ))
|
||||
my $today = strftime("%2m-%2d", localtime(time));
|
||||
my $tomorrow = strftime("%2m-%2d", localtime(time+86400));
|
||||
my $todayevent = holiday_refresh($HolidayDevice[0],$today);
|
||||
if (($todayevent ne "none") && ($DayToday == 1))
|
||||
{
|
||||
my $today = strftime("%2m-%2d", localtime(time));
|
||||
my $todayevent = holiday_refresh($HolidayDevice[0],$today);
|
||||
if ($todayevent ne "none")
|
||||
{
|
||||
Log3 $hash->{NAME}, 1, "alarmclock: $hash->{NAME} - holiday => $HolidayDevice[0] - $todayevent";
|
||||
return 1;
|
||||
}
|
||||
Log3 $hash->{NAME}, 1, "alarmclock: $hash->{NAME} - holiday => $HolidayDevice[0] - $todayevent";
|
||||
$hash->{helper}{Today} = 8;
|
||||
}
|
||||
elsif( IsDevice($HolidayDevice[0], "Calendar" ))
|
||||
my $tomorrowevent = holiday_refresh($HolidayDevice[0],$tomorrow);
|
||||
if (($tomorrowevent ne "none") && ($DayTomorrow == 1))
|
||||
{
|
||||
my $stoday = strftime("%2d.%2m.%2y", localtime(time));
|
||||
my $line = Calendar_Get($defs{$HolidayDevice[0]},"get","text","mode=alarm|start|upcoming");
|
||||
if ($line)
|
||||
$hash->{helper}{Tomorrow} = 8;
|
||||
}
|
||||
}
|
||||
elsif( IsDevice($HolidayDevice[0], "Calendar" ))
|
||||
{
|
||||
my $stoday = strftime("%2d.%2m.%2y", localtime(time));
|
||||
my $stomorrow = strftime("%2d.%2m.%2y", localtime(time+86400));
|
||||
my $line = Calendar_Get($defs{$HolidayDevice[0]},"get","text","mode=alarm|start|upcoming");
|
||||
if ($line)
|
||||
{
|
||||
chomp($line);
|
||||
my @lines = split('\n',$line);
|
||||
foreach $line (@lines)
|
||||
{
|
||||
chomp($line);
|
||||
my @lines = split('\n',$line);
|
||||
foreach $line (@lines)
|
||||
my $date = substr($line,0,8);
|
||||
if (($date eq $stoday) && ($DayToday == 1))
|
||||
{
|
||||
chomp($line);
|
||||
my $date = substr($line,0,8);
|
||||
if ($date eq $stoday)
|
||||
{
|
||||
my $todaydesc = substr($line,15);
|
||||
Log3 $hash->{NAME}, 1, "alarmclock: $hash->{NAME} - holiday => $HolidayDevice[0] - $todaydesc";
|
||||
return 1;
|
||||
}
|
||||
my $todaydesc = substr($line,15);
|
||||
Log3 $hash->{NAME}, 1, "alarmclock: $hash->{NAME} - holiday => $HolidayDevice[0] - $todaydesc";
|
||||
$hash->{helper}{Today} = 8;
|
||||
}
|
||||
if (($date eq $stomorrow) && ($DayTomorrow == 1))
|
||||
{
|
||||
$hash->{helper}{Tomorrow} = 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
elsif (scalar(@HolidayDevice) eq "2")
|
||||
{
|
||||
if (ReadingsVal($HolidayDevice[0],"state","NONE") eq $HolidayDevice[1])
|
||||
{
|
||||
Log3 $hash->{NAME}, 1, "alarmclock: $hash->{NAME} - holiday => $HolidayDevice[0] - $HolidayDevice[1]";
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
elsif (scalar(@HolidayDevice) eq "3")
|
||||
{
|
||||
my $HolidayEvent = $HolidayDevice[2];
|
||||
$HolidayEvent =~ s/ //g;
|
||||
if (ReadingsVal($HolidayDevice[0],$HolidayDevice[1],"NONE") eq $HolidayEvent)
|
||||
{
|
||||
Log3 $hash->{NAME}, 1, "alarmclock: $hash->{NAME} - holiday => $HolidayDevice[0] - $HolidayDevice[1] - $HolidayEvent";
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
$a ++;
|
||||
}
|
||||
}
|
||||
elsif (scalar(@HolidayDevice) eq "2")
|
||||
{
|
||||
if ((ReadingsVal($HolidayDevice[0],"state","NONE") eq $HolidayDevice[1]) && ($DayToday == 1))
|
||||
{
|
||||
Log3 $hash->{NAME}, 1, "alarmclock: $hash->{NAME} - holiday => $HolidayDevice[0] - $HolidayDevice[1]";
|
||||
$hash->{helper}{Today} = 8;
|
||||
}
|
||||
}
|
||||
elsif (scalar(@HolidayDevice) eq "3")
|
||||
{
|
||||
my $HolidayEvent = $HolidayDevice[2];
|
||||
$HolidayEvent =~ s/ //g;
|
||||
if ((ReadingsVal($HolidayDevice[0],$HolidayDevice[1],"NONE") eq $HolidayEvent) && ($DayToday == 1))
|
||||
{
|
||||
Log3 $hash->{NAME}, 1, "alarmclock: $hash->{NAME} - holiday => $HolidayDevice[0] - $HolidayDevice[1] - $HolidayEvent";
|
||||
$hash->{helper}{Today} = 8;
|
||||
}
|
||||
}
|
||||
$a ++;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -1178,91 +1203,101 @@ sub alarmclock_vacation_check($)
|
||||
|
||||
my ($hash) = @_;
|
||||
my ($SecNow, $MinNow, $HourNow, $DayNow, $MonthNow, $YearNow, $WDayNow, $YDNow, $SumTimeNow) = localtime(time);
|
||||
|
||||
if ($WDayNow == 0)
|
||||
my $WDayToday = $WDayNow;
|
||||
my $WDayTomorrow = $WDayNow + 1;
|
||||
if ($WDayToday == 0)
|
||||
{
|
||||
$WDayNow = 7;
|
||||
$WDayToday = 7;
|
||||
}
|
||||
|
||||
if ((AttrVal($hash->{NAME}, "VacationDevice", "NONE" ) ne "NONE" ) && (AttrVal($hash->{NAME}, "VacationCheck", "1" ) ne "0" ))
|
||||
{
|
||||
|
||||
my @VacationDays = split(/\|/, AttrVal($hash->{NAME},"VacationDays","1|2|3|4|5|6|7"));
|
||||
my $Day = grep {$_==$WDayNow;} @VacationDays;
|
||||
my $DayToday = grep {$_==$WDayToday;} @VacationDays;
|
||||
my $DayTomorrow = grep {$_==$WDayTomorrow;} @VacationDays;
|
||||
my @Vacation = split(/\|/, AttrVal($hash->{NAME},"VacationDevice",""));
|
||||
my $a = 0;
|
||||
my $b = scalar(@Vacation);
|
||||
|
||||
if ($Day == 1)
|
||||
while ($a < $b)
|
||||
{
|
||||
my @Vacation = split(/\|/, AttrVal($hash->{NAME},"VacationDevice",""));
|
||||
my @VacationDevice = split(/:/,$Vacation[$a]);
|
||||
|
||||
my $a = 0;
|
||||
my $b = scalar(@Vacation);
|
||||
|
||||
while ($a < $b)
|
||||
if (scalar(@VacationDevice) eq "1")
|
||||
{
|
||||
my @VacationDevice = split(/:/,$Vacation[$a]);
|
||||
|
||||
if (scalar(@VacationDevice) eq "1")
|
||||
if( IsDevice( $VacationDevice[0], "holiday" ))
|
||||
{
|
||||
if( IsDevice( $VacationDevice[0], "holiday" ))
|
||||
my $today = strftime("%2m-%2d", localtime(time));
|
||||
my $tomorrow = strftime("%2m-%2d", localtime(time+86400));
|
||||
my $todayevent = holiday_refresh($VacationDevice[0],$today);
|
||||
if (($todayevent ne "none") && ($DayToday == 1))
|
||||
{
|
||||
my $today = strftime("%2m-%2d", localtime(time));
|
||||
my $todayevent = holiday_refresh($VacationDevice[0],$today);
|
||||
if ($todayevent ne "none")
|
||||
{
|
||||
Log3 $hash->{NAME}, 1, "alarmclock: $hash->{NAME} - vacation => $VacationDevice[0] - $todayevent";
|
||||
return 1;
|
||||
}
|
||||
Log3 $hash->{NAME}, 1, "alarmclock: $hash->{NAME} - vacation => $VacationDevice[0] - $todayevent";
|
||||
$hash->{helper}{Today} = 9;
|
||||
}
|
||||
elsif( IsDevice($VacationDevice[0], "Calendar" ))
|
||||
my $tomorrowevent = holiday_refresh($VacationDevice[0],$tomorrow);
|
||||
if (($tomorrowevent ne "none") && ($DayTomorrow == 1))
|
||||
{
|
||||
my $stoday = strftime("%2d.%2m.%2y", localtime(time));
|
||||
my @tday = split('\.',$stoday);
|
||||
my $fline = Calendar_Get($defs{$VacationDevice[0]},"get","full","mode=alarm|start|upcoming");
|
||||
my @lines = split('\n',$fline);
|
||||
foreach $fline (@lines)
|
||||
$hash->{helper}{Tomorrow} = 9;
|
||||
}
|
||||
}
|
||||
elsif( IsDevice($VacationDevice[0], "Calendar" ))
|
||||
{
|
||||
my $stoday = strftime("%2d.%2m.%2y", localtime(time));
|
||||
my $stomorrow = strftime("%2d.%2m.%2y", localtime(time+86400));
|
||||
my @tday = split('\.',$stoday);
|
||||
my @tmor = split('\.',$stomorrow);
|
||||
my $fline = Calendar_Get($defs{$VacationDevice[0]},"get","full","mode=alarm|start|upcoming");
|
||||
my @lines = split('\n',$fline);
|
||||
foreach $fline (@lines)
|
||||
{
|
||||
chomp($fline);
|
||||
my @chunks = split(' ',$fline);
|
||||
my @sday = split('\.',$chunks[2]);
|
||||
my @eday = split('\.',substr($chunks[3],9,10));
|
||||
my $rets = ($sday[2]-$tday[2]-2000)*365+($sday[1]-$tday[1])*31+($sday[0]-$tday[0]);
|
||||
my $rete = ($eday[2]-$tday[2]-2000)*365+($eday[1]-$tday[1])*31+($eday[0]-$tday[0]);
|
||||
if (($rete>=0) && ($rets<=0) && ($DayToday == 1))
|
||||
{
|
||||
chomp($fline);
|
||||
my @chunks = split(' ',$fline);
|
||||
my @sday = split('\.',$chunks[2]);
|
||||
my @eday = split('\.',substr($chunks[3],9,10));
|
||||
my $rets = ($sday[2]-$tday[2]-2000)*365+($sday[1]-$tday[1])*31+($sday[0]-$tday[0]);
|
||||
my $rete = ($eday[2]-$tday[2]-2000)*365+($eday[1]-$tday[1])*31+($eday[0]-$tday[0]);
|
||||
if ( ($rete>=0) && ($rets<=0) )
|
||||
{
|
||||
my $todaydesc = $chunks[5];
|
||||
Log3 $hash->{NAME}, 1, "alarmclock: $hash->{NAME} - vacation => $VacationDevice[0] - $todaydesc";
|
||||
return 1;
|
||||
}
|
||||
my $todaydesc = $chunks[5];
|
||||
Log3 $hash->{NAME}, 1, "alarmclock: $hash->{NAME} - vacation => $VacationDevice[0] - $todaydesc";
|
||||
$hash->{helper}{Today} = 9;
|
||||
}
|
||||
$rets = ($sday[2]-$tmor[2]-2000)*365+($sday[1]-$tmor[1])*31+($sday[0]-$tmor[0]);
|
||||
$rete = ($eday[2]-$tmor[2]-2000)*365+($eday[1]-$tmor[1])*31+($eday[0]-$tmor[0]);
|
||||
if (($rete>=0) && ($rets<=0) && ($DayTomorrow == 1))
|
||||
{
|
||||
$hash->{helper}{Tomorrow} = 9;
|
||||
}
|
||||
}
|
||||
}
|
||||
elsif (scalar(@VacationDevice) eq "2")
|
||||
{
|
||||
if (ReadingsVal($VacationDevice[0],"state","NONE") eq $VacationDevice[1])
|
||||
{
|
||||
Log3 $hash->{NAME}, 1, "alarmclock: $hash->{NAME} - vacation => $VacationDevice[0] - $VacationDevice[1]";
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
elsif (scalar(@VacationDevice) eq "3")
|
||||
{
|
||||
my $VacationEvent = $VacationDevice[2];
|
||||
$VacationEvent =~ s/ //g;
|
||||
if (ReadingsVal($VacationDevice[0],$VacationDevice[1],"NONE") eq $VacationEvent)
|
||||
{
|
||||
Log3 $hash->{NAME}, 1, "alarmclock: $hash->{NAME} - vacation => $VacationDevice[0] - $VacationDevice[1] - $VacationEvent";
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
$a ++;
|
||||
}
|
||||
elsif (scalar(@VacationDevice) eq "2")
|
||||
{
|
||||
if ((ReadingsVal($VacationDevice[0],"state","NONE") eq $VacationDevice[1]) && ($DayToday == 1))
|
||||
{
|
||||
Log3 $hash->{NAME}, 1, "alarmclock: $hash->{NAME} - vacation => $VacationDevice[0] - $VacationDevice[1]";
|
||||
$hash->{helper}{Today} = 9;
|
||||
}
|
||||
}
|
||||
elsif (scalar(@VacationDevice) eq "3")
|
||||
{
|
||||
my $VacationEvent = $VacationDevice[2];
|
||||
$VacationEvent =~ s/ //g;
|
||||
if ((ReadingsVal($VacationDevice[0],$VacationDevice[1],"NONE") eq $VacationEvent)&& ($DayToday == 1))
|
||||
{
|
||||
Log3 $hash->{NAME}, 1, "alarmclock: $hash->{NAME} - vacation => $VacationDevice[0] - $VacationDevice[1] - $VacationEvent";
|
||||
$hash->{helper}{Today} = 9;
|
||||
}
|
||||
}
|
||||
$a ++;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
########################################################################################
|
||||
#
|
||||
# skip
|
||||
@ -1308,12 +1343,16 @@ sub alarmclock_Notify($$)
|
||||
|
||||
if((ReadingsVal($hash->{NAME},"state",0)) =~ /^(Alarm is running|Snooze for.*)/)
|
||||
{
|
||||
if(my @AlarmOffDevice = split(/:/, AttrVal($hash->{NAME},"EventForAlarmOff",""),2))
|
||||
{
|
||||
if(($devName eq $AlarmOffDevice[0]) && (grep { $AlarmOffDevice[1] eq $_ } @{$events}))
|
||||
{
|
||||
alarmclock_alarmroutine_stop($hash);
|
||||
}
|
||||
if(my @AlarmOffDevice = split(/\|/, AttrVal($hash->{NAME},"EventForAlarmOff","")))
|
||||
{
|
||||
foreach my $AlarmOffDevice(@AlarmOffDevice)
|
||||
{
|
||||
my @AlarmOffDevicePart = split(/:/, $AlarmOffDevice,2);
|
||||
if(($devName eq $AlarmOffDevicePart[0]) && (grep { $AlarmOffDevicePart[1] eq $_ } @{$events}))
|
||||
{
|
||||
alarmclock_alarmroutine_stop($hash);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1322,12 +1361,16 @@ sub alarmclock_Notify($$)
|
||||
|
||||
if((ReadingsVal($hash->{NAME},"state",0)) eq "Alarm is running")
|
||||
{
|
||||
if(my @SnoozeDevice = split(/:/, AttrVal($hash->{NAME},"EventForSnooze",""),2))
|
||||
{
|
||||
if(($devName eq $SnoozeDevice[0]) && (grep { $SnoozeDevice[1] eq $_ } @{$events}))
|
||||
{
|
||||
alarmclock_snooze_start($hash);
|
||||
}
|
||||
if(my @SnoozeDevice = split(/\|/, AttrVal($hash->{NAME},"EventForSnooze","")))
|
||||
{
|
||||
foreach my $SnoozeDevice(@SnoozeDevice)
|
||||
{
|
||||
my @SnoozeDevicePart = split(/:/, $SnoozeDevice,2);
|
||||
if(($devName eq $SnoozeDevicePart[0]) && (grep { $SnoozeDevicePart[1] eq $_ } @{$events}))
|
||||
{
|
||||
alarmclock_snooze_start($hash);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user