Files
SnarfCode/scripts/find_all_weather_entities.py

27 lines
1.2 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()
try:
states = json.loads(raw)
weather_station_entities = [s for s in states if any(k in s['entity_id'].lower() for k in ['back_yard', 'weather_station', 'tempest', 'rain', 'wind', 'humidity'])]
print(f"\nFound {len(weather_station_entities)} matching entities:")
for s in weather_station_entities:
print(f" - {s['entity_id']} = {s['state']} (unit: {s.get('attributes', {}).get('unit_of_measurement')}, name: {s.get('attributes', {}).get('friendly_name')})")
except Exception as e:
print("Error:", e)
c.close()