Hallo Klaus,
anbei ein patch, mit dem man über die API auch trigger-Befehle schicken kann. Im Prinzip ist das identisch zu 'set', deshalb beschränkt sich die Änderung auf die Erweiterung der Befehlsabfrage selbst.
Index: 02_HTTPAPI.pm
===================================================================
--- 02_HTTPAPI.pm (Revision 30353)
+++ 02_HTTPAPI.pm (Arbeitskopie)
@@ -107,7 +107,7 @@
my $link;
return($hash, 503, 'close', "text/plain; charset=utf-8", encode($encoding, "error=503 Service Unavailable")) if(IsDisabled($name));
- if($request =~ m/^(\/$infix)\/(set|get|read|readtimestamp|readinternal|write)\?(.*)$/) {
+ if($request =~ m/^(\/$infix)\/(set|get|read|readtimestamp|readinternal|write|trigger)\?(.*)$/) {
$link = $1;
$apiCmd = $2;
$apiCmdString = $3;
@@ -166,7 +166,7 @@
} else {
return($hash, 400, 'close', "text/plain; charset=utf-8", encode($encoding, "error=400 Bad Request, $request > attribute reading or internal is missing"))
}
- } elsif ($apiCmd eq 'set') {
+ } elsif ($apiCmd eq 'set' || $apiCmd eq 'trigger') {
my $setCmd;
if ($apiCmdString =~ /&action(\=[^&]*)?(?=&|$)|^action(\=[^&]*)?(&|$)/) {
$setCmd = substr(($1 // $2), 1);
@@ -174,7 +174,7 @@
$setCmd =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg;
#my $ret = CommandSet(undef, "$fhemDevName $setCmd");
#my $ret = AnalyzeCommand($defs{$hash->{SNAME}}, "set $fhemDevName $setCmd");
- my $ret = AnalyzeCommand($defs{$name}, "set $fhemDevName $setCmd");
+ my $ret = AnalyzeCommand($defs{$name}, "$apiCmd $fhemDevName $setCmd");
if ($ret) {
return($hash, 400, 'close', "text/plain; charset=utf-8", encode($encoding, "error=400 Bad Request, $request > $ret"))
} else {
@@ -365,7 +365,7 @@
<a id="HTTPAPI"></a>
<h3>HTTPAPI</h3>
<ul>
- HTTPAPI is a compact HTML API server that performs http requests to execute set and get commands
+ HTTPAPI is a compact HTML API server that performs http requests to execute set, get and trigger commands
and reads and writes readings.<br><br>
<a id="HTTPAPI-define"></a>
@@ -435,6 +435,22 @@
</ul>
<br><br>
+ <a id="HTTPAPI-trigger"></a>
+ <b>Trigger</b>
+ <ul>
+ <li>API command line for executing a trigger command<br>
+ Request:
+ <ul>
+ <code>http://<ip-addr>:<port>/<apiName>/trigger?device=<devname>&action=<cmd></code><br>
+ </ul>
+ Response:
+ <ul>
+ <code><device>=<cmd>|error=<error message></code><br>
+ </ul>
+ </li>
+ </ul>
+ <br><br>
+
<a id="HTTPAPI-events"></a>
<b>Generated events</b>
<ul>