Von English mit KI übersetzt ·
Genau das machen wir für die Linienbeleuchtung in unserem Werk, über ein kleines Skript auf dem PC des Supervisors. Es ist die Commands API mit einem API-Schlüssel.Ihre Schaltkarte sendet bereits einen Befehl, und Geräte können nur Befehle senden, die im Commands-Katalog des Gerätoprofils auf der Basic-Stufe stehen. Die Methode existiert also. Um ihren genauen Namen und ihre Parameter zu sehen, fragen Sie die API mit demselben Schlüssel ab, den Sie gleich erstellen: GET /tenant/<tenantId>/api/iot/devices/<deviceId>/rpc-commands listet auf, was eine Steuerung an dieses Gerät senden darf.Erstellen Sie den Schlüssel unter API Keys: Geben Sie ihm die Berechtigung, Basisbefehle zu senden und Befehle zu lesen, tragen Sie die Adresse Ihres Desktops in die IP-Allowlist ein und wählen Sie ein Ablaufdatum. Dann:
#!/bin/sh
# ~/bin/office-lights (chmod 700)
KEY=$(cat ~/.config/hermetry/key)
curl -s -X POST "https://<your host>/tenant/<tenantId>/api/iot/devices/<deviceId>/rpc"
-H "Authorization: Bearer $KEY"
-H "Content-Type: application/json"
-d "{"method":"light.set","params":{"on":$1},"timeoutMs":10000}"
Ein zweiseitiger Befehl mit einem Timeout von 30 Sekunden oder weniger wartet und antwortet mit 200 und dem Status, sodass Sie im Terminal SUCCESSFUL oder den Fehler sehen. Binden Sie office-lights true und office-lights false an zwei Tastenkürzel, und Sie sind fertig. Ein API-Schlüssel kann nur Methoden senden, die im Katalog stehen, was ohnehin genau das ist, was Sie hier wollen.Dokumentation: Commands API.
We do exactly this for the line lights at our plant, from a little script on the supervisor’s PC. It’s the Commands API with an API key.
Your switch card already sends a command, and boards can only send commands that are in the device profile’s Commands catalogue at the Basic tier. So the method exists. To see its exact name and params, ask the API with the same key you’re about to create: GET /tenant/<tenantId>/api/iot/devices/<deviceId>/rpc-commands lists what a control may send to that device.
Create the key under API Keys: give it the permission to send basic commands and to read commands, put your desktop’s address in the IP allowlist, and pick an expiry. Then:
#!/bin/sh
# ~/bin/office-lights (chmod 700)
KEY=$(cat ~/.config/hermetry/key)
curl -s -X POST "https://<your host>/tenant/<tenantId>/api/iot/devices/<deviceId>/rpc"
-H "Authorization: Bearer $KEY"
-H "Content-Type: application/json"
-d "{"method":"light.set","params":{"on":$1},"timeoutMs":10000}"
A two-way command with a timeout of 30 seconds or less waits and answers 200 with the status, so you see SUCCESSFUL or the error in the terminal. Bind office-lights true and office-lights false to two shortcuts and you’re done. An API key can only send methods that are in the catalogue, which is what you want here anyway.
Docs: Commands API.

