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

98_alarmclock.pm:new feature RepRoutine

git-svn-id: https://svn.fhem.de/fhem/trunk@14245 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
FlorianZ 2017-05-11 09:44:19 +00:00
parent f9ac569711
commit b1f0001c38
2 changed files with 182 additions and 3 deletions

View File

@ -1,5 +1,6 @@
# 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: 98_alarmclock: New feature RepRoutine
- feature: 31_PLAYBULB: support for new Garden Model, move battery Reading to
powerLevel and add powerCharge Reading for Garden
- feature: 00_DFPlayerMini: improved requestAck handling

View File

@ -79,6 +79,9 @@ qw(
OffRoutine:textField-long
HardAlarmRoutine:textField-long
SnoozeRoutine:textField-long
RepRoutine1:textField-long
RepRoutine2:textField-long
RepRoutine3:textField-long
);
@ -116,6 +119,21 @@ sub alarmclock_Initialize($)
. " SnoozeRoutine"
. " HolidayDevice"
. " HolidayCheck:1,0"
. " RepRoutine1"
. " RepRoutine1WaitInSec"
. " RepRoutine1Repeats"
. " RepRoutine1Mode:Alarm,PreAlarm,off"
. " RepRoutine1Stop:Snooze,off"
. " RepRoutine2"
. " RepRoutine2WaitInSec"
. " RepRoutine2Repeats"
. " RepRoutine2Mode:Alarm,PreAlarm,off"
. " RepRoutine2Stop:Snooze,off"
. " RepRoutine3"
. " RepRoutine3WaitInSec"
. " RepRoutine3Repeats"
. " RepRoutine3Mode:Alarm,PreAlarm,off"
. " RepRoutine3Stop:Snooze,off"
. " disable:1,0"
. " $readingFnAttributes";
@ -138,6 +156,10 @@ sub alarmclock_Define($$)
return "Wrong syntax: use define <name> alarmclock" if(int(@a) != 2);
$hash->{helper}{Repeat1} = 0;
$hash->{helper}{Repeat2} = 0;
$hash->{helper}{Repeat3} = 0;
return undef;
}
@ -631,13 +653,16 @@ sub alarmclock_alarmroutine_start($)
{
my ($hash) = @_;
my $Mode = "Alarm";
fhem("".AttrVal($hash->{NAME},"AlarmRoutine",""));
readingsSingleUpdate( $hash,"state", "Alarm is running", 1 );
alarmclock_hardalarm_timer($hash);
alarmclock_maxalarmduration_timer($hash);
alarmclock_reproutine($hash, $Mode);
Log3 $hash->{NAME}, 3, "alarmclock: $hash->{NAME} - AlarmRoutine started.";
}
@ -672,9 +697,11 @@ sub alarmclock_prealarmroutine_start($)
{
my ($hash) = @_;
my $Mode = "PreAlarm";
fhem("".AttrVal($hash->{NAME},"PreAlarmRoutine",""));
readingsSingleUpdate( $hash,"state", "PreAlarm is running", 1 );
alarmclock_reproutine($hash, $Mode);
Log3 $hash->{NAME}, 3, "alarmclock: $hash->{NAME} - PreAlarmRoutine started.";
}
@ -690,7 +717,7 @@ sub alarmclock_snooze_start($)
{
my ($hash) = @_;
my $Mode = "Snooze";
if((AttrVal($hash->{NAME},"SnoozeTimeInSec","NONE")) =~ /^([0-9]?[0-9]?[0-9]?[0-9])$/)
{
@ -700,6 +727,7 @@ sub alarmclock_snooze_start($)
readingsSingleUpdate( $hash,"state", "Snooze for $SnoozeTime sec", 1 );
RemoveInternalTimer($hash, "alarmclock_hardalarmroutine_start");
RemoveInternalTimer($hash, "alarmclock_alarmroutine_stop");
alarmclock_reproutine_stop($hash, $Mode);
Log3 $hash->{NAME}, 5, "alarmclock: $hash->{NAME} - snooze-timer created with $SnoozeTime sec.";
}
@ -776,6 +804,7 @@ sub alarmclock_maxalarmduration_timer($)
}
########################################################################################
#
# HardAlarm wird gestartet
@ -792,6 +821,146 @@ sub alarmclock_hardalarmroutine_start($)
}
########################################################################################
#
# RepRoutine
#
########################################################################################
sub alarmclock_reproutine($$)
{
my ($hash, $Mode) = @_;
if(((AttrVal($hash->{NAME},"RepRoutine1","NONE")) ne "NONE") &&
(AttrVal($hash->{NAME},"RepRoutine1Mode","off")) eq $Mode)
{
$hash->{helper}{Repeat1} = 0;
my $WaitTime1 = AttrVal($hash->{NAME},"RepRoutine1WaitInSec","10");
InternalTimer(gettimeofday()+$WaitTime1, "alarmclock_reproutine1_start", $hash, 0);
}
if(((AttrVal($hash->{NAME},"RepRoutine2","NONE")) ne "NONE") &&
(AttrVal($hash->{NAME},"RepRoutine2Mode","off")) eq $Mode)
{
$hash->{helper}{Repeat2} = 0;
my $WaitTime2 = AttrVal($hash->{NAME},"RepRoutine2WaitInSec","10");
InternalTimer(gettimeofday()+$WaitTime2, "alarmclock_reproutine2_start", $hash, 0);
}
if(((AttrVal($hash->{NAME},"RepRoutine3","NONE")) ne "NONE") &&
(AttrVal($hash->{NAME},"RepRoutine3Mode","off")) eq $Mode)
{
$hash->{helper}{Repeat3} = 0;
my $WaitTime3 = AttrVal($hash->{NAME},"RepRoutine3WaitInSec","10");
InternalTimer(gettimeofday()+$WaitTime3, "alarmclock_reproutine3_start", $hash, 0);
}
}
########################################################################################
#
# RepRoutine stop
#
########################################################################################
sub alarmclock_reproutine_stop($$)
{
my ($hash, $Mode) = @_;
if((AttrVal($hash->{NAME},"RepRoutine1Stop","Snooze")) eq $Mode)
{
RemoveInternalTimer($hash, "alarmclock_reproutine1_start");
}
if((AttrVal($hash->{NAME},"RepRoutine2Stop","Snooze")) eq $Mode)
{
RemoveInternalTimer($hash, "alarmclock_reproutine2_start");
}
if((AttrVal($hash->{NAME},"RepRoutine3Stop","Snooze")) eq $Mode)
{
RemoveInternalTimer($hash, "alarmclock_reproutine3_start");
}
}
########################################################################################
#
# RepRoutine1 wird gestartet
#
########################################################################################
sub alarmclock_reproutine1_start($)
{
my ($hash) = @_;
my $WaitTime = AttrVal($hash->{NAME},"RepRoutine1WaitInSec","10");
my $Repeats = AttrVal($hash->{NAME},"RepRoutine1Repeats","2");
my $RNow = $hash->{helper}{Repeat1};
if ($Repeats > $RNow)
{
my $RNext = $RNow + 1;
$hash->{helper}{Repeat1} = $RNext;
fhem("".AttrVal($hash->{NAME},"RepRoutine1",""));
Log3 $hash->{NAME}, 3, "alarmclock: $hash->{NAME} - Rep1: $hash->{helper}{Repeat1}";
InternalTimer(gettimeofday()+$WaitTime, "alarmclock_reproutine1_start", $hash, 0);
}
}
########################################################################################
#
# RepRoutine2 wird gestartet
#
########################################################################################
sub alarmclock_reproutine2_start($)
{
my ($hash) = @_;
my $WaitTime = AttrVal($hash->{NAME},"RepRoutine2WaitInSec","10");
my $Repeats = AttrVal($hash->{NAME},"RepRoutine2Repeats","2");
my $RNow = $hash->{helper}{Repeat2};
if ($Repeats > $RNow)
{
my $RNext = $RNow + 1;
$hash->{helper}{Repeat2} = $RNext;
fhem("".AttrVal($hash->{NAME},"RepRoutine2",""));
Log3 $hash->{NAME}, 3, "alarmclock: $hash->{NAME} - Rep2: $hash->{helper}{Repeat2}";
InternalTimer(gettimeofday()+$WaitTime, "alarmclock_reproutine2_start", $hash, 0);
}
}
########################################################################################
#
# RepRoutine3 wird gestartet
#
########################################################################################
sub alarmclock_reproutine3_start($)
{
my ($hash) = @_;
my $WaitTime = AttrVal($hash->{NAME},"RepRoutine3WaitInSec","10");
my $Repeats = AttrVal($hash->{NAME},"RepRoutine3Repeats","2");
my $RNow = $hash->{helper}{Repeat3};
if ($Repeats > $RNow)
{
my $RNext = $RNow + 1;
$hash->{helper}{Repeat3} = $RNext;
fhem("".AttrVal($hash->{NAME},"RepRoutine3",""));
Log3 $hash->{NAME}, 3, "alarmclock: $hash->{NAME} - Rep3: $hash->{helper}{Repeat3}";
InternalTimer(gettimeofday()+$WaitTime, "alarmclock_reproutine3_start", $hash, 0);
}
}
########################################################################################
#
@ -965,6 +1134,15 @@ sub alarmclock_Notify($$)
</li>
<li><b>HolidayDevice</b> <br>
Name of the holiday device.<br>
There are 3 possibilities:<br>
1.holiday device from Typ holiday.<br>
&lt;devicename&gt; Example: attr &lt;name&gt; HolidayDevice Feiertage <br>
AlarmTime 8_Holiday accesses when state is not none <br>
2.On state of a device.For example a dummy <br>
&lt;devicename&gt;:&lt;value&gt; Example: attr &lt;name&gt; HolidayDevice MyDummy:Holiday <br>
Here the AlarmTime 8_Holiday takes effect when the state of the dummy has the value Holiday <br>
3.On a reading of a device. <br>
&lt;devicename&gt;:&lt;readingname&gt;:&lt;value&gt; Example: attr &lt;name&gt; HolidayDevice MyDummy:Today:Holiday <br>
</li>
<li><b>HolidayCheck</b> <br>
0 disables monitoring the holiday device<br>