mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-10 09:16:53 +00:00
git-svn-id: https://svn.fhem.de/fhem/trunk@6553 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
3489fa262e
commit
c0366ffe65
@ -40,7 +40,7 @@ my $alarmname = "Alarms"; # link text
|
|||||||
my $alarmhiddenroom = "AlarmRoom"; # hidden room
|
my $alarmhiddenroom = "AlarmRoom"; # hidden room
|
||||||
my $alarmpublicroom = "Alarm"; # public room
|
my $alarmpublicroom = "Alarm"; # public room
|
||||||
my $alarmno = 8;
|
my $alarmno = 8;
|
||||||
my $alarmversion = "1.2";
|
my $alarmversion = "1.3";
|
||||||
|
|
||||||
#########################################################################################
|
#########################################################################################
|
||||||
#
|
#
|
||||||
@ -58,7 +58,7 @@ sub Alarm_Initialize ($) {
|
|||||||
$hash->{GetFn} = "Alarm_Get";
|
$hash->{GetFn} = "Alarm_Get";
|
||||||
$hash->{UndefFn} = "Alarm_Undef";
|
$hash->{UndefFn} = "Alarm_Undef";
|
||||||
#$hash->{AttrFn} = "Alarm_Attr";
|
#$hash->{AttrFn} = "Alarm_Attr";
|
||||||
my $attst = "lockstate:lock,unlock";
|
my $attst = "lockstate:lock,unlock statedisplay:simple,color,table,graphics,none";
|
||||||
for( my $level=0;$level<$alarmno;$level++ ){
|
for( my $level=0;$level<$alarmno;$level++ ){
|
||||||
$attst .=" level".$level."start level".$level."end level".$level."msg level".$level."xec:0,1 level".$level."onact level".$level."offact";
|
$attst .=" level".$level."start level".$level."end level".$level."msg level".$level."xec:0,1 level".$level."onact level".$level."offact";
|
||||||
}
|
}
|
||||||
@ -151,6 +151,8 @@ sub Alarm_CreateEntry($) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
my $mga = Alarm_getstate($hash)." Keine Störung";
|
||||||
|
readingsSingleUpdate( $hash, "state", $mga, 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
#########################################################################################
|
#########################################################################################
|
||||||
@ -209,6 +211,54 @@ sub Alarm_Get($@) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#########################################################################################
|
||||||
|
#
|
||||||
|
# Alarm_getstate - Helper function to assemble a state display
|
||||||
|
#
|
||||||
|
# Parameter hash = hash of device addressed
|
||||||
|
#
|
||||||
|
#########################################################################################
|
||||||
|
|
||||||
|
sub Alarm_getstate($) {
|
||||||
|
my ($hash) = @_;
|
||||||
|
my $res = '';
|
||||||
|
my $type = AttrVal($hash->{NAME},"statedisplay",0);
|
||||||
|
#--------------------------
|
||||||
|
if( $type eq "simple" ){
|
||||||
|
for( my $level=0;$level<$alarmno;$level++ ){
|
||||||
|
if( $hash->{READINGS}{"level".$level}{VAL} eq "off" ){
|
||||||
|
$res.='O';
|
||||||
|
}else{
|
||||||
|
$res.='X';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#--------------------------
|
||||||
|
}elsif( $type eq "color" ){
|
||||||
|
$res = '<span style="color:green">';
|
||||||
|
for( my $level=0;$level<$alarmno;$level++ ){
|
||||||
|
if( $hash->{READINGS}{"level".$level}{VAL} eq "off" ){
|
||||||
|
$res.=' '.$level;
|
||||||
|
}else{
|
||||||
|
$res.=' <span style="width:1ex;color:red">'.$level.'</span>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$res.='</span>';
|
||||||
|
#--------------------------
|
||||||
|
}elsif( $type eq "table" ){
|
||||||
|
$res = '<table><tr style="height:1ex">';
|
||||||
|
for( my $level=0;$level<$alarmno;$level++ ){
|
||||||
|
if( $hash->{READINGS}{"level".$level}{VAL} eq "off" ){
|
||||||
|
$res.='<td style="width:1ex;background-color:green"/>';
|
||||||
|
}else{
|
||||||
|
$res.='<td style="width:1ex;background-color:red"/>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$res.='</tr></table>';
|
||||||
|
#--------------------------
|
||||||
|
}
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
#########################################################################################
|
#########################################################################################
|
||||||
#
|
#
|
||||||
# Alarm_Exec - Execute the Alarm
|
# Alarm_Exec - Execute the Alarm
|
||||||
@ -228,6 +278,8 @@ sub Alarm_Exec($$$$$){
|
|||||||
my $msg = '';
|
my $msg = '';
|
||||||
my $cmd;
|
my $cmd;
|
||||||
my $mga;
|
my $mga;
|
||||||
|
my $dly;
|
||||||
|
my @sta;
|
||||||
|
|
||||||
#-- raising the alarm
|
#-- raising the alarm
|
||||||
if( $act eq "on" ){
|
if( $act eq "on" ){
|
||||||
@ -244,10 +296,12 @@ sub Alarm_Exec($$$$$){
|
|||||||
my $ntp = $hour*60+$min;
|
my $ntp = $hour*60+$min;
|
||||||
|
|
||||||
if( ($ntp <= $etp) && ($ntp >= $stp) ){
|
if( ($ntp <= $etp) && ($ntp >= $stp) ){
|
||||||
my $str1 = "$day.$month $hour:$min";
|
#-- calling actors
|
||||||
|
$cmd = AttrVal($name, "level".$level."onact", 0);
|
||||||
|
fhem($cmd);
|
||||||
#-- raised by sensor (attribute values have been controlled in CreateNotifiers)
|
#-- raised by sensor (attribute values have been controlled in CreateNotifiers)
|
||||||
my @sta = split('\|', AttrVal($dev, "alarmSettings", 0));
|
@sta = split('\|', AttrVal($dev, "alarmSettings", 0));
|
||||||
my $mga = $sta[2]." ".AttrVal($name, "level".$level."msg", 0);
|
$mga = $sta[2]." ".AttrVal($name, "level".$level."msg", 0);
|
||||||
#-- replace some parts
|
#-- replace some parts
|
||||||
my @evtpart = split(" ",$evt);
|
my @evtpart = split(" ",$evt);
|
||||||
$mga =~ s/\$NAME/$dev/g;
|
$mga =~ s/\$NAME/$dev/g;
|
||||||
@ -255,19 +309,13 @@ sub Alarm_Exec($$$$$){
|
|||||||
for( my $i=1;$i<= int(@evtpart);$i++){
|
for( my $i=1;$i<= int(@evtpart);$i++){
|
||||||
$mga =~ s/\$EVTPART$i/$evtpart[$i-1]/g;
|
$mga =~ s/\$EVTPART$i/$evtpart[$i-1]/g;
|
||||||
}
|
}
|
||||||
#-- only if level is higher than before
|
#-- readings
|
||||||
if( ($aclvl eq "none") || ($level >= $aclvl) ){
|
readingsSingleUpdate( $hash, "level".$level,$dev,0 );
|
||||||
$msg = "[Alarm $level] raised from device $dev with event $evt";
|
readingsSingleUpdate( $hash, "short", $mga, 0);
|
||||||
|
$mga = Alarm_getstate($hash)." ".$mga;
|
||||||
readingsSingleUpdate( $hash, "state", $mga, 0 );
|
readingsSingleUpdate( $hash, "state", $mga, 0 );
|
||||||
readingsSingleUpdate( $hash, "level", $level, 0 );
|
$msg = "[Alarm $level] raised from device $dev with event $evt";
|
||||||
#-- calling actors
|
|
||||||
$cmd = AttrVal($name, "level".$level."onact", 0);
|
|
||||||
fhem($cmd);
|
|
||||||
Log3 $hash,3,$msg;
|
Log3 $hash,3,$msg;
|
||||||
}else{
|
|
||||||
$msg = "[Alarm $level] not raised from device $dev, already higher level $aclvl running";
|
|
||||||
Log3 $hash,3,$msg;
|
|
||||||
}
|
|
||||||
}else{
|
}else{
|
||||||
$msg = "[Alarm $level] not raised, not in time slot";
|
$msg = "[Alarm $level] not raised, not in time slot";
|
||||||
Log3 $hash,5,$msg;
|
Log3 $hash,5,$msg;
|
||||||
@ -277,8 +325,10 @@ sub Alarm_Exec($$$$$){
|
|||||||
Log3 $hash,5,$msg;
|
Log3 $hash,5,$msg;
|
||||||
}
|
}
|
||||||
}elsif( $act eq "off" ){
|
}elsif( $act eq "off" ){
|
||||||
|
#-- only if this level is active
|
||||||
|
if( $hash->{READINGS}{"level".$level}{VAL} ne "off"){
|
||||||
#-- deleting all running ats
|
#-- deleting all running ats
|
||||||
my $dly = sprintf("alarm%1ddly",$level);
|
$dly = sprintf("alarm%1ddly",$level);
|
||||||
foreach my $d (sort keys %intAt ) {
|
foreach my $d (sort keys %intAt ) {
|
||||||
next if( $intAt{$d}{FN} ne "at_Exec" );
|
next if( $intAt{$d}{FN} ne "at_Exec" );
|
||||||
$mga = $intAt{$d}{ARG}{NAME};
|
$mga = $intAt{$d}{ARG}{NAME};
|
||||||
@ -288,12 +338,16 @@ sub Alarm_Exec($$$$$){
|
|||||||
}
|
}
|
||||||
#-- calling actors
|
#-- calling actors
|
||||||
$cmd = AttrVal($name, "level".$level."offact", 0);
|
$cmd = AttrVal($name, "level".$level."offact", 0);
|
||||||
$msg = "[Alarm $level] canceled from device $dev";
|
|
||||||
fhem($cmd);
|
fhem($cmd);
|
||||||
#-- todo: several levels may be active at one - unclear so far.
|
#-- readings
|
||||||
readingsSingleUpdate( $hash, "state", "Canceled", 0 );
|
readingsSingleUpdate( $hash, "level".$level,"off",0 );
|
||||||
readingsSingleUpdate( $hash, "level", "none", 0 );
|
$mga = " Level $level canceled";
|
||||||
|
readingsSingleUpdate( $hash, "short", $mga, 0);
|
||||||
|
$mga = Alarm_getstate($hash)." ".$mga;
|
||||||
|
readingsSingleUpdate( $hash, "state", $mga, 0 );
|
||||||
|
$msg = "[Alarm $level] canceled from device $dev";
|
||||||
Log3 $hash,3,$msg;
|
Log3 $hash,3,$msg;
|
||||||
|
}
|
||||||
}else{
|
}else{
|
||||||
Log3 $hash,3,"[Alarm $level] Exec called with act=$act";
|
Log3 $hash,3,"[Alarm $level] Exec called with act=$act";
|
||||||
}
|
}
|
||||||
@ -317,6 +371,8 @@ sub Alarm_Sharp($$$$$){
|
|||||||
my $hash = $defs{$name};
|
my $hash = $defs{$name};
|
||||||
my $aclvl = $hash->{READINGS}{"level"}{VAL};
|
my $aclvl = $hash->{READINGS}{"level"}{VAL};
|
||||||
my $msg = '';
|
my $msg = '';
|
||||||
|
my $mga;
|
||||||
|
my $cmd;
|
||||||
|
|
||||||
#-- sharpening the alarm
|
#-- sharpening the alarm
|
||||||
if( $act eq "sharp" ){
|
if( $act eq "sharp" ){
|
||||||
@ -333,15 +389,19 @@ sub Alarm_Sharp($$$$$){
|
|||||||
$msg = "[Alarm $level] sharpened from device $dev with event $evt";
|
$msg = "[Alarm $level] sharpened from device $dev with event $evt";
|
||||||
CommandAttr(undef,$name.' level'.$level.'xec sharp');
|
CommandAttr(undef,$name.' level'.$level.'xec sharp');
|
||||||
Log3 $hash,3,$msg;
|
Log3 $hash,3,$msg;
|
||||||
|
#-- unsharpening implies canceling as well
|
||||||
}elsif( $act eq "unsharp"){
|
}elsif( $act eq "unsharp"){
|
||||||
$msg = "[Alarm $level] unsharpened from device $dev with event $evt";
|
$msg = "[Alarm $level] unsharpened from device $dev with event $evt";
|
||||||
CommandAttr (undef,$name.' level'.$level.'xec unsharp');
|
CommandAttr (undef,$name.' level'.$level.'xec unsharp');
|
||||||
#-- unsharpening implies canceling as well
|
|
||||||
readingsSingleUpdate( $hash, "state", "Canceled", 0 );
|
|
||||||
readingsSingleUpdate( $hash, "level", "none", 0 );
|
|
||||||
#-- calling actors
|
#-- calling actors
|
||||||
my $cmd = AttrVal($name, "level".$level."offact", 0);
|
$cmd = AttrVal($name, "level".$level."offact", 0);
|
||||||
fhem($cmd);
|
fhem($cmd);
|
||||||
|
readingsSingleUpdate( $hash, "level".$level,"off",0 );
|
||||||
|
$mga = " Level $level canceled";
|
||||||
|
readingsSingleUpdate( $hash, "short", $mga, 0);
|
||||||
|
$mga = Alarm_getstate($hash)." ".$mga;
|
||||||
|
readingsSingleUpdate( $hash, "state", $mga, 0 );
|
||||||
|
$msg = "[Alarm $level] canceled from device $dev";
|
||||||
Log3 $hash,3,$msg;
|
Log3 $hash,3,$msg;
|
||||||
}
|
}
|
||||||
return $msg;
|
return $msg;
|
||||||
@ -544,6 +604,9 @@ sub Alarm_Html($)
|
|||||||
my $hash = $defs{$name};
|
my $hash = $defs{$name};
|
||||||
my $id = $defs{$name}{NR};
|
my $id = $defs{$name}{NR};
|
||||||
|
|
||||||
|
#--
|
||||||
|
readingsSingleUpdate( $hash, "state", Alarm_getstate($hash)." ".$hash->{READINGS}{"short"}{VAL}, 0 );
|
||||||
|
|
||||||
#--
|
#--
|
||||||
my $lockstate = ($hash->{READINGS}{lockstate}{VAL}) ? $hash->{READINGS}{lockstate}{VAL} : "unlock";
|
my $lockstate = ($hash->{READINGS}{lockstate}{VAL}) ? $hash->{READINGS}{lockstate}{VAL} : "unlock";
|
||||||
my $showhelper = ($lockstate eq "unlock") ? 1 : 0;
|
my $showhelper = ($lockstate eq "unlock") ? 1 : 0;
|
||||||
@ -667,7 +730,71 @@ sub Alarm_Html($)
|
|||||||
|
|
||||||
<a name="Alarm"></a>
|
<a name="Alarm"></a>
|
||||||
<h3>Alarm</h3>
|
<h3>Alarm</h3>
|
||||||
|
<p> FHEM module to set up a House Alarm System with 8 different alarm levels</p>
|
||||||
|
<br />
|
||||||
|
<br />
|
||||||
|
<a name="Alarmdefine"></a>
|
||||||
|
<h4>Define</h4>
|
||||||
|
<p>
|
||||||
|
<code>define <name> Alarm</code>
|
||||||
|
<br />Defines the Alarm system.
|
||||||
|
</p>
|
||||||
|
<br />
|
||||||
|
<a name="Alarmset"></a>
|
||||||
|
<h4>Set</h4>
|
||||||
|
<ul>
|
||||||
|
<li><a name="alarm_cancel">
|
||||||
|
<code>set <name> cancel <level></code>
|
||||||
|
</a>
|
||||||
|
<br/>cancels an alarm of level <level>, where <level> = 1..7
|
||||||
|
</li>
|
||||||
|
<li><a name="alarm_sharp">
|
||||||
|
<code>set <name> sharp <level></code><br/>
|
||||||
|
<code>set <name> unsharp <level></code>
|
||||||
|
</a>
|
||||||
|
<br/>sets the alarm of level <level> to sharp (i.e., active) or unsharp (i.e., inactive), where <level> = 1..7
|
||||||
|
</li>
|
||||||
|
<li><a name="alarm_lock">
|
||||||
|
<code>set <name> lock</code><br/>
|
||||||
|
<code>set <name> unlock</code>
|
||||||
|
</a>
|
||||||
|
<br/>sets the lockstate of the alarm module to <i>locked</i> (i.e., alarm setups may not be changed)
|
||||||
|
resp. <i>unlocked</i> (i.e., alarm setups may be changed>)</li>
|
||||||
|
</ul>
|
||||||
|
<br />
|
||||||
|
<a name="Alarmget"></a>
|
||||||
|
<h4>Get</h4>
|
||||||
|
<ul>
|
||||||
|
<li><a name="alarm_version"></a>
|
||||||
|
<code>get <name> version</code>
|
||||||
|
<br />Display the version of the module</li>
|
||||||
|
</ul>
|
||||||
|
<br />
|
||||||
|
<a name="Alarmattr"></a>
|
||||||
|
<h4>Attributes</h4>
|
||||||
|
<ul>
|
||||||
|
<li><a name="alarm_lockstate"><code>attr <name> lockstate locked|unlocked</code></a>
|
||||||
|
<br /><i>locked</i> means that alarm setups may not be changed,
|
||||||
|
<i>unlocked</i> means that alarm setups may be changed></li>
|
||||||
|
<li><a name="alarm_statedisplay"><code>attr <name> statedisplay simple,color,table,none</code></a>
|
||||||
|
<br />defines how the state of all eight alarm levels is shown. Example for the case when only alarm no. 2 is raised:
|
||||||
|
<ul>
|
||||||
|
<li> simple=OOXOOOOO</li>
|
||||||
|
<li> color=<span style="color:green"> 0 1 <span style="width:1ex;color:red">2</span> 3 4 5 6 7</span></li>
|
||||||
|
<li> table=<table><tr style="height:1ex"><td style="width:1ex;background-color:green"/><td style="width:1ex;background-color:green"/><td style="width:1ex;background-color:red"/><td style="width:1ex;background-color:green"/><td style="width:1ex;background-color:green"/><td style="width:1ex;background-color:green"/><td style="width:1ex;background-color:green"/><td style="width:1ex;background-color:green"/></tr></table> </li>
|
||||||
|
<li> none=no state display</li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
<li><a name="alarm_internals"/>For each of the 8 alarm levels, several attributes hold the alarm setup.
|
||||||
|
They should not be changed by hand, but through the web interface to avoid confusion:
|
||||||
|
<code>level<level>start, level<level>end, level<level>msg, level<level>xec,
|
||||||
|
level<level>onact, level<level>offact</code></li>
|
||||||
|
<li>Standard attributes <a href="#alias">alias</a>, <a href="#comment">comment</a>, <a
|
||||||
|
href="#event-on-update-reading">event-on-update-reading</a>, <a
|
||||||
|
href="#event-on-change-reading">event-on-change-reading</a>, <a href="#room"
|
||||||
|
>room</a>, <a href="#eventMap">eventMap</a>, <a href="#loglevel">loglevel</a>,
|
||||||
|
<a href="#webCmd">webCmd</a></li>
|
||||||
|
</ul>
|
||||||
=end html
|
=end html
|
||||||
=begin html_DE
|
=begin html_DE
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user