98_MSwitch.pm:add Internal MODEL (Full,Notify,Toggle,Dummy)

git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@18084 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
Byte09 2018-12-29 13:33:29 +00:00
parent 712c0c4e80
commit 0fd56ff3ae

View File

@ -27,7 +27,6 @@
################################################################# #################################################################
# Todo's: # Todo's:
# reading las_cmd fehlerhaft bei befehlen mit delay # reading las_cmd fehlerhaft bei befehlen mit delay
# evtcount einführen
# del delays kontrollieren # del delays kontrollieren
#--------------------------------------------------------------- #---------------------------------------------------------------
# #
@ -61,7 +60,6 @@ use POSIX;
my $preconf = ""; my $preconf = "";
my $verzeichnis = "./FHEM/MSwitch"; my $verzeichnis = "./FHEM/MSwitch";
if ( -d $verzeichnis ) { if ( -d $verzeichnis ) {
opendir( DIR, $verzeichnis ); opendir( DIR, $verzeichnis );
while ( my $entry = readdir(DIR) ) { while ( my $entry = readdir(DIR) ) {
my $dat = $entry; my $dat = $entry;
@ -177,7 +175,6 @@ my %sets = (
"change_renamed" => "" "change_renamed" => ""
); );
# "exec_cmd1+2" => "noArg",
my %gets = ( my %gets = (
"active_timer" => "noArg", "active_timer" => "noArg",
"restore_MSwitch_Data" => "noArg", "restore_MSwitch_Data" => "noArg",
@ -188,7 +185,6 @@ my %gets = (
sub MSwitch_Initialize($) { sub MSwitch_Initialize($) {
my ($hash) = @_; my ($hash) = @_;
$hash->{SetFn} = "MSwitch_Set"; $hash->{SetFn} = "MSwitch_Set";
$hash->{AsyncOutput} = "MSwitch_AsyncOutput"; $hash->{AsyncOutput} = "MSwitch_AsyncOutput";
$hash->{RenameFn} = "MSwitch_Rename"; $hash->{RenameFn} = "MSwitch_Rename";
@ -236,19 +232,15 @@ sub MSwitch_Initialize($) {
. " setList:textField-long " . " setList:textField-long "
. " readingList:textField-long " . " readingList:textField-long "
. $readingFnAttributes; . $readingFnAttributes;
$hash->{FW_addDetailToSummary} = 0; $hash->{FW_addDetailToSummary} = 0;
} }
#################### EVT_CMD1_COUNT ####################
sub MSwitch_Rename($) { sub MSwitch_Rename($) {
# routine nicht in funktion # routine nicht in funktion
my ( $new_name, $old_name ) = @_; my ( $new_name, $old_name ) = @_;
my $hash_new = $defs{$new_name}; my $hash_new = $defs{$new_name};
$modules{MSwitch}{defptr}{$new_name} = $hash_new; $modules{MSwitch}{defptr}{$new_name} = $hash_new;
} }
#################### ####################
sub MSwitch_Copy ($) { sub MSwitch_Copy ($) {
my ( $old_name, $new_name ) = @_; my ( $old_name, $new_name ) = @_;
@ -256,14 +248,12 @@ sub MSwitch_Copy ($) {
my @areadings = my @areadings =
qw(.Device_Affected .Device_Affected_Details .Device_Events .First_init .Trigger_Whitelist .Trigger_cmd_off .Trigger_cmd_on .Trigger_condition .Trigger_off .Trigger_on .Trigger_time .V_Check last_exec_cmd Trigger_device Trigger_log last_event state .sysconf Sys_Extension) qw(.Device_Affected .Device_Affected_Details .Device_Events .First_init .Trigger_Whitelist .Trigger_cmd_off .Trigger_cmd_on .Trigger_condition .Trigger_off .Trigger_on .Trigger_time .V_Check last_exec_cmd Trigger_device Trigger_log last_event state .sysconf Sys_Extension)
; #alle readings ; #alle readings
my $cs = "attr $new_name disable 1"; my $cs = "attr $new_name disable 1";
my $errors = AnalyzeCommandChain( undef, $cs ); my $errors = AnalyzeCommandChain( undef, $cs );
if ( defined($errors) ) { if ( defined($errors) ) {
MSwitch_LOG( $new_name, 1, "ERROR $cs" ); MSwitch_LOG( $new_name, 1, "ERROR $cs" );
} }
foreach my $key (@areadings) { foreach my $key (@areadings) {
my $tmp = ReadingsVal( $old_name, $key, 'undef' ); my $tmp = ReadingsVal( $old_name, $key, 'undef' );
fhem( "setreading " . $new_name . " " . $key . " " . $tmp ); fhem( "setreading " . $new_name . " " . $key . " " . $tmp );
@ -306,15 +296,12 @@ sub MSwitch_summary($) {
my $optiontime; my $optiontime;
my $devtitletime = ''; my $devtitletime = '';
my $triggertime = ReadingsVal( $name, 'Trigger_device', 'not defined' ); my $triggertime = ReadingsVal( $name, 'Trigger_device', 'not defined' );
my $devtime = ReadingsVal( $name, '.Trigger_time', '' ); my $devtime = ReadingsVal( $name, '.Trigger_time', '' );
$devtime =~ s/\[//g; $devtime =~ s/\[//g;
$devtime =~ s/\]/ /g; $devtime =~ s/\]/ /g;
my @devtime = split( /~/, $devtime ); my @devtime = split( /~/, $devtime );
$optiontime .= "<option value=\"Time:\">At: aktiv</option>"; $optiontime .= "<option value=\"Time:\">At: aktiv</option>";
my $count = @devtime; my $count = @devtime;
$devtime[0] =~ s/on/on+cmd1: /g if defined $devtime[0]; $devtime[0] =~ s/on/on+cmd1: /g if defined $devtime[0];
$devtime[1] =~ s/off/off+cmd2: /g if defined $devtime[1]; $devtime[1] =~ s/off/off+cmd2: /g if defined $devtime[1];
$devtime[2] =~ s/ononly/only cmd1: /g if defined $devtime[2]; $devtime[2] =~ s/ononly/only cmd1: /g if defined $devtime[2];
@ -351,6 +338,7 @@ sub MSwitch_summary($) {
. $optiontime . $optiontime
. "</select>"; . "</select>";
} }
if ( $info eq 'No Info saved at ATTR omment' ) { if ( $info eq 'No Info saved at ATTR omment' ) {
$ret .= $ret .=
"<input disabled title=\"" "<input disabled title=\""
@ -366,6 +354,9 @@ sub MSwitch_summary($) {
. $info . "')\">"; . $info . "')\">";
} }
$ret .= " <input disabled name='Text1' size='10' type='text' value='Mode: "
. $hash->{MODEL} . "'> ";
if ( $trigger eq 'no_trigger' || $trigger eq 'undef' || $trigger eq '' ) { if ( $trigger eq 'no_trigger' || $trigger eq 'undef' || $trigger eq '' ) {
$triggerc = 0; $triggerc = 0;
if ( $triggerc != 0 || $timer != 0 ) { if ( $triggerc != 0 || $timer != 0 ) {
@ -609,6 +600,7 @@ sub MSwitch_Define($$) {
$hash->{Version_Modul} = $version; $hash->{Version_Modul} = $version;
$hash->{Version_Datenstruktur} = $vupdate; $hash->{Version_Datenstruktur} = $vupdate;
$hash->{Version_autoupdate} = $autoupdate; $hash->{Version_autoupdate} = $autoupdate;
$hash->{MODEL} = 'Full';
if ( $init_done && !defined( $hash->{OLDDEF} ) ) { if ( $init_done && !defined( $hash->{OLDDEF} ) ) {
my $timecond = gettimeofday() + 5; my $timecond = gettimeofday() + 5;
@ -956,7 +948,6 @@ sub MSwitch_Set($@) {
my $devicemode = AttrVal( $name, 'MSwitch_Mode', 'Full' ); my $devicemode = AttrVal( $name, 'MSwitch_Mode', 'Full' );
my $delaymode = AttrVal( $name, 'MSwitch_Delete_Delays', '0' ); my $delaymode = AttrVal( $name, 'MSwitch_Delete_Delays', '0' );
if ( !exists( $sets{$cmd} ) ) { if ( !exists( $sets{$cmd} ) ) {
my @cList; my @cList;
@ -1083,24 +1074,17 @@ sub MSwitch_Set($@) {
################################## ##################################
if ( $cmd eq 'reset_cmd_count' ) { if ( $cmd eq 'reset_cmd_count' ) {
if ($args[0] eq "1") if ( $args[0] eq "1" ) {
{
delete( $hash->{READINGS}{EVT_CMD1_COUNT} ); delete( $hash->{READINGS}{EVT_CMD1_COUNT} );
} }
if ($args[0] eq "2") if ( $args[0] eq "2" ) {
{
delete( $hash->{READINGS}{EVT_CMD2_COUNT} ); delete( $hash->{READINGS}{EVT_CMD2_COUNT} );
} }
return; return;
} }
####################################### #######################################
if ( $cmd eq 'reload_timer' ) { if ( $cmd eq 'reload_timer' ) {
MSwitch_Clear_timer($hash); MSwitch_Clear_timer($hash);
@ -1336,7 +1320,6 @@ sub MSwitch_Set($@) {
$hash->{DEF} = $name . ' # ' . $devices; $hash->{DEF} = $name . ' # ' . $devices;
} }
} }
} }
else { else {
@ -1575,7 +1558,6 @@ sub MSwitch_Set($@) {
MSwitch_Delete_Delay( $hash, $name ); MSwitch_Delete_Delay( $hash, $name );
} }
############ ############
# ausführen des off befehls # ausführen des off befehls
my $zweig = 'nicht definiert'; my $zweig = 'nicht definiert';
$zweig = "cmd1" if $cmd eq "on"; $zweig = "cmd1" if $cmd eq "on";
@ -1732,7 +1714,6 @@ sub MSwitch_Set($@) {
last LOOP1; last LOOP1;
} }
} }
} }
else { else {
@ -1851,11 +1832,9 @@ sub MSwitch_Set($@) {
last LOOP1; last LOOP1;
} }
} }
} }
} }
} }
if ( $devicemode ne "Notify" ) { if ( $devicemode ne "Notify" ) {
@ -1872,13 +1851,8 @@ sub MSwitch_Set($@) {
MSwitch_LOG( $name, 6, "$name: uebergabe an sub execute " ) MSwitch_LOG( $name, 6, "$name: uebergabe an sub execute " )
if $anzahl > 0; if $anzahl > 0;
MSwitch_Cmd( $hash, @cmdpool ) if $anzahl > 0; MSwitch_Cmd( $hash, @cmdpool ) if $anzahl > 0;
#$lastdevice = $device ;
#readingsSingleUpdate( $hash, "last_cmd", $hash->{helper}{priorityids}{$lastdevice}, 1 );
return; return;
} }
return; return;
} }
@ -1897,14 +1871,10 @@ sub MSwitch_Cmd(@) {
MSwitch_LOG( $Name, 6, "$Name: execute -> " . $cmds ); MSwitch_LOG( $Name, 6, "$Name: execute -> " . $cmds );
my @cut = split( /\|/, $cmds ); my @cut = split( /\|/, $cmds );
$cmds = $cut[0]; $cmds = $cut[0];
#ersetze platzhakter vor ausführung #ersetze platzhakter vor ausführung
#change # $cmds =~ s/#\[wa\]/|/g; #neu #change # $cmds =~ s/#\[wa\]/|/g; #neu
my $device = $cut[1]; my $device = $cut[1];
$lastdevice = $device; $lastdevice = $device;
my $toggle = ''; my $toggle = '';
if ( $cmds =~ m/set (.*)(MSwitchtoggle)(.*)/ ) { if ( $cmds =~ m/set (.*)(MSwitchtoggle)(.*)/ ) {
MSwitch_LOG( $Name, 6, MSwitch_LOG( $Name, 6,
@ -2195,23 +2165,28 @@ sub MSwitch_Attr(@) {
my $cs = "setstate $name ???"; my $cs = "setstate $name ???";
my $errors = AnalyzeCommandChain( undef, $cs ); my $errors = AnalyzeCommandChain( undef, $cs );
$hash->{MODEL} = 'Full' if $aVal eq 'Full';
$hash->{MODEL} = 'Toggle' if $aVal eq 'Toggle';
} }
if ( $aName eq 'MSwitch_Mode' && ( $aVal eq 'Dummy' ) ) { if ( $aName eq 'MSwitch_Mode' && ( $aVal eq 'Dummy' ) ) {
MSwitch_Delete_Delay( $hash, 'all' ); MSwitch_Delete_Delay( $hash, 'all' );
MSwitch_Clear_timer($hash); MSwitch_Clear_timer($hash);
$hash->{NOTIFYDEV} = 'no_trigger'; $hash->{NOTIFYDEV} = 'no_trigger';
$hash->{MODEL} = 'Dummy';
} }
if ( $aName eq 'MSwitch_Mode' && $aVal eq 'Notify' ) { if ( $aName eq 'MSwitch_Mode' && $aVal eq 'Notify' ) {
readingsSingleUpdate( $hash, "state", 'active', 1 ); readingsSingleUpdate( $hash, "state", 'active', 1 );
$hash->{MODEL} = 'Notify';
my $cs = "setstate $name active"; my $cs = "setstate $name active";
my $errors = AnalyzeCommandChain( undef, $cs ); my $errors = AnalyzeCommandChain( undef, $cs );
if ( defined($errors) ) { if ( defined($errors) ) {
MSwitch_LOG( $name, 1, MSwitch_LOG( $name, 1,
"$name MSwitch_Notify: Fehler bei Befehlsausführung $errors -> Comand: $_ " "$name MSwitch_Notify: Fehler bei Befehlsausführung $errors -> Comand: $_ "
. __LINE__ ); . __LINE__ );
} }
} }
@ -2246,8 +2221,6 @@ sub MSwitch_Attr(@) {
} }
} }
return undef; return undef;
} }
@ -2294,25 +2267,20 @@ sub MSwitch_Notify($$) {
my $resetcmd1 = AttrVal( $ownName, "MSwitch_Reset_EVT_CMD1_COUNT", 0 ); my $resetcmd1 = AttrVal( $ownName, "MSwitch_Reset_EVT_CMD1_COUNT", 0 );
my $resetcmd2 = AttrVal( $ownName, "MSwitch_Reset_EVT_CMD2_COUNT", 0 ); my $resetcmd2 = AttrVal( $ownName, "MSwitch_Reset_EVT_CMD2_COUNT", 0 );
if ( $resetcmd1 > 0
if ($resetcmd1 > 0 && ReadingsVal( $ownName, 'EVT_CMD1_COUNT', '0' ) >= $resetcmd1) && ReadingsVal( $ownName, 'EVT_CMD1_COUNT', '0' ) >= $resetcmd1 )
{ {
readingsSingleUpdate( $own_hash, "EVT_CMD1_COUNT", 0, $showevents ); readingsSingleUpdate( $own_hash, "EVT_CMD1_COUNT", 0, $showevents );
} }
if ($resetcmd2 > 0 && ReadingsVal( $ownName, 'EVT_CMD2_COUNT', '0' ) >= $resetcmd1) if ( $resetcmd2 > 0
&& ReadingsVal( $ownName, 'EVT_CMD2_COUNT', '0' ) >= $resetcmd1 )
{ {
readingsSingleUpdate( $own_hash, "EVT_CMD2_COUNT", 0, $showevents ); readingsSingleUpdate( $own_hash, "EVT_CMD2_COUNT", 0, $showevents );
} }
#readingsSingleUpdate( $own_hash, "trigdev0", 'anfang ', 1 ); # nur zu testzwecken
# nur abfragen für eigenes Notify # nur abfragen für eigenes Notify
if ( $init_done if ( $init_done
&& $devName eq "global" && $devName eq "global"
@ -2321,8 +2289,6 @@ if ($resetcmd2 > 0 && ReadingsVal( $ownName, 'EVT_CMD2_COUNT', '0' ) >= $resetcm
# reaktion auf eigenes notify start / define / modify # reaktion auf eigenes notify start / define / modify
my $timecond = gettimeofday() + 5; my $timecond = gettimeofday() + 5;
InternalTimer( $timecond, "MSwitch_LoadHelper", $own_hash ); InternalTimer( $timecond, "MSwitch_LoadHelper", $own_hash );
# return;
} }
if ( $init_done if ( $init_done
@ -2332,8 +2298,6 @@ if ($resetcmd2 > 0 && ReadingsVal( $ownName, 'EVT_CMD2_COUNT', '0' ) >= $resetcm
# reaktion auf eigenes notify start / define / modify # reaktion auf eigenes notify start / define / modify
my $timecond = gettimeofday() + 5; my $timecond = gettimeofday() + 5;
InternalTimer( $timecond, "MSwitch_LoadHelper", $own_hash ); InternalTimer( $timecond, "MSwitch_LoadHelper", $own_hash );
# return;
} }
if ( $devName eq "global" if ( $devName eq "global"
@ -2341,8 +2305,6 @@ if ($resetcmd2 > 0 && ReadingsVal( $ownName, 'EVT_CMD2_COUNT', '0' ) >= $resetcm
{ {
# reaktion auf eigenes notify start / define / modify # reaktion auf eigenes notify start / define / modify
MSwitch_LoadHelper($own_hash); MSwitch_LoadHelper($own_hash);
# return;
} }
# nur abfragen für eigenes Notify ENDE # nur abfragen für eigenes Notify ENDE
@ -2492,8 +2454,6 @@ if ($resetcmd2 > 0 && ReadingsVal( $ownName, 'EVT_CMD2_COUNT', '0' ) >= $resetcm
#MSwitch_LOG( $ownName, 0, "$ownName: event -> $event " ); #MSwitch_LOG( $ownName, 0, "$ownName: event -> $event " );
$own_hash->{eventsave} = 'unsaved'; $own_hash->{eventsave} = 'unsaved';
MSwitch_LOG( $ownName, 5, MSwitch_LOG( $ownName, 5,
"$ownName: eingehendes Event -> " "$ownName: eingehendes Event -> "
@ -2508,8 +2468,6 @@ if ($resetcmd2 > 0 && ReadingsVal( $ownName, 'EVT_CMD2_COUNT', '0' ) >= $resetcm
$eventcopy =~ s/: /:/s; # BUG !!!!!!!!!!!!!!!!!!!!!!!! $eventcopy =~ s/: /:/s; # BUG !!!!!!!!!!!!!!!!!!!!!!!!
$event =~ s/: /:/s; $event =~ s/: /:/s;
# readingsSingleUpdate( $own_hash, "incomming", $eventcopy, 1 );
# Teste auf einhaltung Triggercondition für ausführung zweig 1 und zweig 2 # Teste auf einhaltung Triggercondition für ausführung zweig 1 und zweig 2
# kann ggf an den anfang der routine gesetzt werden ? test erforderlich # kann ggf an den anfang der routine gesetzt werden ? test erforderlich
my $triggercondition = my $triggercondition =
@ -2561,7 +2519,6 @@ if ($resetcmd2 > 0 && ReadingsVal( $ownName, 'EVT_CMD2_COUNT', '0' ) >= $resetcm
. $eventcopy1 ); . $eventcopy1 );
next EVENT; next EVENT;
} }
} }
} }
@ -2608,7 +2565,6 @@ if ($resetcmd2 > 0 && ReadingsVal( $ownName, 'EVT_CMD2_COUNT', '0' ) >= $resetcm
my $testvar = ''; my $testvar = '';
my $check = 0; my $check = 0;
#test auf zweige cmd1/2 and switch MSwitch on/off #test auf zweige cmd1/2 and switch MSwitch on/off
if ( $triggeron ne 'no_trigger' ) { if ( $triggeron ne 'no_trigger' ) {
MSwitch_LOG( $ownName, 6, MSwitch_LOG( $ownName, 6,
@ -2650,10 +2606,6 @@ if ($resetcmd2 > 0 && ReadingsVal( $ownName, 'EVT_CMD2_COUNT', '0' ) >= $resetcm
"$ownName: checktrigger ergebniss -> " . $testvar ); "$ownName: checktrigger ergebniss -> " . $testvar );
} }
#test auf zweige cmd1/2 and switch MSwitch on/off ENDE #test auf zweige cmd1/2 and switch MSwitch on/off ENDE
#test auf zweige cmd1/2 only #test auf zweige cmd1/2 only
@ -2743,51 +2695,44 @@ $foundcmd2 = 1;
} }
} }
#foundcmd1/2 #foundcmd1/2
if( $foundcmd1 eq "1" && AttrVal( $ownName, "MSwitch_Reset_EVT_CMD1_COUNT" ,'undef') ne 'undef') if ( $foundcmd1 eq "1"
&& AttrVal( $ownName, "MSwitch_Reset_EVT_CMD1_COUNT", 'undef' ) ne
'undef' )
{ {
my $inhalt = ReadingsVal( $ownName, 'EVT_CMD1_COUNT', '0' ); my $inhalt = ReadingsVal( $ownName, 'EVT_CMD1_COUNT', '0' );
if ($resetcmd1 == 0 ) if ( $resetcmd1 == 0 ) {
{
$inhalt++; $inhalt++;
readingsSingleUpdate( $own_hash, "EVT_CMD1_COUNT", $inhalt, $showevents ); readingsSingleUpdate( $own_hash, "EVT_CMD1_COUNT", $inhalt,
$showevents );
} }
elsif ($resetcmd1 > 0 && $inhalt < $resetcmd1) elsif ( $resetcmd1 > 0 && $inhalt < $resetcmd1 ) {
{
$inhalt++; $inhalt++;
readingsSingleUpdate( $own_hash, "EVT_CMD1_COUNT", $inhalt, $showevents ); readingsSingleUpdate( $own_hash, "EVT_CMD1_COUNT", $inhalt,
$showevents );
} }
} }
if ( $foundcmd2 eq "1"
#MSwitch_LOG( $ownName, 0, "$ownName: cmdcount erreicht -> $foundcmd1 - $foundcmd2 " ); && AttrVal( $ownName, "MSwitch_Reset_EVT_CMD2_COUNT", 'undef' ) ne
'undef' )
if( $foundcmd2 eq "1" && AttrVal( $ownName, "MSwitch_Reset_EVT_CMD2_COUNT" ,'undef') ne 'undef')
{ {
my $inhalt = ReadingsVal( $ownName, 'EVT_CMD2_COUNT', '0' ); my $inhalt = ReadingsVal( $ownName, 'EVT_CMD2_COUNT', '0' );
if ($resetcmd2 == 0 ) if ( $resetcmd2 == 0 ) {
{
$inhalt++; $inhalt++;
readingsSingleUpdate( $own_hash, "EVT_CMD2_COUNT", $inhalt, $showevents ); readingsSingleUpdate( $own_hash, "EVT_CMD2_COUNT", $inhalt,
$showevents );
} }
elsif ($resetcmd2 > 0 && $inhalt < $resetcmd2) elsif ( $resetcmd2 > 0 && $inhalt < $resetcmd2 ) {
{
$inhalt++; $inhalt++;
readingsSingleUpdate( $own_hash, "EVT_CMD2_COUNT", $inhalt, $showevents ); readingsSingleUpdate( $own_hash, "EVT_CMD2_COUNT", $inhalt,
$showevents );
} }
} }
#ausführen aller cmds in @cmdarray nach triggertest aber vor conditiontest #ausführen aller cmds in @cmdarray nach triggertest aber vor conditiontest
#my @cmdarray1; #enthält auszuführende befehle nach conditiontest #my @cmdarray1; #enthält auszuführende befehle nach conditiontest
#schaltet zweig 3 und 4 #schaltet zweig 3 und 4
@ -3225,7 +3170,6 @@ sub MSwitch_fhemwebFn($$$$) {
} }
######################################### #########################################
# SHOW # SHOW
# teste auf grössere PRIORITY als anzahl devices # teste auf grössere PRIORITY als anzahl devices
foreach (@testidsdev) foreach (@testidsdev)
@ -3737,7 +3681,6 @@ sub MSwitch_fhemwebFn($$$$) {
$detailhtml = $detailhtml . "priority: " . $aktfolge . "&nbsp;"; $detailhtml = $detailhtml . "priority: " . $aktfolge . "&nbsp;";
# ende # ende
# show # show
# showfolgehtml # showfolgehtml
@ -4675,16 +4618,13 @@ sub MSwitch_fhemwebFn($$$$) {
my $inhalt = "execute 'cmd1' only at :"; my $inhalt = "execute 'cmd1' only at :";
my $inhalt1 = "execute 'cmd2' only at :"; my $inhalt1 = "execute 'cmd2' only at :";
my $inhalt6 = "execute 'cmd1+cmd2' only at :"; my $inhalt6 = "execute 'cmd1+cmd2' only at :";
my $inhalt2 = "execute 'cmd1' only"; my $inhalt2 = "execute 'cmd1' only";
my $inhalt3 = "execute 'cmd2' only"; my $inhalt3 = "execute 'cmd2' only";
my $inhalt4 = "switch MSwitch on + execute 'cmd1' at :"; my $inhalt4 = "switch MSwitch on + execute 'cmd1' at :";
my $inhalt5 = "switch $Name on + execute 'cmd1'"; my $inhalt5 = "switch $Name on + execute 'cmd1'";
my $displaynot = ''; my $displaynot = '';
my $displayntog = ''; my $displayntog = '';
my $help = ""; my $help = "";
if ( AttrVal( $Name, 'MSwitch_Help', "0" ) eq '1' ) { if ( AttrVal( $Name, 'MSwitch_Help', "0" ) eq '1' ) {
$help = $help =
@ -6088,10 +6028,8 @@ sub MSwitch_Exec_Notif($$$$$) {
$out = $devicedetails{$ekey}; $out = $devicedetails{$ekey};
} }
# MSwitch_LOG( $name, 0,"$name: delaymode -> " . $delaymode ." - ".$device ); # MSwitch_LOG( $name, 0,"$name: delaymode -> " . $delaymode ." - ".$device );
if ( $delaymode eq '1' ) { if ( $delaymode eq '1' ) {
MSwitch_Delete_Delay( $hash, $device ); MSwitch_Delete_Delay( $hash, $device );
} }
@ -6565,9 +6503,6 @@ sub MSwitch_Restartcmd($) {
"$name: repeattime nach test -> " "$name: repeattime nach test -> "
. $devicedetails{ $device . '_repeattime' } ); . $devicedetails{ $device . '_repeattime' } );
#MSwitch_LOG( $name, 0, "$name repeattime ".$devicedetails{ $device . '_repeattime' } );
#MSwitch_LOG( $name, 0, "$name repeatcount ".$devicedetails{ $device . '_repeatcount' });
###################################### ######################################
if ( AttrVal( $name, 'MSwitch_Expert', "0" ) eq '1' if ( AttrVal( $name, 'MSwitch_Expert', "0" ) eq '1'
&& $devicedetails{ $device . '_repeatcount' } > 0 && $devicedetails{ $device . '_repeatcount' } > 0
@ -6657,9 +6592,6 @@ sub MSwitch_checkcondition($$$) {
$condition =~ s/\[\$EVT_CMD1_COUNT\]/"\$EVT_CMD1_COUNT"/g; $condition =~ s/\[\$EVT_CMD1_COUNT\]/"\$EVT_CMD1_COUNT"/g;
$condition =~ s/\[\$EVT_CMD2_COUNT\]/"\$EVT_CMD2_COUNT"/g; $condition =~ s/\[\$EVT_CMD2_COUNT\]/"\$EVT_CMD2_COUNT"/g;
MSwitch_LOG( $name, 6, MSwitch_LOG( $name, 6,
"$name: Checkcondition - Parameter condition -> " . $condition ); "$name: Checkcondition - Parameter condition -> " . $condition );
MSwitch_LOG( $name, 6, MSwitch_LOG( $name, 6,
@ -6668,8 +6600,6 @@ sub MSwitch_checkcondition($$$) {
if ( !defined($condition) ) { return 'true'; } if ( !defined($condition) ) { return 'true'; }
if ( $condition eq '' ) { return 'true'; } if ( $condition eq '' ) { return 'true'; }
#MSwitch_LOG( $name, 0,"$name: searchstring erreicht -> " .$condition );
###### perlersetzung ###### perlersetzung
############## ##############
@ -6683,8 +6613,6 @@ sub MSwitch_checkcondition($$$) {
my $lastpart = $3; my $lastpart = $3;
my $exec = "\$field = " . $2; my $exec = "\$field = " . $2;
#MSwitch_LOG( $name, 0,"$name: secondpart -> " .$secondpart );
if ( $secondpart =~ m/(!\$.*|\$.*)/ ) { if ( $secondpart =~ m/(!\$.*|\$.*)/ ) {
#MSwitch_LOG( $name, 0,"$name: found var exec -> " .$field ); #MSwitch_LOG( $name, 0,"$name: found var exec -> " .$field );
@ -6694,15 +6622,10 @@ sub MSwitch_checkcondition($$$) {
eval($exec); eval($exec);
} }
#MSwitch_LOG( $name, 0,"$name: exec -> " .$exec );
# MSwitch_LOG( $name, 0,"$name: field -> " .$field );
#
#if ($field eq "!\$we" || $field eq "\$we" )
if ( $field =~ m/([0-9]{2}):([0-9]{2}):([0-9]{2})/ ) { if ( $field =~ m/([0-9]{2}):([0-9]{2}):([0-9]{2})/ ) {
my $hh = $1; my $hh = $1;
if ( $hh > 23 ) { $hh = $hh - 24 } if ( $hh > 23 ) { $hh = $hh - 24 }
#if ( $hh < 10 ) { $hh = "0" . $hh } #if ( $hh < 10 ) { $hh = "0" . $hh }
$field = $hh . ":" . $2; $field = $hh . ":" . $2;
} }
@ -6713,8 +6636,6 @@ sub MSwitch_checkcondition($$$) {
last if $x > 10; #notausstieg last if $x > 10; #notausstieg
} }
# MSwitch_LOG( $name, 0,"$name: searchstring erreicht -> " .$condition );
if ( $attrrandomnumber ne '' ) { if ( $attrrandomnumber ne '' ) {
MSwitch_Createnumber($hash); MSwitch_Createnumber($hash);
} }
@ -6789,7 +6710,6 @@ sub MSwitch_checkcondition($$$) {
$condition =~ s/\$EVTPART2/$evtparts[1]/ig; $condition =~ s/\$EVTPART2/$evtparts[1]/ig;
$condition =~ s/\$EVTPART3/$evtparts[2]/ig; $condition =~ s/\$EVTPART3/$evtparts[2]/ig;
my $evtcmd1 = ReadingsVal( $name, 'EVT_CMD1_COUNT', '0' ); my $evtcmd1 = ReadingsVal( $name, 'EVT_CMD1_COUNT', '0' );
my $evtcmd2 = ReadingsVal( $name, 'EVT_CMD2_COUNT', '0' ); my $evtcmd2 = ReadingsVal( $name, 'EVT_CMD2_COUNT', '0' );
@ -6797,7 +6717,6 @@ sub MSwitch_checkcondition($$$) {
$condition =~ s/\$EVT_CMD2_COUNT/$evtcmd2/ig; $condition =~ s/\$EVT_CMD2_COUNT/$evtcmd2/ig;
MSwitch_LOG( $name, 5, "condition: " . $condition ); MSwitch_LOG( $name, 5, "condition: " . $condition );
###################################### ######################################
$condition =~ s/{!\$we}/ !\$we /ig; $condition =~ s/{!\$we}/ !\$we /ig;
@ -6885,14 +6804,6 @@ m/(.*?)(\[\[[a-zA-Z][a-zA-Z0-9_]{0,30}:[a-zA-Z0-9_]{0,30}\]-\[[a-zA-Z][a-zA-Z0-9
$part2 = $testhour . ':' . $testmin; $part2 = $testhour . ':' . $testmin;
} }
# else{
#$testhour = '0' . $testhour if $testhour < 10;
# $part2 = $testhour . ':' . $testmin;
#}
#MSwitch_LOG( $name, 0,"$name: Checkcondition - Parameter part2 -> " . $part2 );
$condition = $part2; $condition = $part2;
$condition = $1 . $condition if ( defined $1 ); $condition = $1 . $condition if ( defined $1 );
$condition = $condition . $5 if ( defined $5 ); $condition = $condition . $5 if ( defined $5 );
@ -6946,14 +6857,10 @@ m/(.*?)(\[\[[a-zA-Z][a-zA-Z0-9_]{0,30}:[a-zA-Z0-9_]{0,30}\]-\[[a-zA-Z][a-zA-Z0-9
# timerformatierung erkannt - auswerten über sub # timerformatierung erkannt - auswerten über sub
# my $param = $argarray[$count]; # my $param = $argarray[$count];
# MSwitch_LOG( $name, 0,
# "$name: Checkcondition - Parameter args -> " . $args );
$newargarray[$count] = MSwitch_Checkcond_time( $args, $name ); $newargarray[$count] = MSwitch_Checkcond_time( $args, $name );
} }
elsif ( $testarg =~ '[.*:.*]' ) { elsif ( $testarg =~ '[.*:.*]' ) {
# my $param = $argarray[$count];
# stateformatierung erkannt - auswerten über sub # stateformatierung erkannt - auswerten über sub
$newargarray[$count] = MSwitch_Checkcond_state( $args, $name ); $newargarray[$count] = MSwitch_Checkcond_state( $args, $name );
} }
@ -7039,13 +6946,6 @@ sub MSwitch_Checkcond_time($$) {
my $hour2 = substr( $condition, 6, 2 ); my $hour2 = substr( $condition, 6, 2 );
my $min2 = substr( $condition, 9, 2 ); my $min2 = substr( $condition, 9, 2 );
#MSwitch_LOG( $name, 0, "$name: timer-> " . $condition );
#MSwitch_LOG( $name, 0, "$name: hour1-> " . $hour1 );
#MSwitch_LOG( $name, 0, "$name: hour2-> " . $hour2 );
#MSwitch_LOG( $name, 0, "$name: min1-> " . $min1 );
#MSwitch_LOG( $name, 0, "$name: min2-> " . $min2 );
if ( $hour1 eq "24" ) # test auf 24 zeitangabe if ( $hour1 eq "24" ) # test auf 24 zeitangabe
{ {
$hour1 = "00"; $hour1 = "00";
@ -7065,31 +6965,21 @@ sub MSwitch_Checkcond_time($$) {
my $timecond1; my $timecond1;
my $timecond2; my $timecond2;
# MSwitch_LOG( $name, 0, "$name: hour1-> " . $hour1 );
# MSwitch_LOG( $name, 0, "$name: hour2-> " . $hour2 );
#MSwitch_LOG( $name, 0, "$name: akthour-> " . $akthour );
#my $time1;
my ( $tday, $tmonth, $tdate, $tn ); #my ($tday,$tmonth,$tdate,$tn,$time1); my ( $tday, $tmonth, $tdate, $tn ); #my ($tday,$tmonth,$tdate,$tn,$time1);
$timecondtest = localtime; $timecondtest = localtime;
$timecondtest =~ s/\s+/ /g; $timecondtest =~ s/\s+/ /g;
( $tday, $tmonth, $tdate, $tn, $time1 ) = split( / /, $timecondtest ); ( $tday, $tmonth, $tdate, $tn, $time1 ) = split( / /, $timecondtest );
$timecond1 = timelocal( '00', $min1, $hour1, $tdate, $tmonth, $time1 ); $timecond1 = timelocal( '00', $min1, $hour1, $tdate, $tmonth, $time1 );
$timecond2 = timelocal( '00', $min2, $hour2, $tdate, $tmonth, $time1 ); $timecond2 = timelocal( '00', $min2, $hour2, $tdate, $tmonth, $time1 );
my $timeaktuell =timelocal( '00', $aktmin, $akthour, $date, $month, $time1 ); my $timeaktuell =
timelocal( '00', $aktmin, $akthour, $date, $month, $time1 );
#MSwitch_LOG( $name, 0, "$name: timecond1-> " . $timecond1 );
#MSwitch_LOG( $name, 0, "$name: timecond2-> " . $timecond2 );
#MSwitch_LOG( $name, 0, "$name: timeaktuell-> " . $timeaktuell );
### new ### new
if ( $timeaktuell < $timecond2 && $timecond2 < $timecond1 ) if ( $timeaktuell < $timecond2 && $timecond2 < $timecond1 ) {
{
use constant SECONDS_PER_DAY => 60 * 60 * 24; use constant SECONDS_PER_DAY => 60 * 60 * 24;
$timecond1 = $timecond1 - SECONDS_PER_DAY; $timecond1 = $timecond1 - SECONDS_PER_DAY;
$adday = 1 $adday = 1;
} }
if ( $timeaktuell > $timecond1 && $timecond2 < $timecond1 ) if ( $timeaktuell > $timecond1 && $timecond2 < $timecond1 )
@ -7099,7 +6989,6 @@ sub MSwitch_Checkcond_time($$) {
$timecond2 = $timecond2 + SECONDS_PER_DAY; $timecond2 = $timecond2 + SECONDS_PER_DAY;
$adday = 1 $adday = 1
} }
######## old ######## old
@ -7121,7 +7010,6 @@ sub MSwitch_Checkcond_time($$) {
# } # }
################## ##################
############# timecondition 2 ############# timecondition 2
# my $timecond2; # my $timecond2;
# $timecondtest = localtime; # $timecondtest = localtime;
@ -7152,23 +7040,15 @@ sub MSwitch_Checkcond_time($$) {
# $timecond2 = timelocal( '00', $min2, $hour2, $tdate, $tmonth, $time1 ); # $timecond2 = timelocal( '00', $min2, $hour2, $tdate, $tmonth, $time1 );
# } # }
# my $timeaktuell = # my $timeaktuell =
# timelocal( '00', $aktmin, $akthour, $date, $month, $time1 ); # timelocal( '00', $aktmin, $akthour, $date, $month, $time1 );
my $return = "($timecond1 < $timeaktuell && $timeaktuell < $timecond2)"; my $return = "($timecond1 < $timeaktuell && $timeaktuell < $timecond2)";
if ( $days ne '' ) { if ( $days ne '' ) {
$daycondition = MSwitch_Checkcond_day( $days, $name, $adday, $day ); $daycondition = MSwitch_Checkcond_day( $days, $name, $adday, $day );
$return = "($return $daycondition)"; $return = "($return $daycondition)";
} }
#MSwitch_LOG( $name, 0, "$name: return-> " . $return);
return $return; return $return;
} }
#################### ####################
@ -7828,7 +7708,6 @@ sub MSwitch_Check_Event($$) {
my $triggerdevice = my $triggerdevice =
ReadingsVal( $Name, 'Trigger_device', 'no_trigger' ); ReadingsVal( $Name, 'Trigger_device', 'no_trigger' );
if ( ReadingsVal( $Name, 'Trigger_device', '' ) eq "all_events" ) { if ( ReadingsVal( $Name, 'Trigger_device', '' ) eq "all_events" ) {
$dev_hash = $hash; $dev_hash = $hash;
@ -8650,14 +8529,11 @@ sub MSwitch_EventBulk($$$$) {
my $evtfull = join( ':', @evtparts ); my $evtfull = join( ':', @evtparts );
$evtparts[2] = '' if !defined $evtparts[2]; $evtparts[2] = '' if !defined $evtparts[2];
#my $logmsg = $own_hash->{helper}{writelog};
$event =~ s/\[#dp\]/:/g; $event =~ s/\[#dp\]/:/g;
$evtfull =~ s/\[#dp\]/:/g; $evtfull =~ s/\[#dp\]/:/g;
$evtparts[1] =~ s/\[#dp\]/:/g if $evtparts[1]; $evtparts[1] =~ s/\[#dp\]/:/g if $evtparts[1];
$evtparts[2] =~ s/\[#dp\]/:/g if $evtparts[2]; $evtparts[2] =~ s/\[#dp\]/:/g if $evtparts[2];
#$evtparts[2] =~ s/\[#dp\]/:/g;
MSwitch_LOG( $name, 5, "aufruf eventbulk eventfullout: " . $evtfull ); MSwitch_LOG( $name, 5, "aufruf eventbulk eventfullout: " . $evtfull );
MSwitch_LOG( $name, 5, "aufruf eventbulk event " . $event ); MSwitch_LOG( $name, 5, "aufruf eventbulk event " . $event );
@ -8670,8 +8546,6 @@ sub MSwitch_EventBulk($$$$) {
$hash->{eventsave} = "saved"; $hash->{eventsave} = "saved";
readingsBeginUpdate($hash); readingsBeginUpdate($hash);
#readingsBulkUpdate( $hash, "showevents", $showevents ,$showevents ) ;
readingsBulkUpdate( $hash, "EVENT", $event, $showevents ) readingsBulkUpdate( $hash, "EVENT", $event, $showevents )
if $event ne ''; if $event ne '';
readingsBulkUpdate( $hash, "EVTFULL", $evtfull, $showevents ) readingsBulkUpdate( $hash, "EVTFULL", $evtfull, $showevents )
@ -8901,7 +8775,6 @@ sub MSwitch_confchange($$) {
my @changes = split( /\|/, $cs ); my @changes = split( /\|/, $cs );
foreach my $change (@changes) { foreach my $change (@changes) {
#MSwitch_LOG( $name, 5, "zu ersetzen: ".$change );
my @names = split( /#/, $change ); my @names = split( /#/, $change );
# afected devices # afected devices