diff --git a/fhem/FHEM/98_MSwitch.pm b/fhem/FHEM/98_MSwitch.pm index 2633cb3d1..59e30cddd 100644 --- a/fhem/FHEM/98_MSwitch.pm +++ b/fhem/FHEM/98_MSwitch.pm @@ -83,7 +83,7 @@ if ( $preconf && $preconf ne "" ) { } my $autoupdate = 'off'; #off/on -my $version = '2.09'; +my $version = '2.10_test'; my $vupdate = 'V2.00' ; # versionsnummer der datenstruktur . änderung der nummer löst MSwitch_VUpdate aus . my $savecount = 30 @@ -230,8 +230,10 @@ sub MSwitch_Initialize($) { . " MSwitch_Safemode:0,1" . " MSwitch_Startdelay:0,10,20,30,60,90,120" . " MSwitch_Wait" + . " MSwitch_Event_Id_Distributor:textField-long " . " setList:textField-long " . " readingList:textField-long " + . " textField-long " . $readingFnAttributes; $hash->{FW_addDetailToSummary} = 0; } @@ -1144,7 +1146,15 @@ sub MSwitch_Set($@) { $execids = $args[1]; $args[0] = 'ID'; } +if ( $args[0] ne 'ID' || $args[0] ne '' ){ +if ( $args[1] !~ m/.\d/ ) + + { + Log3( $name, 1, "error at id call $args[1]: format must be exec_cmd_1 " ); + return ; + } + } # cmd1 abarbeiten MSwitch_Exec_Notif( $hash, 'on', 'nocheck', '', $execids ); return; @@ -1158,6 +1168,18 @@ sub MSwitch_Set($@) { $execids = $args[1]; $args[0] = 'ID'; } + if ( $args[0] ne '' || $args[0] ne "ID" ){ + + + if ( $args[1] !~ m/.\d/ ) + + { + Log3( $name, 1, "error at id call $args[1]: format must be exec_cmd_2 " ); + return ; + } + + } + # cmd2 abarbeiten MSwitch_Exec_Notif( $hash, 'off', 'nocheck', '', $execids ); @@ -2117,7 +2139,76 @@ sub MSwitch_Attr(@) { } } +################################## + + +if ( $cmd eq 'set' && $aName eq 'MSwitch_Event_Id_Distributor') +{ + + +delete( $hash->{helper}{eventtoid}); + +#$aVal =~ s/\n/,/g; +#$aVal =~ s/,,/,/g; +#Log3( $name, 0, $aVal ); +return "Invalid Regex $aVal: $@" if $aVal eq "" ; +return "Invalid Regex $aVal: $@" if !$aVal; +return "Invalid Regex $aVal: $@" if $aVal eq "1" ; + + + +my @test = split(/\n/,$aVal); +#Log3( $name, 0, "@test" ); + + + + + +#my %setid =(); + + foreach my $testdevices (@test ) { + Log3( $name, 0, $testdevices ); + + + if ( $testdevices !~ m/(.*:)?.*:.*=\>cmd(1|2)[\s]ID[\s](\d)(,\d){0,5}$/ ) { +return "wrong syntax. The syntax must be: \n\n[DEVICE:]READING:STATE=>cmd<1|2> ID x[,y,z] \n\n[] = optional \n<1|2> = 1 or 2 \nseveral entries are separated by a line break"; +} +} + + foreach my $testdevices (@test ) { + Log3( $name, 0, $testdevices ); + + my ( $key,$val) = split(/=>/,$testdevices); + Log3( $name, 0, $key ); + Log3( $name, 0, $val ); + + #$setid{$key} = $val; + $hash->{helper}{eventtoid}{$key} = $val; + + + } + + + +return; +} + +if ( $cmd eq 'del' && $aName eq 'MSwitch_Event_Id_Distributor' ) +{ +delete( $hash->{helper}{eventtoid}); +return; +} + + + + + + +################################### + + + if ( $cmd eq 'set' && $aName eq 'disable' && $aVal == 1 ) { $hash->{NOTIFYDEV} = 'no_trigger'; MSwitch_Delete_Delay( $hash, 'all' ); @@ -2323,10 +2414,12 @@ sub MSwitch_Notify($$) { my $devicemode = AttrVal( $ownName, 'MSwitch_Mode', 'Full' ); my $devicefilter = AttrVal( $ownName, 'MSwitch_Trigger_Filter', 'undef' ); my $debugmode = AttrVal( $ownName, 'MSwitch_Debug', "0" ); - my $startdelay = - AttrVal( $ownName, 'MSwitch_Startdelay', $standartstartdelay ); + my $startdelay = AttrVal( $ownName, 'MSwitch_Startdelay', $standartstartdelay ); my $attrrandomnumber = AttrVal( $ownName, 'MSwitch_RandomNumber', '' ); - + #my $bridgemode = AttrVal( $ownName, 'MSwitch_Event_Id_Distributor:', 'undef' ); + #my $expertmode = AttrVal( $ownName, 'MSwitch_Expert:', '0' ); + + return if ( $devicemode eq 'Dummy' ); return if ( ReadingsVal( $ownName, "Trigger_device", "no_trigger" ) eq @@ -2459,7 +2552,7 @@ sub MSwitch_Notify($$) { my $activecount = 0; my $anzahl; EVENT: foreach my $event (@eventscopy) { - +################################## MSwitch_LOG( $ownName, 5, "$ownName: event -> $event " ); @@ -2603,6 +2696,10 @@ sub MSwitch_Notify($$) { @eventsplit ); if ( $testvar ne 'undef' ) { + + my $chbridge = MSwitch_checkbridge( $own_hash, $ownName, $eventcopy,); + next EVENT if $chbridge ne "no_bridge"; + $set = $testvar; $check = 1; $foundcmd1 = 1; @@ -2623,6 +2720,10 @@ sub MSwitch_Notify($$) { $triggeroff, $incommingdevice, 'off', $eventcopy, @eventsplit ); if ( $testvar ne 'undef' ) { + + my $chbridge = MSwitch_checkbridge( $own_hash, $ownName, $eventcopy,); + next EVENT if $chbridge ne "no_bridge"; + $set = $testvar; $check = 1; $foundcmd2 = 1; @@ -2646,6 +2747,11 @@ sub MSwitch_Notify($$) { $triggercmdoff, $incommingdevice, 'offonly', $eventcopy, @eventsplit ); if ( $testvar ne 'undef' ) { + + my $chbridge = MSwitch_checkbridge( $own_hash, $ownName, $eventcopy,); + next EVENT if $chbridge ne "no_bridge"; + + push @cmdarray, $own_hash . ',off,check,' . $eventcopy1; $check = 1; $foundcmd2 = 1; @@ -2662,6 +2768,10 @@ sub MSwitch_Notify($$) { $triggercmdon, $incommingdevice, 'ononly', $eventcopy, @eventsplit ); if ( $testvar ne 'undef' ) { + + my $chbridge = MSwitch_checkbridge( $own_hash, $ownName, $eventcopy,); + next EVENT if $chbridge ne "no_bridge"; + push @cmdarray, $own_hash . ',on,check,' . $eventcopy1; $check = 1; $foundcmd1 = 1; @@ -2885,7 +2995,22 @@ sub MSwitch_Notify($$) { } } ######################### +sub MSwitch_checkbridge($$$) { + my ( $hash, $name, $event ) = @_; + my $bridgemode = AttrVal( $name, 'MSwitch_Event_Id_Distributor', '0' ); + my $expertmode = AttrVal( $name, 'MSwitch_Expert', '0' ); + return "no_bridge" if $expertmode eq "0"; + return "no_bridge" if $bridgemode eq "0"; + return "no_bridge" if !defined $hash->{helper}{eventtoid}{$event}; + my @bridge = split(/ /,$hash->{helper}{eventtoid}{$event}); + my $zweig ; + $zweig = "on" if $bridge[0] eq "cmd1"; + $zweig = "off" if $bridge[0] eq "cmd2"; + MSwitch_Exec_Notif( $hash, $zweig, 'nocheck', '', $bridge[2] ); +return "undef"; +} +############################ sub MSwitch_fhemwebFn($$$$) { # my $loglevel = 5; @@ -4921,7 +5046,31 @@ sub MSwitch_fhemwebFn($$$$) { else { $ret .= "

