diff --git a/fhem/FHEM/10_EIB.pm b/fhem/FHEM/10_EIB.pm index 8fb963f78..9097bf336 100644 --- a/fhem/FHEM/10_EIB.pm +++ b/fhem/FHEM/10_EIB.pm @@ -20,6 +20,9 @@ # ABU 20151207 added dpt3, fixed doku-section myDimmer # ABU 20151213 added dpt13 # ABU 20151221 added multiple group support for get according thread 45954 +# ABU 20160111 added feature EIBreadingRegex, EIBwritingRegex, Fixed some doku +# ABU 20160116 fixed motd-error due to debug-mode +# ABU 20160122 fixed doku, changed return value for EIB_Set from undef to "", reintegrated multiple group sending package main; @@ -144,6 +147,8 @@ EIB_Initialize($) { "EIBreadingX:1,0 " . "EIBreadingSender:1,0 " . "EIBanswerReading:1,0 " . + "EIBreadingRegex " . + "EIBwritingRegex " . "$readingFnAttributes " . "model:".join(",", keys %eib_dpttypes); } @@ -270,7 +275,8 @@ EIB_Get($@) { sub EIB_Set($@) { my ($hash, @a, $str) = @_; - my $ret = undef; + #my $ret = undef; + my $ret = ""; my $na = int(@a); #return, if no set value specified @@ -300,6 +306,19 @@ EIB_Set($@) { my $groupnr = 1; + # the command can be send to any of the defined groups indexed starting by 1 + # optional last argument starting with g indicates the group + # execute only for non-strings. Otherwise a "g" is interpreted to execute this group-send-mechanism... + if ($value ne "string") + { + $groupnr = $1 if($na>2 && $a[$na-1]=~ m/g([0-9]*)/); + #return, if unknown group + return "groupnr $groupnr not known." if(!$hash->{CODE}{$groupnr}); + } + my $v = join(" ", @a); + Log3 $name, 5, "EIB set $v"; + (undef, $v) = split(" ", $v, 2); # Not interested in the name... + # the command can be send to any of the defined groups indexed starting by 1 # optional last argument starting with g indicates the group # execute only for non-strings. Otherwise a "g" is interpreted to execute this group-send-mechanism... @@ -420,10 +439,38 @@ EIB_Set($@) { my $defptr = $modules{EIB}{defptr}{$code}; foreach my $n (keys %{ $defptr }) { + my $regAttr = $attr{$n}{"EIBwritingRegex"}; + if ($regAttr) + { + #substitute contents of state, if desired + # + #get array of given attributes + my @reg = split("[ ]", $regAttr); + #format reading as input for regex + my $tempVal = "setG$groupnr:$v"; + + #loop over all regex + for (my $i = 0; $i < int(@reg); $i++) + { + #get search / replaye parts + my @regInner = split("\/", $reg[$i]); + $tempVal =~ s/$regInner[0]/$regInner[1]/g; + + #log it + Log (5, "modified set with regex s/$regInner[0]/$regInner[1]/g to value $tempVal"); + print ("modified set with regex s/$regInner[0]/$regInner[1]/g to value $tempVal\n") if ($debug eq 1); + } + + #process result + readingsSingleUpdate($defptr->{$n},"state",$tempVal,1); + } else + { + #process regular reading + readingsSingleUpdate($defptr->{$n},"state",$v,1); + } + #debug print "setg = $defptr->{$n}{NAME} , $groupnr , attr = AttrVal($defptr->{$n}{NAME},'EIBreadingX',0)n" if ($debug eq 1); - #process regular reading - readingsSingleUpdate($defptr->{$n}, "state", $v, 1); #process extended reading - mark as set readingsSingleUpdate($defptr->{$n},"setG" . $groupnr,$v,1) if (AttrVal($defptr->{$n}{NAME},'EIBreadingX',0) == 1); } @@ -481,11 +528,39 @@ EIB_Parse($$) { # parse/translate by datapoint type $v = EIB_ParseByDatapointType($lh,$n,$rawv,$gnr); # MH added optional groupnr $lh->{RAWSTATE} = $rawv; - $lh->{LASTGROUP} = $dev; - - #process regular reading - readingsSingleUpdate($lh,"state",$v,1); - + $lh->{LASTGROUP} = $dev; + + my $regAttr = $attr{$n}{"EIBreadingRegex"}; + if ($regAttr) + { + #substitute contents of state, if desired + # + #get array of given attributes + my @reg = split("[ ]", $regAttr); + #format reading as input for regex + my $tempVal = "getG$gnr:$v"; + + #loop over all regex + for (my $i = 0; $i < int(@reg); $i++) + { + #get search / replaye parts + my @regInner = split("\/", $reg[$i]); + $tempVal =~ s/$regInner[0]/$regInner[1]/g; + + #log it + Log (5, "modified set with regex s/$regInner[0]/$regInner[1]/g to value $tempVal"); + print ("modified set with regex s/$regInner[0]/$regInner[1]/g to value $tempVal\n") if ($debug eq 1); + } + + #process result + readingsSingleUpdate($lh,"state",$tempVal,1); + } + else + { + #process regular reading + readingsSingleUpdate($lh,"state",$v,1); + } + #debug print "getg = $n , group= $gnr , EIBreadingX = AttrVal($def->{$n}{NAME},'EIBreadingX',0)\n" if ($debug eq 1); #process extended reading - mark as "get" @@ -1214,14 +1289,12 @@ eib_name2hex($)
set <name> <value> [<time> g<groupnr>]

