diff --git a/fhem/CHANGED b/fhem/CHANGED index 4baaa5d9b..0c0641e50 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,6 @@ # 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. + - feature: 72_TA_CMI_JSON: added set fixwertImpuls and setList - feature: 72_TA_CMI_JSON: added set fixwertAnalog fixwertDigital - change: 70_ZoneMinder: made Crypt dependency for v 1.30 optional - change: 48_BlinkCamera: Change to new Blink login API / add resetUniqueID diff --git a/fhem/FHEM/72_TA_CMI_JSON.pm b/fhem/FHEM/72_TA_CMI_JSON.pm index 695ad6ca4..619e473c6 100755 --- a/fhem/FHEM/72_TA_CMI_JSON.pm +++ b/fhem/FHEM/72_TA_CMI_JSON.pm @@ -51,7 +51,11 @@ sub TA_CMI_JSON_Initialize { # $hash->{FW_detailFn} = "TA_CMI_JSON::DetailFn"; # $hash->{FW_directNotify} = "TA_CMI_JSON::DirectNotify"; - $hash->{AttrList} = "username password outputStatesInterval interval readingNamesInputs readingNamesOutputs readingNamesDL-Bus readingNamesLoggingAnalog readingNamesLoggingDigital includePrettyReadings:0,1 includeUnitReadings:0,1 prettyOutputStates:0,1 " . $readingFnAttributes; + $hash->{AttrList} = "username password outputStatesInterval interval readingNamesInputs:textField-long ". + "readingNamesOutputs:textField-long readingNamesDL-Bus:textField-long ". + "readingNamesLoggingAnalog:textField-long readingNamesLoggingDigital:textField-long ". + "includePrettyReadings:0,1 includeUnitReadings:0,1 prettyOutputStates:0,1 setList:textField-long ". + $readingFnAttributes; Log3 '', 3, "TA_CMI_JSON - Initialize done ..."; } @@ -115,6 +119,12 @@ my %outputStates = ( 7 => 'Manual-On' ); +my %fixwertTypes = ( + 'fixwertAnalog' => 'D1', + 'fixwertDigital' => '11', + 'fixwertImpuls' => '1f' +); + ## Import der FHEM Funktionen BEGIN { GP_Import(qw( @@ -372,29 +382,60 @@ sub extractReadings($$$$) { return undef; } -sub Set($$$@) { +sub Set { my ( $hash, $name, $opt, @arg) = @_; Log3 $name, 5, "TA_CMI_JSON ($name) - Set: $name $opt ".join(' ', @arg); - if ($opt eq 'fixwertAnalog' || $opt eq 'fixwertDigital') { - + my ($sets, $cmdList) = getCmdHash(AttrVal($name, 'setList', '')); + + if ($opt eq 'fixwertAnalog' || $opt eq 'fixwertDigital' || $opt eq 'fixwertImpuls') { my $index = $arg[0]; my $value = $arg[1]; - my $type; - if ($opt eq 'fixwertAnalog') { - $type = 'D1'; - } else { - $type = '1f'; - } + my $type = $fixwertTypes{$opt}; FixwertChangeRequest($hash, $index, $value, $type); return undef; + } else { + + my $command = $sets->{$opt}; + + if (defined $command) { +# Log3 $name, 5, "TA_CMI_JSON ($name) - command: $command"; + my ($cmd, $index, $value) = split(' ', $command); + +# Log3 $name, 5, "TA_CMI_JSON ($name) - cmd: $cmd"; +# Log3 $name, 5, "TA_CMI_JSON ($name) - index: $index"; +# Log3 $name, 5, "TA_CMI_JSON ($name) - value: $value"; +# Log3 $name, 5, "TA_CMI_JSON ($name) - arg: ".join(' ', @arg); + + unshift @arg, $value if (defined $value); + unshift @arg, $index if (defined $index); + +# Log3 $name, 5, "TA_CMI_JSON ($name) - arg2: ".join(' ', @arg); + return Set($hash, $name, $cmd, @arg); + } } - return 'fixwertAnalog fixwertDigital'; + return "Unknown argument $opt, choose one of fixwertAnalog fixwertDigital fixwertImpuls $cmdList"; +} + +# credits for this method go to MQTT2_DEVICE +sub getCmdHash($) +{ + my ($list) = @_; + my (%h, @cmd); + map { + my ($k,$v) = split(" ",$_,2); + push @cmd, $k; + $k =~ s/:.*//; # potential arguments + $h{$k} = $v; + } + grep /./, + split("\n", $list); + return (\%h, join(" ",@cmd)); } sub FixwertChangeRequest($$$$) { @@ -584,10 +625,13 @@ sub ParseOutputStateResponse($$$) { Set @@ -615,6 +659,11 @@ sub ParseOutputStateResponse($$$) {
  • interval
    Query interval in seconds. Minimum query interval is 60 seconds.
  • outputStatesInterval
    Request interval in seconds for getting output states.
  • prettyOutputStates [0:1]
    If set, generates a reading _State_Pretty for output states (eg Auto-On, Manual-Off)
  • +
  • + setList
    Used to define Set shortcuts for fixwertAnalog, Digital, and Impuls. eg Light_on:noArg fixwertImpuls 3 1
    + The second parameter (for the value) can be left out and directly read from the input field. eg Water_Temperature fixwertAnalog 7
    + can be used like set cmiNode Water_Temperature 55.0. +
  • username
    Username for querying the JSON-API. Needs to be either admin or user privilege.
  • password
    Password for querying the JSON-API.
  • @@ -655,10 +704,13 @@ Weitere Informationen zu diesem Modul im interval
    Abfrage-Intervall in Sekunden. Muss mindestens 60 sein.
  • outputStatesInterval
    Abfrage-Intervall für Ausgangs-Stati in Sekunden.
  • prettyOutputStates [0:1]
    Definiert, ob zu einem Ausgangs-Status ein zusätzliches Reading _State_Pretty geschrieben werden soll (liefert zB Auto-On, Manual-Off)
  • +
  • + setList
    Dienst zum Anlegen direkter Set Befehle für fixwertAnalog, Digital, und Impuls. zB Licht_ein:noArg fixwertImpuls 3 1
    + Wird der zweite Parameter (der Wert) weggelassen, kann dieser direkt aus dem Textfeld übernommen werden. zB Wasser_Temperatur fixwertAnalog 7
    + könnte dann mit set cmiNode Wasser_Temperatur 55.0 verwendet werden. +
  • username
    Username zur Abfrage der JSON-API. Muss die Berechtigungsstufe admin oder user haben.
  • password
    Passwort zur Abfrage der JSON-API.