"; } - + # id event bridge + + + + #my $bridgemode = AttrVal( $name, 'MSwitch_Event_Id_Distributor', '0' ); + my $expertmode = AttrVal( $Name, 'MSwitch_Expert', '0' ); + + + if ($hash->{helper}{eventtoid} && $expertmode eq "1" ){ + $ret .= + " + + + + "; + my $toid = $hash->{helper}{eventtoid}; + foreach my $a ( keys %{$toid} ) + { + $ret .=""; + } + + $ret .=" +
Event to ID distributor (Settings via attribute):
 
    incommming Event: ".$a." =\> execute ".$hash->{helper}{eventtoid}{$a}."
 

"; + } + # affected devices $ret .= " @@ -6026,7 +6175,7 @@ sub MSwitch_Exec_Notif($$$$$) { my $ekey = ''; my $out = '0'; - MSwitch_LOG( $name, 5, + MSwitch_LOG( $name,5, "$name: execnotif -> $hash, $comand, $check, $event,$execids " ); return "" @@ -7085,7 +7234,7 @@ sub MSwitch_Checkcond_time($$) { # my $timeaktuell = # timelocal( '00', $aktmin, $akthour, $date, $month, $time1 ); - my $return = "($timecond1 < $timeaktuell && $timeaktuell < $timecond2)"; + my $return = "($timecond1 <= $timeaktuell && $timeaktuell <= $timecond2)"; if ( $days ne '' ) { $daycondition = MSwitch_Checkcond_day( $days, $name, $adday, $day ); $return = "($return $daycondition)"; @@ -9077,8 +9226,9 @@ MSwitch is an auxiliary module that works both event- and time-controlled.
MSwitch_Mode: Full, Notify, Toggle - Device Operation Mode
  • MSwitch_Condition_Time: 0.1 - activation of the trigger conditions for timed triggering
  • MSwitch_Safemode: 0.1 - 1. aborts all actions of the device if more than 20 calls per second take place
  • -
  • MSwitch_RandomTime - see Wiki
  • -
  • MSwitch_RandomNumber - see Wiki
  • +
  • MSwitch_RandomTime - see Wiki: https://wiki.fhem.de/wiki/MSwitch#MSwitch_Random_Time_.28HH:MM:SS-HH:MM:SS.29
  • +
  • MSwitch_RandomNumber - see Wiki: https://wiki.fhem.de/wiki/MSwitch#MSwitch_Random_Number
  • +
  • MSwitch_Event_Id_Distributor - see Wiki: https://wiki.fhem.de/wiki/MSwitch#MSwitch_Event_Id_Distributor