2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-02-26 10:34:52 +00:00

98_alarmclock: add new feature PresenceDevice

git-svn-id: https://svn.fhem.de/fhem/trunk@14329 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
FlorianZ 2017-05-20 12:45:20 +00:00
parent 16991ee329
commit f9c013cd9b
2 changed files with 171 additions and 62 deletions

View File

@ -1,5 +1,6 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # 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. # Do not insert empty lines here, update check depends on it.
- feature: 98_alarmclock: New feature PresenceDevice
- change: 49_SSCam: version 2.2.1, last record playback possible as iFrame, - change: 49_SSCam: version 2.2.1, last record playback possible as iFrame,
deviceoverview available, deviceoverview available,
CAUTION - syntax of runView options has been changed !! CAUTION - syntax of runView options has been changed !!

View File

@ -119,6 +119,8 @@ sub alarmclock_Initialize($)
. " SnoozeRoutine" . " SnoozeRoutine"
. " HolidayDevice" . " HolidayDevice"
. " HolidayCheck:1,0" . " HolidayCheck:1,0"
. " PresenceDevice"
. " PresenceCheck:1,0"
. " RepRoutine1" . " RepRoutine1"
. " RepRoutine1WaitInSec" . " RepRoutine1WaitInSec"
. " RepRoutine1Repeats" . " RepRoutine1Repeats"
@ -438,7 +440,7 @@ sub alarmclock_Attr(@)
} }
} }
###HolidayCheck### ###Holiday###
if($attr_name eq "HolidayCheck") if($attr_name eq "HolidayCheck")
{ {
@ -475,42 +477,13 @@ sub alarmclock_createtimer($)
if ((AttrVal($hash->{NAME}, "disable", 0 ) ne "1" ) && (ReadingsVal($hash->{NAME},"state","activated") ne "deactivated")) if ((AttrVal($hash->{NAME}, "disable", 0 ) ne "1" ) && (ReadingsVal($hash->{NAME},"state","activated") ne "deactivated"))
{ {
### Check HolidayDevice ### ### Holiday ###
if (alarmclock_holiday_check($hash))
if ((AttrVal($hash->{NAME}, "HolidayDevice", "NONE" ) ne "NONE" ) && (AttrVal($hash->{NAME}, "HolidayCheck", "1" ) ne "0" ))
{ {
my @HolidayDevice = split(/:/, AttrVal($hash->{NAME},"HolidayDevice",""),3); $alarmtimetoday = $alarmday{8};
if (scalar(@HolidayDevice) eq "1")
{
if (ReadingsVal($HolidayDevice[0],"state","none") ne "none")
{
$alarmtimetoday = $alarmday{8};
Log3 $hash->{NAME}, 3, "alarmclock: $hash->{NAME} - holiday";
}
}
elsif (scalar(@HolidayDevice) eq "2")
{
if (ReadingsVal($HolidayDevice[0],"state","NONE") eq $HolidayDevice[1])
{
$alarmtimetoday = $alarmday{8};
Log3 $hash->{NAME}, 3, "alarmclock: $hash->{NAME} - holiday";
}
}
elsif (scalar(@HolidayDevice) eq "3")
{
my $HolidayEvent = $HolidayDevice[2];
$HolidayEvent =~ s/ //g;
if (ReadingsVal($HolidayDevice[0],$HolidayDevice[1],"NONE") eq $HolidayEvent)
{
$alarmtimetoday = $alarmday{8};
Log3 $hash->{NAME}, 3, "alarmclock: $hash->{NAME} - holiday";
}
}
} }
### Ende Holiday ### ### End Holiday ###
if ((ReadingsVal($hash->{NAME},$alarmtimetoday,"NONE")) =~ /^([0-1]?[0-9]|2[0-3]):[0-5][0-9]$/) if ((ReadingsVal($hash->{NAME},$alarmtimetoday,"NONE")) =~ /^([0-1]?[0-9]|2[0-3]):[0-5][0-9]$/)
{ {
@ -534,7 +507,7 @@ if ((AttrVal($hash->{NAME}, "disable", 0 ) ne "1" ) && (ReadingsVal($hash->{NAME
Log3 $hash->{NAME}, 5, "alarmclock: $hash->{NAME} - alarm-timer created with $AlarmIn sec"; Log3 $hash->{NAME}, 5, "alarmclock: $hash->{NAME} - alarm-timer created with $AlarmIn sec";
### Check für Pre-Alarm ### ### PreAlarm ###
if((AttrVal($hash->{NAME},"PreAlarmTimeInSec","NONE")) =~ /^([0-9]?[0-9]?[0-9]?[0-9])$/) if((AttrVal($hash->{NAME},"PreAlarmTimeInSec","NONE")) =~ /^([0-9]?[0-9]?[0-9]?[0-9])$/)
{ {
@ -556,7 +529,7 @@ if ((AttrVal($hash->{NAME}, "disable", 0 ) ne "1" ) && (ReadingsVal($hash->{NAME
Log3 $hash->{NAME}, 4, "alarmclock: $hash->{NAME} - no PreAlarmTimeInSec is set"; Log3 $hash->{NAME}, 4, "alarmclock: $hash->{NAME} - no PreAlarmTimeInSec is set";
} }
### Ende Pre-Alarm ### ### End PreAlarm ###
} }
@ -569,7 +542,7 @@ if ((AttrVal($hash->{NAME}, "disable", 0 ) ne "1" ) && (ReadingsVal($hash->{NAME
} }
### Check für OffDefaultTime ### ### OffDefaultTime ###
elsif((ReadingsVal($hash->{NAME},$alarmtimetoday,"NONE")) eq "off") elsif((ReadingsVal($hash->{NAME},$alarmtimetoday,"NONE")) eq "off")
{ {
@ -604,7 +577,7 @@ if ((AttrVal($hash->{NAME}, "disable", 0 ) ne "1" ) && (ReadingsVal($hash->{NAME
} }
} }
### Ende OffDefaultTime ### ### End OffDefaultTime ###
else else
@ -619,7 +592,7 @@ if ((AttrVal($hash->{NAME}, "disable", 0 ) ne "1" ) && (ReadingsVal($hash->{NAME
######################################################################################## ########################################################################################
# #
# Zeit bis Mitternacht wird berrechnet und ein Timer bis Mitternacht + 5Sekunden wird gesetzt # Midnight-timer + 5 seconds
# #
######################################################################################## ########################################################################################
@ -645,7 +618,7 @@ if ((AttrVal($hash->{NAME}, "disable", 0 ) ne "1" ) && (ReadingsVal($hash->{NAME
######################################################################################## ########################################################################################
# #
# Alarm-Routine wird gestartet # Alarm-Routine start
# #
######################################################################################## ########################################################################################
@ -655,20 +628,25 @@ sub alarmclock_alarmroutine_start($)
my ($hash) = @_; my ($hash) = @_;
my $Mode = "Alarm"; my $Mode = "Alarm";
fhem("".AttrVal($hash->{NAME},"AlarmRoutine","")); if (alarmclock_presence_check($hash))
readingsSingleUpdate( $hash,"state", "Alarm is running", 1 ); {
alarmclock_hardalarm_timer($hash); fhem("".AttrVal($hash->{NAME},"AlarmRoutine",""));
alarmclock_maxalarmduration_timer($hash); readingsSingleUpdate( $hash,"state", "Alarm is running", 1 );
alarmclock_reproutine($hash, $Mode); alarmclock_hardalarm_timer($hash);
Log3 $hash->{NAME}, 3, "alarmclock: $hash->{NAME} - AlarmRoutine started."; alarmclock_maxalarmduration_timer($hash);
alarmclock_reproutine($hash, $Mode);
Log3 $hash->{NAME}, 3, "alarmclock: $hash->{NAME} - AlarmRoutine started.";
}
else
{
alarmclock_createtimer($hash);
}
} }
######################################################################################## ########################################################################################
# #
# Alarm-Routine wird gestoppt # Alarm-Routine stop
# #
######################################################################################## ########################################################################################
@ -689,7 +667,7 @@ sub alarmclock_alarmroutine_stop($)
######################################################################################## ########################################################################################
# #
# Pre-Alarm-Routine wird gestartet # Pre-Alarm-Routine start
# #
######################################################################################## ########################################################################################
@ -699,11 +677,13 @@ sub alarmclock_prealarmroutine_start($)
my ($hash) = @_; my ($hash) = @_;
my $Mode = "PreAlarm"; my $Mode = "PreAlarm";
fhem("".AttrVal($hash->{NAME},"PreAlarmRoutine","")); if (alarmclock_presence_check($hash))
readingsSingleUpdate( $hash,"state", "PreAlarm is running", 1 ); {
alarmclock_reproutine($hash, $Mode); fhem("".AttrVal($hash->{NAME},"PreAlarmRoutine",""));
Log3 $hash->{NAME}, 3, "alarmclock: $hash->{NAME} - PreAlarmRoutine started."; readingsSingleUpdate( $hash,"state", "PreAlarm is running", 1 );
alarmclock_reproutine($hash, $Mode);
Log3 $hash->{NAME}, 3, "alarmclock: $hash->{NAME} - PreAlarmRoutine started.";
}
} }
@ -807,7 +787,7 @@ sub alarmclock_maxalarmduration_timer($)
######################################################################################## ########################################################################################
# #
# HardAlarm wird gestartet # HardAlarm start
# #
######################################################################################## ########################################################################################
@ -886,7 +866,7 @@ sub alarmclock_reproutine_stop($$)
######################################################################################## ########################################################################################
# #
# RepRoutine1 wird gestartet # RepRoutine1 start
# #
######################################################################################## ########################################################################################
@ -904,7 +884,6 @@ sub alarmclock_reproutine1_start($)
my $RNext = $RNow + 1; my $RNext = $RNow + 1;
$hash->{helper}{Repeat1} = $RNext; $hash->{helper}{Repeat1} = $RNext;
fhem("".AttrVal($hash->{NAME},"RepRoutine1","")); fhem("".AttrVal($hash->{NAME},"RepRoutine1",""));
Log3 $hash->{NAME}, 3, "alarmclock: $hash->{NAME} - Rep1: $hash->{helper}{Repeat1}";
InternalTimer(gettimeofday()+$WaitTime, "alarmclock_reproutine1_start", $hash, 0); InternalTimer(gettimeofday()+$WaitTime, "alarmclock_reproutine1_start", $hash, 0);
} }
} }
@ -912,7 +891,7 @@ sub alarmclock_reproutine1_start($)
######################################################################################## ########################################################################################
# #
# RepRoutine2 wird gestartet # RepRoutine2 start
# #
######################################################################################## ########################################################################################
@ -930,7 +909,6 @@ sub alarmclock_reproutine2_start($)
my $RNext = $RNow + 1; my $RNext = $RNow + 1;
$hash->{helper}{Repeat2} = $RNext; $hash->{helper}{Repeat2} = $RNext;
fhem("".AttrVal($hash->{NAME},"RepRoutine2","")); fhem("".AttrVal($hash->{NAME},"RepRoutine2",""));
Log3 $hash->{NAME}, 3, "alarmclock: $hash->{NAME} - Rep2: $hash->{helper}{Repeat2}";
InternalTimer(gettimeofday()+$WaitTime, "alarmclock_reproutine2_start", $hash, 0); InternalTimer(gettimeofday()+$WaitTime, "alarmclock_reproutine2_start", $hash, 0);
} }
} }
@ -938,7 +916,7 @@ sub alarmclock_reproutine2_start($)
######################################################################################## ########################################################################################
# #
# RepRoutine3 wird gestartet # RepRoutine3 start
# #
######################################################################################## ########################################################################################
@ -956,11 +934,125 @@ sub alarmclock_reproutine3_start($)
my $RNext = $RNow + 1; my $RNext = $RNow + 1;
$hash->{helper}{Repeat3} = $RNext; $hash->{helper}{Repeat3} = $RNext;
fhem("".AttrVal($hash->{NAME},"RepRoutine3","")); fhem("".AttrVal($hash->{NAME},"RepRoutine3",""));
Log3 $hash->{NAME}, 3, "alarmclock: $hash->{NAME} - Rep3: $hash->{helper}{Repeat3}";
InternalTimer(gettimeofday()+$WaitTime, "alarmclock_reproutine3_start", $hash, 0); InternalTimer(gettimeofday()+$WaitTime, "alarmclock_reproutine3_start", $hash, 0);
} }
} }
########################################################################################
#
# Presence Check
#
########################################################################################
sub alarmclock_presence_check($)
{
my ($hash) = @_;
if ((AttrVal($hash->{NAME}, "PresenceDevice", "NONE" ) ne "NONE" ) && (AttrVal($hash->{NAME}, "PresenceCheck", "1" ) ne "0" ))
{
my @Presence = split(/\|/, AttrVal($hash->{NAME},"PresenceDevice",""));
my $a = 0;
my $b = scalar(@Presence);
while ($a < $b)
{
my @PresenceDevice = split(/:/,$Presence[$a]);
if (scalar(@PresenceDevice) eq "1")
{
if (ReadingsVal($PresenceDevice[0],"state","present") ne "present")
{
Log3 $hash->{NAME}, 3, "alarmclock: $hash->{NAME} - absent";
return 0;
}
}
elsif (scalar(@PresenceDevice) eq "2")
{
if (ReadingsVal($PresenceDevice[0],"state","NONE") eq $PresenceDevice[1])
{
Log3 $hash->{NAME}, 3, "alarmclock: $hash->{NAME} - absent";
return 0;
}
}
elsif (scalar(@PresenceDevice) eq "3")
{
my $PresenceEvent = $PresenceDevice[2];
$PresenceEvent =~ s/ //g;
if (ReadingsVal($PresenceDevice[0],$PresenceDevice[1],"NONE") eq $PresenceEvent)
{
Log3 $hash->{NAME}, 3, "alarmclock: $hash->{NAME} - absent";
return 0;
}
}
$a ++;
}
}
return 1;
}
########################################################################################
#
# Holiday Check
#
########################################################################################
sub alarmclock_holiday_check($)
{
my ($hash) = @_;
if ((AttrVal($hash->{NAME}, "HolidayDevice", "NONE" ) ne "NONE" ) && (AttrVal($hash->{NAME}, "HolidayCheck", "1" ) ne "0" ))
{
my @Holiday = split(/\|/, AttrVal($hash->{NAME},"HolidayDevice",""));
my $a = 0;
my $b = scalar(@Holiday);
while ($a < $b)
{
my @HolidayDevice = split(/:/,$Holiday[$a]);
if (scalar(@HolidayDevice) eq "1")
{
if (ReadingsVal($HolidayDevice[0],"state","none") ne "none")
{
Log3 $hash->{NAME}, 3, "alarmclock: $hash->{NAME} - holiday";
return 1;
}
}
elsif (scalar(@HolidayDevice) eq "2")
{
if (ReadingsVal($HolidayDevice[0],"state","NONE") eq $HolidayDevice[1])
{
Log3 $hash->{NAME}, 3, "alarmclock: $hash->{NAME} - holiday";
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}, 3, "alarmclock: $hash->{NAME} - holiday";
return 1;
}
}
$a ++;
}
}
return 0;
}
######################################################################################## ########################################################################################
# #
@ -1147,6 +1239,22 @@ sub alarmclock_Notify($$)
<li><b>HolidayCheck</b> <br> <li><b>HolidayCheck</b> <br>
0 disables monitoring the holiday device<br> 0 disables monitoring the holiday device<br>
1 activates monitoring 1 activates monitoring
</li>
<li><b>PresenceDevice</b> <br>
Name of the presence device.<br>
There are 3 possibilities:<br>
1.presence device from Typ presence.<br>
&lt;devicename&gt; Example: attr &lt;name&gt; PresenceDevice Presence <br>
Alarmclock cancel alarm when state is absent <br>
2.On state of a device.For example a dummy <br>
&lt;devicename&gt;:&lt;value&gt; Example: attr &lt;name&gt; PresenceDevice MyDummy:absent <br>
Here the Alarmclock cancel alarm when the state of the dummy has the value absent <br>
3.On a reading of a device. <br>
&lt;devicename&gt;:&lt;readingname&gt;:&lt;value&gt; Example: attr &lt;name&gt; PresenceDevice MyDummy:user:notathome <br>
</li>
<li><b>PresenceCheck</b> <br>
0 disables monitoring the presence device<br>
1 activates monitoring
</li> </li>
<li><b>disable</b> <br> <li><b>disable</b> <br>
1 disables all alarms<br> 1 disables all alarms<br>