diff --git a/fhem/CHANGED b/fhem/CHANGED index 7473a5ee5..6b207a13e 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,8 @@ # 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. + - change: 10_KNX: moved KNX_scan function to KNXIO-module, see Forum #122582 + - change: 00_KNXIO: update KNX and KNXIO-module at same time!, Forum #127792 + added new Attr. enableKNXscan, see cmd-ref - change: 74_AutomowerConnect: Common.pm, automowerconnect.js improved disabled handling, reworked use only differential data - feature: OpenWeatherMapAPI: add human-readable text of daily forecast diff --git a/fhem/FHEM/10_KNX.pm b/fhem/FHEM/10_KNX.pm index 1493a4947..58f4066d3 100644 --- a/fhem/FHEM/10_KNX.pm +++ b/fhem/FHEM/10_KNX.pm @@ -138,6 +138,9 @@ # cmd-ref: correct wiki links, W3C conformance... # error-msg on invalid set dpt1 cmd (on-till...) # Attr anwerReading now deprecated - converted to putCmd - autosave will be deactivated during fhem-restart if a answerReading is converted - use save! +# MH 292306xx move KNX_scan Function to KNXIO-Module - update both KNXIO and KNX-Module !!! +# update cmd-ref +# # todo replace cascading if..elsif with given # todo-9/2023 final removal of attr answerReading conversion @@ -455,9 +458,6 @@ sub Initialize { $hash->{noAutocreatedFilelog} = 1; # autocreate devices create no FileLog $hash->{AutoCreate} = {'KNX_.*' => { ATTR => 'disable:1'} }; #autocreate devices are disabled by default - # register KNX_scan cmd (use from cmd-line) - $cmds{KNX_scan} = { Fn => "KNX_scancmd", Hlp => ',request values from KNX-Hardware. Use "help KNX" for more help',}; - return; } @@ -482,11 +482,11 @@ sub KNX_Define { q{[]"}) if (int(@a) < 3 || $a[2] !~ m/^(?:$PAT_GAD|$PAT_GAD_HEX)/ixms); $hash->{'.DEFLINE'} = join(q{ },@a); # temp store defs for define2... - return InternalTimer(gettimeofday() + 5.0,\&KNX_Define2,$hash) if (! $init_done); + return InternalTimer(gettimeofday() + 3.0,\&KNX_Define2,$hash) if (! $init_done); return KNX_Define2($hash); } -### continue define 5 sec after init complete! +### continue define after init complete sub KNX_Define2 { my $hash = shift // return; @@ -692,7 +692,7 @@ sub KNX_Get { return; } -#Does something according the given cmd... +#send Value to bus ############################# sub KNX_Set { my ($hash, $name, $targetGadName, @arg) = @_; @@ -1864,79 +1864,6 @@ sub KNX_Log { return; } -############################################## -########## public utility functions ########## -# when called from FHEM cmd-line -sub main::KNX_scancmd { - my $cl = shift; - my $devs = shift; - $devs = 'TYPE=KNX' if (! defined($devs) || $devs eq q{}); # select all if nothing defined -# return main::KNX_scan($devs); - main::KNX_scan($devs); - return; -} - -### get state of devices from KNX_Hardware -# called with devspec as argument -# e.g : KNX_scan() / KNX_scan('device1') / KNX_scan('device1, dev2,dev3,...' / KNX_scan('room=Kueche'), ... -# returns number of "gets" executed -sub main::KNX_scan { - my $devs = shift // 'TYPE=KNX'; # select all if nothing defined - - if (! $init_done) { # avoid scan before init complete - Log3 (undef, 2,'KNX_scan command rejected during FHEM-startup!'); - return 0; - } - - my @devlist = devspec2array($devs); - - my $i = 0; #counter devices - my $j = 0; #counter devices with get - my $k = 0; #counter total get's - my $getsarr = q{}; - - foreach my $knxdef (@devlist) { - next unless $knxdef; - next if($knxdef eq $devs && !$defs{$knxdef}); - my $devhash = $defs{$knxdef}; - next if ((! defined($devhash)) || ($devhash->{TYPE} ne 'KNX') || $devhash->{DEF} =~ /$MODELERR/ixms); - - #check if IO-device is ready - my $iodev = $devhash->{IODev}->{NAME}; - next if (! defined($iodev)); - my $iostate = ReadingsVal($iodev,'state',q{}); - next if ($iostate ne 'connected'); - - $i++; - my $k0 = $k; #save previous number of get's - foreach my $key (keys %{$devhash->{GADDETAILS}}) { - last if (! defined($key)); - my $option = $devhash->{GADDETAILS}->{$key}->{OPTION}; - next if (defined($option) && $option =~ /(?:set|listenonly)/ixms); - $k++; - $getsarr .= $knxdef . q{ } . $key . q{,}; - } - $j++ if ($k > $k0); - } - Log3 (undef, 3, qq{KNX_scan: $i devices selected (regex= $devs) / $j devices with get / $k "gets" executing...}); - doKNX_scan($getsarr) if ($k > 0); - return $k; -} - -### issue all get cmd's - each one delayed by InternalTimer -sub doKNX_scan { - my ($devgad, $arr) = split(/,/xms,shift,2); - - my ($name, $gadName) = split(/[\s]/xms,$devgad); - KNX_Get ($defs{$name}, $name, $gadName); - - if (defined($arr) && $arr ne q{}) { - return InternalTimer(gettimeofday() + 0.2,\&doKNX_scan,$arr); # does not support array-> use string... - } - Log3 (undef, 3, q{KNX_scan: finished}); - return; -} - 1; @@ -1993,96 +1920,111 @@ sub doKNX_scan {

