From 0bda2db3b840438b8144840efeef3ae6cc61a7ef Mon Sep 17 00:00:00 2001 From: Byte009 <34764406+Byte009@users.noreply.github.com> Date: Thu, 30 May 2019 07:12:54 +0200 Subject: [PATCH] Add files via upload --- FHEM/98_Siro.pm | 264 +++++++++++++++++++++++++++++++----------------- 1 file changed, 169 insertions(+), 95 deletions(-) diff --git a/FHEM/98_Siro.pm b/FHEM/98_Siro.pm index c9ab507..1d4de31 100644 --- a/FHEM/98_Siro.pm +++ b/FHEM/98_Siro.pm @@ -1,6 +1,12 @@ # $Id: 98_Siro.pm 16472 2018-03-23 15:03:57Z Byte09 $ # - +# Siro module for FHEM +# Thanks for templates/coding from SIGNALduino team and Jarnsen_darkmission_ralf9 +# +# Needs SIGNALduino. +# Published under GNU GPL License, v2 +# History: +# 30.05.19 Version 1.0 innitial comit ################################################################################################################ # Todo's: # - @@ -11,7 +17,7 @@ package main; use strict; use warnings; -my $version = "V 1"; +my $version = "1.0"; sub Siro_Initialize($) { @@ -37,7 +43,8 @@ sub Siro_Initialize($) { . " SIRO_Battery_low" . " SIRO_signalLongStopRepeats:10,15,20,40,45,50" . " $readingFnAttributes" - . " SIRO_channel:1,2,3,4,5,6,7,8,9,10,11,12,13,14,15" + . " SIRO_send_channel:1,2,3,4,5,6,7,8,9,10,11,12,13,14,15" + . " SIRO_send_id" . " SIRO_time_to_open" . " SIRO_time_to_close" . " SIRO_debug:0,1" @@ -196,7 +203,7 @@ sub Define($$) { if ( $a[2] =~ m/^[A-Fa-f0-9]{8}$/i ) { $hash->{ID} = uc( substr( $a[2], 0, 7 ) ); - $hash->{CHANNEL} = sprintf( "%d", hex( substr( $a[2], 7, 1 ) ) ); + $hash->{CHANNEL_RECEIVE} = sprintf( "%d", hex( substr( $a[2], 7, 1 ) ) ); $askedchannel = sprintf( "%d", hex( substr( $a[2], 7, 1 ) ) ); } else { @@ -209,7 +216,7 @@ sub Define($$) { my $code = uc( $a[2] ); my $ncode = 1; - my $devpointer = $hash->{ID} . $hash->{CHANNEL}; + my $devpointer = $hash->{ID} . $hash->{CHANNEL_RECEIVE}; $hash->{CODE}{ $ncode++ } = $code; $hash->{MODEL} = "LE-serie"; $modules{Siro}{defptr}{$devpointer} = $hash; @@ -285,28 +292,40 @@ sub SendCommand($@) { } - Log3( $name, 5,"Siro_sendCommand: args2 - $args[1]"); + Log3( $name, 5,"Siro_sendCommand: args1 - $args[1]"); if ( $args[1] eq "longstop" || $hash->{helper}{progmode} eq "on") { - $SignalRepeats = AttrVal( $name, 'SIRO_SignalLongStopRepeats', '15' ); + $SignalRepeats = AttrVal( $name, 'SIRO_signalLongStopRepeats', '15' ); } else { $SignalRepeats = AttrVal( $name, 'SIRO_signalRepeats', '10' ); } - $chan = AttrVal( $name, 'SIRO_channel', undef ); + $chan = AttrVal( $name, 'SIRO_send_channel', undef ); if ( !defined($chan) ) { - $chan = $hash->{CHANNEL}; + $chan = $hash->{CHANNEL_RECEIVE}; } $binChannel = sprintf( "%04b", $chan ); my $value = $name . " " . join( " ", @args ); + + my $sendid = AttrVal( $name, 'SIRO_send_id', 'undef' ); + if ( $sendid eq 'undef') + { $binHash = sprintf( "%028b", hex( $hash->{ID} ) ); + } + else{ + $binHash = sprintf( "%028b", hex( $sendid ) ); + } + + + + Log3 $io, 5, "Siro_sendCommand: BinHash: = $binHash"; $binCommand = sprintf( "%08b", hex($command) ); @@ -464,12 +483,29 @@ Log3( $name, 5, "Siro Parse Befehl: $newstate"); my $parseaborted = 0; $lh->{helper}{parse_aborted} = $parseaborted; Log3 $lh, 5, "Siro_Parse: $name $newstate"; - $hash->{helper}{remotecmd} = "on"; #verhindert das senden von signalen + + + my $defchannnel = $lh->{CHANNEL_RECEIVE}; + my $atrrchannel = AttrVal( $name, 'SIRO_send_channel', $defchannnel ); + + Log3 $lh, 5, "Siro_Parse: defchannnel - $defchannnel "; + Log3 $lh, 5, "Siro_Parse: atrrchannel - $atrrchannel "; + + if ($defchannnel eq $atrrchannel) + { + $lh->{helper}{remotecmd} = "on"; #verhindert das senden von signalen nur wenn nicht auf anderem kanal gesendet wird + } + + Log3 $lh, 5, "Siro_Parse: hash->{helper}{remotecmd} - ".$hash->{helper}{remotecmd}; + Log3( $name, 3, "Siro-Parse ($name) : Signal FB emfangen - $newstate"); Set( $lh, $name, $newstate ); return $name; } } + + + else { # device nicht vorhanden my ( undef, $rawData ) = split( "#", $msg ); @@ -508,12 +544,11 @@ sub Set($@) { my ( $hash, $name, @args ) = @_; my $cmd = $args[0]; # eingehendes set my $zielposition = $args[1]; # eingehendes set position - Log3( $name, 5, "Siro - Set: eingehendes komando $cmd") if $cmd ne "?"; + Log3( $name, 5, "Siro-Set: eingehendes Kommando $cmd") if $cmd ne "?"; ### check for old version if (ReadingsVal( $name, 'last_reset_os', 'undef' ) ne 'undef' && $cmd ne "?") { - Log3( $name,0 , "Da Siromodul wurde geaendert und die einstellungen sind nicht mehr Kompatibel. Bitte das Sirodevice \"$name\" kontrollieren ."); - + Log3( $name,0 , "Das Siromodul wurde geaendert und die einstellungen sind nicht mehr Kompatibel. Bitte das Sirodevice \"$name\" kontrollieren ."); } ################## @@ -584,7 +619,7 @@ sub Set($@) { if ( $hash->{helper}{progmode} eq "on" && $cmd eq "sequenz") # sequenz ausführen { - Log3( $name, 5, "programmiermodus sequenz gefunden :$args[1]"); + Log3( $name, 5, "Siro-Programmiermodus: Sequenz gefunden :$args[1]"); my @seq = split(/,/, $args[1]); shift @seq; @@ -594,7 +629,7 @@ sub Set($@) { #$actiontime $exectime = $exectime+2; my $execcmd = $seqpart; - Log3( $name, 5, "Siro programmin sequenz : $exectime - $execcmd"); + Log3( $name, 5, "Siro-Programmiermodus: Sequenz - $exectime - $execcmd"); InternalTimer( $exectime, "FHEM::Siro::Prog", $name." ".$execcmd ); } return; @@ -619,7 +654,7 @@ sub Set($@) { delete( $hash->{Signalduino_MSGCNT} ); delete( $hash->{Signalduino_RSSI} ); delete( $hash->{Signalduino_TIME} ); - Log3( $name, 5, "Siro Parse deactivated cause off programmingmode"); + Log3( $name, 5, "Siro-Programmiermodus: Parse deaktiviert"); return; } @@ -627,7 +662,7 @@ sub Set($@) { if ($state eq "programming") # keine Befehlsausf?hrung w?hrend einer programmierung { - Log3( $name, 1, "Siro - Befehl nicht moeglich , Device im Programmiermodus"); + Log3( $name, 1, "Siro-Programmiermodus: Befehl nicht moeglich , Device ist im Programmiermodus"); return; } @@ -637,13 +672,13 @@ sub Set($@) { delete( $hash->{helper}{exexcmd} ); # on/off off blockiert befehlsausf?hrung / l?schen vor jedem durchgang #setze helper neu wenn signal von fb kommt + if ($hash->{helper}{remotecmd} eq "on") { $hash->{helper}{exexcmd} = "off" } delete( $hash->{helper}{remotecmd} ); - readingsBeginUpdate($hash); readingsBulkUpdate( $hash, "ActionTime", $actiontime, 0 ); readingsBulkUpdate( $hash, "LastActionTime", $lastactiontime, 0 ); @@ -651,8 +686,7 @@ sub Set($@) { readingsEndUpdate($hash, 1); # befehl aus %sendCommands ermitteln my $comand = $sendCommands{$cmd}; # auzuf?hrender befehl - Log3( $name, 5, "Siro - Set: ermittelter Befehl: $comand " - ); + Log3( $name, 5, "Siro-Set: ermittelter Befehl: $comand " ); # set reset_motor_term reset_motor_term @@ -667,8 +701,8 @@ sub Set($@) { # wenn vorhanden neuberechnung aller readings if ($aktendaction > time && ($downtime ne "undef" || $uptime ne "undef")) { - Log3( $name, 5, "Siro - Set: laufende aktion gefunden - abbruch"); - Log3( $name, 5, "Siro - Set: laufende aktion -"); + Log3( $name, 5, "Siro-Set: laufende aktion gefunden - abbruch"); + Log3( $name, 5, "Siro-Set: laufende aktion -"); #aktTimeAction - dauer der laufenden aktion - in variable $akttimeaction #aktEndAction geplantes aktionsende - in variabel $aktendaction @@ -676,14 +710,14 @@ sub Set($@) { #$aktrunningaction - typ der laufenden aktion #$position -position bei actionsbeginn my $pastaction = $akttimeaction - ($aktendaction - $actiontime); - Log3( $name, 5, "Siro - Set: unterbrochene aktion $state lief $pastaction "); - Log3( $name, 5, "Siro - Set: aktionsbeginn bei $position "); + Log3( $name, 5, "Siro-Set: unterbrochene Aktion $state lief $pastaction "); + Log3( $name, 5, "Siro-Set: Aktionsbeginn bei $position "); if ($state eq "runningDown" || $state eq "runningDownfortimer") { $drivedpercents = $pastaction/$down1time; $drivedpercents = ( int( $drivedpercents * 10 ) / 10 ); - Log3( $name, 5, "Siro - Set: positionsver?nderung um $drivedpercents prozent nach unten "); + Log3( $name, 5, "Siro-Set: Positionsveraenderung um $drivedpercents Prozent nach unten "); $newposition = int ($position+$drivedpercents); } @@ -691,11 +725,11 @@ sub Set($@) { { $drivedpercents = $pastaction/$up1time; $drivedpercents = ( int( $drivedpercents * 10 ) / 10 ); - Log3( $name, 5, "Siro - Set: positionsver?nderung um $drivedpercents prozent nach oben "); + Log3( $name, 5, "Siro-Set: Positionsveraenderung um $drivedpercents Prozent nach oben "); $newposition = int ($position-$drivedpercents); } - Log3( $name, 5, "Siro - Set: newposition - $newposition "); + Log3( $name, 5, "Siro-Set: neue Position - $newposition "); my $operationtime = ReadingsNum( $name, 'motor-term', 0 ); my $newoperationtime = $operationtime + $pastaction; @@ -713,7 +747,7 @@ sub Set($@) { if ($comand ne "stop") #wenn anders kommando als stop befehl zwischenspeichern und per internal timer neu aufrufen , vorher fahrt stoppen per befehl. Stopbefehl l?uft durch wegen notbetrieb ohne timer attribute, gespeicherter befehl wir abgelegt in reading ($cmd) helper/cmd1 und ($zielposition) helper/cmd2. bei aufruf set wird auf vorhandensein gepr?ft. { SendCommand( $hash, 'stop' ); - Log3( $name, 5, "Siro - Set: zwischenspeichern von cmd ($cmd) und position ($zielposition)"); + Log3( $name, 5, "Siro-Set: Twischenspeichern von Cmd ($cmd) und Position ($zielposition)"); $hash->{helper}{savedcmds}{cmd1} = $cmd; $hash->{helper}{savedcmds}{cmd2} = $zielposition if defined $zielposition; InternalTimer( time, "FHEM::Siro::Restartset", "$name" ); @@ -725,7 +759,7 @@ sub Set($@) { # up/down for timer mappen auf on/off und timer für stop setzen if ( $comand eq 'upfortimer' ) { - Log3( $name, 5, "Siro_Set: up_for_timer $args[1]" ); + Log3( $name, 5, "Siro-Set: up_for_timer $args[1]" ); $hash->{helper}{savedcmds}{cmd1} = 'stop'; InternalTimer( time + $args[1], "FHEM::Siro::Restartset", "$name" ); } @@ -744,9 +778,10 @@ sub Set($@) { { if ($favposition eq "nA") { - Log3( $name, 1, "Siro Favoritenanfahrt nicht m?glich , Reading nicht gesetzt"); + Log3( $name, 1, "Siro-Set: Favoritenanfahrt nicht m?glich , Reading nicht gesetzt"); return; } + Log3( $name, 3, "Siro-Set ($name) : set Favorit"); SendCommand( $hash, 'stop' , 'longstop' ); # befehl ?ndern auf position favorite # weiterer programmdurchlauf @@ -779,12 +814,12 @@ sub Set($@) { my $exectime = $actiontime; foreach my $seqpart (@sequenzraw) { - Log3( $name, 5, "Siro setfav : seqpart - $seqpart"); + Log3( $name, 5, "Siro-Set: Favorit seqpart - $seqpart"); my @seqpartraw =split (/\:/,$seqpart); #$actiontime $exectime = $exectime+$seqpartraw[0]; my $execcmd = $seqpartraw[1]; - Log3( $name, 5, "Siro setfav : $exectime - $execcmd"); + Log3( $name, 5, "Siro-Set: Favorit $exectime - $execcmd"); InternalTimer( $exectime, "FHEM::Siro::Prog", $name." ".$execcmd ); InternalTimer( ($actiontime+$blocking), "FHEM::Siro::Delock", $name ); } @@ -805,12 +840,12 @@ sub Set($@) { my $exectime = $actiontime; foreach my $seqpart (@sequenzraw) { - Log3( $name, 5, "Siro setfav : seqpart - $seqpart"); + Log3( $name, 5, "Siro-Set: Delfavorit seqpart - $seqpart"); my @seqpartraw =split (/\:/,$seqpart); #$actiontime $exectime = $exectime+$seqpartraw[0]; my $execcmd = $seqpartraw[1]; - Log3( $name, 5, "Siro setfav : $exectime - $execcmd"); + Log3( $name, 5, "Siro-Set: Delfavorit $exectime - $execcmd"); InternalTimer( $exectime, "FHEM::Siro::Prog", $name." ".$execcmd ); InternalTimer( $exectime+10, "FHEM::Siro::Delock", $name ); } @@ -829,6 +864,7 @@ sub Set($@) { # set on ( device faeht runter ) if ($comand eq "on" || $comand eq "downfortimer" ) { + Log3( $name, 3, "Siro-Set ($name) : set Down"); if ($downtime eq "undef" || $uptime eq "undef") # bei ungesetzten fahrzeiten { readingsSingleUpdate( $hash, "state", "100", 1 ) ; @@ -840,9 +876,9 @@ sub Set($@) { my $waytodrive = 100 - $state; my $timetodrive = $waytodrive * $down1time; my $endaction = time + $timetodrive; - Log3( $name, 5, "Siro - Settree: on downtime - waytodrive $waytodrive"); - Log3( $name, 5, "Siro - Settree: on downtime - state $state"); - Log3( $name, 5, "Siro - Settree: on downtime - down1time $down1time"); + Log3( $name, 5, "Siro-Set: on downtime - waytodrive $waytodrive"); + Log3( $name, 5, "Siro-Set: on downtime - state $state"); + Log3( $name, 5, "Siro-Set: on downtime - down1time $down1time"); SendCommand( $hash, 'on' ); #SendCommand( $hash, 'stop' ); @@ -858,18 +894,13 @@ sub Set($@) { readingsSingleUpdate( $hash, "state", "runningDown" , 1 ) ; # internen timer setzen runningtime - dann states setzen - Log3( $name, 5, "Siro - setze timer -$comand"); + Log3( $name, 5, "Siro-Set: setze Timer -$comand"); InternalTimer( $endaction, "FHEM::Siro::Finish", "$name" ); } else{ readingsSingleUpdate( $hash, "state", "runningDownfortimer" , 1 ) ; } - - - - - #befehl ausfuhren } @@ -877,6 +908,7 @@ sub Set($@) { # set off ( device faeht hoch ) if ($comand eq "off" || $comand eq "upfortimer" ) { + Log3( $name, 3, "Siro-Set ($name) : set Up"); if ($downtime eq "undef" || $uptime eq "undef") # bei ungesetzten fahrzeiten { @@ -892,9 +924,9 @@ sub Set($@) { my $waytodrive = 0 + $state; my $timetodrive = $waytodrive * $up1time; my $endaction = time + $timetodrive; - Log3( $name, 5, "Siro - Settree: off downtime - waytodrive $waytodrive"); - Log3( $name, 5, "Siro - Settree: off downtime - state $state"); - Log3( $name, 5, "Siro - Settree: off downtime - down1time $down1time"); + Log3( $name, 5, "Siro-Set: off downtime - waytodrive $waytodrive"); + Log3( $name, 5, "Siro-Set: off downtime - state $state"); + Log3( $name, 5, "Siro-Set: off downtime - down1time $down1time"); SendCommand( $hash, 'off' ); readingsBeginUpdate($hash); @@ -910,15 +942,14 @@ sub Set($@) { readingsSingleUpdate( $hash, "state", "runningUp" , 1 ) ; # internen timer setzen runningtime - dann states setzen - Log3( $name, 5, "Siro - setze timer -$comand"); + Log3( $name, 5, "Siro-Set: setze timer -$comand"); InternalTimer( $endaction, "FHEM::Siro::Finish", "$name" ); } else { readingsSingleUpdate( $hash, "state", "runningUpfortimer" , 1 ) ; } - - + #befehl ausfuhren } @@ -926,12 +957,15 @@ sub Set($@) { # set level ( positionsanfahrt ) if ($comand eq "level") { + if ( AttrVal($name,'SIRO_inversPosition','0') eq '1' ) { $zielposition = 100 - $zielposition; $state = 100 - $state; } + Log3( $name, 3, "Siro-Set ($name) : set Position $zielposition "); + if ($downtime eq "undef" || $uptime eq "undef") # bei ungesetzten fahrzeiten { Log3( $name, 1, "ERROR Siro - Set: Function is not available without set runtime attribute, please define"); @@ -972,20 +1006,20 @@ sub Set($@) { readingsEndUpdate( $hash, 1); # internen timer setzen runningtime - dann states setzen - Log3( $name, 5, "Siro - setze timer -$comand"); + Log3( $name, 5, "Siro-Set: setze timer -$comand"); InternalTimer( $endaction, "FHEM::Siro::Finish", "$name" ); - Log3( $name, 5, "Siro - Set: found direction - $cmdpos"); - Log3( $name, 5, "Siro - Set: found finish - $zielposition"); - Log3( $name, 5, "Siro - Set: found position now - $state"); - Log3( $name, 5, "Siro - Set: found position drivingtime - $drivingtime"); - + Log3( $name, 5, "Siro-Set: found direction - $cmdpos"); + Log3( $name, 5, "Siro-Set: found finish - $zielposition"); + Log3( $name, 5, "Siro-Set: found position now - $state"); + } ###################################################### # set stop if ($comand eq "stop" && ReadingsVal( $name, 'LastAction', 'undef' ) ne $comand ) { + Log3( $name, 3, "Siro-Set ($name) : set Stop "); if ($downtime eq "undef" || $uptime eq "undef") # bei ungesetzten fahrzeiten { SendCommand( $hash, 'stop' ); @@ -1032,7 +1066,7 @@ sub Prog($) { my ($input) = @_; my ( $name, $arg ) = split(/ /, $input ); my $hash = $defs{$name}; - Log3( $name, 5, "Siro Prog - $arg "); + Log3( $name, 5, "Siro-Prog: $arg "); SendCommand( $hash, $arg ); return; } @@ -1051,8 +1085,7 @@ sub Finish($) { my $operationtime = ReadingsNum( $name, 'motor-term', 0 ); my $newoperationtime = $operationtime + ReadingsNum ($name, 'aktTimeAction', 0 ); - Log3( $name, 5, "Siro - Finish: "); - Log3( $name, 5, "action - $action "); + Log3( $name, 5, "Siro-Finish: action - $action"); SendCommand( $hash, 'stop' ) if ( $action ne "on" && $action ne "off" ) ; @@ -1078,7 +1111,7 @@ sub Restartset($) { my ( $name, $arg ) = split( / /, $input ); my $hash = $defs{$name}; return "" if ( IsDisabled($name) ); - Log3( $name, 5, "Siro - restartset : aufruf"); + Log3( $name, 5, "Siro-Restartset : aufgerufen"); my $cmd = $hash->{helper}{savedcmds}{cmd1}; my $pos = $hash->{helper}{savedcmds}{cmd2}; delete( $hash->{helper}{savedcmds} ); @@ -1120,7 +1153,7 @@ sub versionchange($) { $attr = AttrVal($name,'operation_mode','undef'); if ($attr eq "1"){ my $modch = AttrVal($name,'channel_send_mode_1','undef'); - CommandAttr(undef,$name . ' SIRO_channel ' . $modch) + CommandAttr(undef,$name . ' SIRO_send_channel ' . $modch) } fhem("deleteattr $name operation_mode"); @@ -1154,9 +1187,8 @@ my ( $FW_wname, $d, $room, $pageHash ) =@_; # pageHash is set for summaryFn. my $hash = $defs{$d}; my $name = $hash->{NAME}; return "" if ( IsDisabled($name) ); - Log3( $name, 5, "Siro - fhemweb"); my $progmode =$hash->{helper}{progmode}; - Log3( $name, 5, "Siro - fhemweb $name progmode $progmode"); + if (!defined $progmode){$progmode='off';} my $msg; ############## versionsänderung @@ -1182,6 +1214,34 @@ my ( $FW_wname, $d, $room, $pageHash ) =@_; # pageHash is set for summaryFn.