Von English mit KI übersetzt ·
Wir machen das auf unserer Produktionsfläche: Ein Pi mit einem Hornlautsprecher liest kritische Alarme über den Lärm hinweg vor. Ciaran hat recht, frag die Alarms-API ab.Bitte deinen Administrator um einen API-Schlüssel nur mit der Berechtigung zum Lesen von Alarmen (das Lesen von Alarmen ist standardmäßig eine Berechtigung auf Benutzerebene) und eine IP-Allowlist für die Adresse der Uni. Dann:
import requests, subprocess, time
H = {"Authorization": f"Bearer {API_KEY}"}
URL = f"https://{HOST}/tenant/{TENANT}/api/iot/alarms"
seen = set()
while True:
r = requests.get(URL, headers=H, params={"status": "OPEN", "severity": "CRITICAL,MAJOR",
"sort": "opened:desc", "pageSize": 20}, timeout=10)
for a in r.json()["items"]:
if a["alarmId"] not in seen:
seen.add(a["alarmId"])
subprocess.run(["sh", "-c", f'echo "{a["deviceName"]}: {a["title"]}" | piper --model en_GB-alan-medium.onnx --output-raw | aplay -r 22050 -f S16_LE'])
time.sleep(15)
Der Status OPEN bewirkt, dass bestätigte Alarme nicht mehr vorgelesen werden, was die Leute mögen: In der App bestätigen, und der Raum wird still. Gib deinen Alarmregeln lesbare Titel, denn genau das wird vorgelesen, z. B. „{{device.name}} Temperatur {{value}}“. Fünfzehn Sekunden sind ein höflicher Abfrageintervall, bleib deutlich unter den API-Limits. Falls du jemals einen öffentlichen Endpunkt bekommst, würde der Webhook alarm.created das Polling ersetzen: Webhooks.
We do this on our plant floor, a Pi with a horn speaker reads critical alarms over the noise. Ciaran’s right, poll the Alarms API.
Ask your admin for an API key with only the alarm read permission (reading alarms is a User-level permission by default) and an IP allowlist for the uni’s address. Then:
import requests, subprocess, time
H = {"Authorization": f"Bearer {API_KEY}"}
URL = f"https://{HOST}/tenant/{TENANT}/api/iot/alarms"
seen = set()
while True:
r = requests.get(URL, headers=H, params={"status": "OPEN", "severity": "CRITICAL,MAJOR",
"sort": "opened:desc", "pageSize": 20}, timeout=10)
for a in r.json()["items"]:
if a["alarmId"] not in seen:
seen.add(a["alarmId"])
subprocess.run(["sh", "-c", f'echo "{a["deviceName"]}: {a["title"]}" | piper --model en_GB-alan-medium.onnx --output-raw | aplay -r 22050 -f S16_LE'])
time.sleep(15)
Status OPEN means acknowledged alarms stop being read, which people like: ack it in the app and the room goes quiet. Give your alarm rules readable titles because that’s what gets spoken, e.g. „{{device.name}} temperature {{value}}“. Fifteen seconds is a polite poll rate, stay well under the API limits. If you ever do get a public endpoint, the alarm.created webhook would replace the polling: Webhooks.

