Traducido del English por IA ·
Hacemos exactamente esto para las luces de línea de nuestra planta, desde un pequeño script en el PC del supervisor. Es la API de Commands con una clave de API.Su tarjeta de conmutación ya envía un comando, y las placas solo pueden enviar comandos que estén en el catálogo Commands del perfil del dispositivo en el nivel Basic. Así que el método existe. Para ver su nombre exacto y sus parámetros, consulte la API con la misma clave que va a crear: GET /tenant/<tenantId>/api/iot/devices/<deviceId>/rpc-commands lista lo que un control puede enviar a ese dispositivo.Cree la clave en API Keys: concédale el permiso para enviar comandos básicos y leer comandos, añada la dirección de su escritorio a la lista de IP permitidas y elija una caducidad. Después:
#!/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}"
Un comando bidireccional con un tiempo de espera de 30 segundos o menos espera y responde 200 con el estado, así que verá SUCCESSFUL o el error en el terminal. Asigne office-lights true y office-lights false a dos atajos y listo. Una clave de API solo puede enviar métodos que estén en el catálogo, que es justo lo que se quiere aquí.Documentación: 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.