KNX

@@ -2322,30 +2272,30 @@ The result of the "get" cmd will be stored in the respective readings. The command is supported only if the IO-device is of TYPE KNXIO!
Useful after a fhem-start to syncronize the readings with the status of the KNX-device.
The "get" cmds are scheduled asynchronous, with a delay of 200ms between each get. (avoid overloading KNX-bus) -If called as perl-function, returns number of "get" cmds issued.
-Examples: +If called as perl-function, returns number of "get" cmds issued.
-syntax when used as perl-function (eg. in at, notify,...)
-   KNX_scan()                    - scan all possible devices
-   KNX_scan('dev-A')             - scan device-A only
-   KNX_scan('dev-A,dev-B,dev-C') - scan device-A, device-B, device-C
-   KNX_scan('room=Kueche')       - scan all KNX-devices in room Kueche
-   KNX_scan('EG_.*')             - scan all KNX-devices where device-names begin with EG_ 
-syntax when used from FHEM-cmdline
-   KNX_scan                      - scan all possible devices
-   KNX_scan dev-A                - scan device-A only
-   KNX_scan dev-A,dev-B,dev-C    - scan device-A, device-B, device-C
-   KNX_scan room=Kueche          - scan all KNX-devices in room Kueche
-   KNX_scan EG_.*                - scan all KNX-devices where device-names begin with EG_
-
-When using KNX_scan or any 'set or get <KNX-device> ...' in a global:INITIALIZED notify, pls. ensure to have some delay in processing the cmd's by using fhem sleep. -
Example:
-   defmod initialized_nf notify global:INITIALIZED sleep 10 quiet;; set KNX_date now;; set KNX_time now;;
-This avoids sending requests while the KNX-Gateway has not finished its initial handshake-procedure with FHEM (the KNX-IO-device).
-
If you are using KNXIO-module as IO-device for your KNX-devices, a better solution is available:
-   defmod initializedKNXIO_nf notify <KNXIO-deviceName>:INITIALIZED set KNX_date now;; set KNX_time now;; KNX_scan;;
+Examples: +syntax when used as perl-function (eg. in at, notify,...) + KNX_scan() - scan all possible devices + KNX_scan('dev-A') - scan device-A only + KNX_scan('dev-A,dev-B,dev-C') - scan device-A, device-B, device-C + KNX_scan('room=Kueche') - scan all KNX-devices in room Kueche + KNX_scan('EG_.*') - scan all KNX-devices where device-names begin with EG_ +syntax when used from FHEM-cmdline + KNX_scan - scan all possible devices + KNX_scan dev-A - scan device-A only + KNX_scan dev-A,dev-B,dev-C - scan device-A, device-B, device-C + KNX_scan room=Kueche - scan all KNX-devices in room Kueche + KNX_scan EG_.* - scan all KNX-devices where device-names begin with EG_ + +Do not use KNX_scan or any 'set or get <KNX-device> ...' in a global:INITIALIZED notify, the IO-device will not be + ready for communication at that time! +
+A better solution is available:
+   defmod initializedKNXIO_nf notify <KNXIO-deviceName>:INITIALIZED set KNX_date now;; set KNX_time now;; KNX_scan;;
This event is triggered 30 seconds after FHEM init complete and the KNXIO-device status is "connected". -
+

See also help KNXIO how to start KNX_scan by using KNXIO-Attribute enableKNXscan, without using any notify,doif,... +