Files
SnarfCode/scripts/list_st_entities.py

24 lines
1.0 KiB
Python

import paramiko
import sys
import json
sys.stdout.reconfigure(encoding='utf-8')
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect('140.44.4.71', username='root', key_filename=r'C:\Users\Snarf\.ssh\id_ed25519_snarfnet', timeout=10)
ha_token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIzZWUyNTE1MDk0NGU0ZjRjYmJkMGM1MWI5MThmY2EzYiIsImlhdCI6MTc0NjgxMDM3NSwiZXhwIjoyMDYyMTcwMzc1fQ.Le6M7WL63nxtLTxccFacQR5GVUY5C-a_zGtmXT_uaz4"
cmd = f"""curl -s -H "Authorization: Bearer {ha_token}" -H "Content-Type: application/json" http://14.4.4.20:8123/api/states"""
_, stdout, stderr = c.exec_command(cmd)
raw = stdout.read().decode()
states = json.loads(raw)
st_entities = [s for s in states if s['entity_id'].startswith('sensor.st_00158555')]
print(f"Total Weather Station ST-00158555 entities: {len(st_entities)}")
for s in st_entities:
print(f" {s['entity_id']} = {s['state']} {s.get('attributes', {}).get('unit_of_measurement', '')} ({s.get('attributes', {}).get('friendly_name')})")
c.close()