where value one of:

-

Example:

       set lamp1 on
@@ -1249,12 +1322,12 @@ eib_name2hex($)
 	

The current date and time can be sent to the bus by the following settings:

       define timedev EIB 0/0/7
-      attr timedev model dpt10
+      attr timedev model time
       attr timedev eventMap /value now:now/
       attr timedev webCmd now
       
       define datedev EIB 0/0/8
-      attr datedev model dpt11
+      attr datedev model date
       attr datedev eventMap /value now:now/
       attr datedev webCmd now
       
@@ -1269,91 +1342,40 @@ eib_name2hex($)
   

Get

If you execute get for a EIB/KNX-Element there will be requested a state from the device. The device has to be able to respond to a read - this is not given for all devices.
- This function is not available for dummies.
The answer from the bus-device is not shown in the toolbox, but is treated like a regular telegram.

- +

Attributes

-
-
    -
  • IODev
  • -
  • alias
  • -
  • comment
  • -
  • devStateIcon
  • -
  • devStateStyle
  • - -
  • dummy
  • -
  • readingFnAttributes
  • - -
  • eventMap
  • -
  • group
  • -
  • icon
  • -
  • ignore
  • - -
  • room
  • -
  • showtime
  • -
  • sortby
  • - -
  • userattr
  • -
  • verbose
  • -
  • webCmd
  • -
  • widgetOverride
  • -
  • model - - set the model according to the datapoint types defined by the (EIB / KNX specifications). The device state in FHEM is interpreted and shown according to the specification. -
      -
    • dpt1 -> will be interpreted as on/off
    • -
    • dpt5
    • -
    • dpt5.003
    • -
    • angle
    • -
    • percent
    • -
    • dpt3 -> usage: set value to +/-0..100. -54 means dim down by 50%
    • -
    • dpt5.004
    • -
    • percent255
    • -
    • dpt6
    • -
    • dpt6.001
    • -
    • dpt6.010
    • -
    • dpt7
    • -
    • length-mm
    • -
    • current-mA
    • -
    • brightness
    • -
    • timeperiod-ms
    • -
    • timeperiod-min
    • -
    • timeperiod-h
    • -
    • dpt9
    • -
    • tempsensor
    • -
    • lightsensor
    • -
    • speedsensor
    • -
    • speedsensor-km/h
    • -
    • pressuresensor
    • -
    • rainsensor
    • -
    • time1sensor
    • -
    • time2sensor
    • -
    • humiditysensor
    • -
    • airqualitysensor
    • -
    • voltage-mV
    • -
    • current-mA2
    • -
    • current-mA2
    • -
    • power
    • -
    • powerdensity
    • -
    • dpt10 -> transferred from and to state, format hh:mm:ss
    • -
    • dpt10_ns -> same as DPT10, seconds always 0
    • -
    • time -> receiving has no effect, sending any value contains actual system time
    • -
    • dpt11 -> transferred from and to state, format hh:mm:ss
    • -
    • date -> receiving has no effect, sending any value contains actual system date
    • -
    • dpt12
    • -
    • dpt13
    • -
    • dpt14
    • -
    • dpt16 -> has to be used with "set string"
    • -
    -
  • - -
  • EIBreadingX - +

    + IODev
    + alias
    + comment
    + devStateIcon
    + devStateStyle
    + do_not_notify
    + dummy
    + readingFnAttributes
    + event-aggregator
    + event-min-interval
    + event-on-change-reading
    + event-on-update-reading
    + eventMap
    + group
    + icon
    + ignore
    + room
    + showtime
    + sortby
    + stateFormat
    + userReadings
    + userattr
    + verbose
    + webCmd
    + widgetOverride
    +
    + +

    EIBreadingX

    +
    Enable additional readings for this EIB-device. With this Attribute set, a reading setG<x> will be updated when a set command is issued from FHEM, a reading getG<x> will be updated as soon a Value is received from EIB-Bus (<x> stands for the groupnr. - see define statement). The logic for the state reading remains unchanged. This is especially useful when the define statement contains more than one group parameter.

    If set to 1, the following additional readings will be available:

    @@ -1364,43 +1386,124 @@ eib_name2hex($)
           
           define myDimmer EIB 0/1/1 0/1/2
           attr myDimmer EIBreadingX 1
    -      attr myDimmer model dpt1 dpt5.Slider # GA 0/1/1 will be interpreted as on/off, GA 0/1/2 will be handled as dpt5 and show a slider on FHEMWEB
    -      attr myDimmer eventMap /on:An/off:Aus/value g2:dim/
    -      attr myDimmer webCmd on:off:dim
    -      attr myDimmer stateFormat getG2 % # copies actual dim-level (as sent/received to/from dimmer) into STATE 
    +      attr myDimmer model dpt1 dpt5 # GA 0/1/1 will be interpreted as on/off, GA 0/1/2 will be handled as dpt5
    +      attr myDimmer stateFormat getG2 % # copies actual dim-level (as received from dimmer) into STATE 
           
    -
  • If the EIBreadingX is set, you can specify multiple blank separated models to cope with multiple groups in the define statement. The setting cannot be done thru the pulldown-menu, you have to specify them with attr <device> model <dpt1> <dpt2> <dpt3>

    - -
  • EIBreadingSender - +
