feat: add various infrastructure check and automation scripts
This commit is contained in:
17
scripts/check_ha_ups.py
Normal file
17
scripts/check_ha_ups.py
Normal file
@@ -0,0 +1,17 @@
|
||||
import urllib.request
|
||||
import json
|
||||
|
||||
HA_URL = "http://14.4.4.20:8123"
|
||||
HA_TOKEN = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJkZWNlMWI5ZjJhZDQ0MTRmODU4NGYzN2I1YjgwZDQxMiIsImlhdCI6MTc5MzQ1MjQ2MywiZXhwIjoyMTA4ODEyNDYzfQ.JznpOqsCSnHz6aTVa8K9pQCz1816DC8SrmS1xn1Sm2k"
|
||||
|
||||
req = urllib.request.Request(f"{HA_URL}/api/states", headers={"Authorization": f"Bearer {HA_TOKEN}", "Content-Type": "application/json"})
|
||||
try:
|
||||
with urllib.request.urlopen(req, timeout=5) as r:
|
||||
states = json.loads(r.read().decode())
|
||||
ups_states = [s for s in states if "ups" in s["entity_id"] or "server_closet" in s["entity_id"] or "nut" in s["entity_id"]]
|
||||
print(f"Found {len(ups_states)} UPS entities in Home Assistant:")
|
||||
for s in ups_states:
|
||||
print(f" {s['entity_id']}: {s['state']} {s.get('attributes', {}).get('unit_of_measurement', '')}")
|
||||
except Exception as e:
|
||||
print("HA err:", e)
|
||||
|
||||
Reference in New Issue
Block a user