+ +

EIBreadingSender

+
Enable an additional reading for this EIB-device. With this Attribute set, a reading sender will be updated any time a new telegram arrives. -

If set to 1, the following additional reading will be available:

+

If set to 1, the following additional reading will be available:

sender

       sender will be updated any time a new telegram arrives at this group-adress
       

Example:

-      define myDimmer EIB 0/1/1 0/1/2
+      define myDimmer EIB 0/1/1
       attr myDimmer EIBreadingSender 1
       
- - -
  • EIBreadOnStart - +
  • + +

    EIBanswerReading

    +
    If enabled, FHEM answers on read requests. The content of state is send to the bus as answer.

    If set to 1, read-requests are answered

    -
    -      FHEM will respond
    -      

    Example:

    -      define myDimmer EIB 0/1/1 0/1/2
    -      attr myDimmer EIBanswerReading 1
    +      define myValue EIB 0/1/1
    +      attr myValue EIBanswerReading 1
           
    - - - -
    +
    + +

    EIBreadingRegex

    +
    + You can pass n pairs of regex-pattern and string to replace, seperated by a slash. Internally the "new" state is always in the format getG[n]:[state]. The substitution is done every time, a new object is received. You can use this function for converting, adding units, having more fun with icons, ... + This function has only an impact on the content of state - no other functions are disturbed. +

    Example:

    +
    +      define myLamp EIB 0/1/1 0/1/2 0/1/2
    +      attr myLamp EIBreadingRegex getG[1]:/steuern: getG[2]:/status: getG[3]:/sperre:
    +	  attr myLamp EIBreadingRegex devStateIcon status.on:general_an status.off:general_aus sperre.on:lock
    +      
    +
    + +

    EIBwritingRegex

    +
    + You can pass n pairs of regex-pattern and string to replace, seperated by a slash. Internally the "new" state is always in the format setG1:[state]. The substitution is done every time, after an object is send. You can use this function for converting, adding units, having more fun with icons, ... + This function has only an impact on the content of state - no other functions are disturbed. +

    Example:

    +
    +      define myLockObject EIB 0/1/1
    +      attr myLamp EIBwritingRegex setG1:on/LOCKED setG1:/UNLOCKED
    +      
    +
    + +

    model

    +
    +

    This attribute is mandatory!

    + Set the model according to the datapoint types defined by the (EIB / KNX specifications). The device state in FHEM is interpreted and shown according to the specification.
    +
    + dpt1 - 1 bit
    + Will be interpreted as on/off, 1=on 0=off and vice versa
    +
    + dpt3 - Discrete Dim-Message
    + Usage: set value to +/-0..100. -54 means dim down by 50%
    +
    + dpt5 - 1 byte unsigned
    + dpt5.003 - angle in degrees
    + angle - same as dpt5.003
    + dpt5.004 - percent
    + percent - same as above
    + percent255 - scaled percentage: 255=100%
    +
    + dpt6 - 1 byte signed
    + dpt6.001 - percent
    + dpt6.010
    +
    + dpt7 - 2 byte unsigned
    + length - mm
    + current - mA
    + brightness
    + timeperiod - ms
    + timeperiod - min
    + timeperiod - h
    +
    + dpt9 - 2 byte float
    + tempsensor
    + lightsensor
    + speedsensor
    + speedsensor-km/h
    + pressuresensor
    + rainsensor
    + time1sensor
    + time2sensor
    + humiditysensor
    + airqualitysensor
    + voltage-mV
    + current-mA2
    + current-mA2
    + power
    + powerdensity
    +
    + dpt10 - time hh:mm:ss
    + dpt10_ns - same as DPT10, seconds always 0
    + time - receiving has no effect, sending any value contains actual system time. For examle use set timedev value now
    +
    + dpt11 - date dd.mm.yyyy
    + date - receiving has no effect, sending any value contains actual system date. For examle use set timedev value now
    +
    + dpt12 - 4 byte unsigned
    +
    + dpt13 - 4 byte signed
    +
    + dpt14 - 4 byte float
    +
    + dpt16 - text, use with "string": set textdev string Hallo Welt
    +
    + =end html =cut