commit - cd1194fb7ed03f88217b829ce98e38a075b5461a
commit + 023ec66df8bd20991316582ae1c0cb353060169a
blob - /dev/null
blob + 171564646f2956d35394b38768e27ddd757925ec (mode 755)
--- /dev/null
+++ get-lights.py
+#!/usr/bin/env python3
+#
+# Copyright 2019, Mischa Peters <mischa AT high5 DOT nl>, High5!.
+# Version 1.0 - 20191028
+#
+# Requires:
+# - Python 3.x
+#
+import argparse
+import ssl
+import urllib.request
+import json
+import re
+import collections
+
+parser = argparse.ArgumentParser(description="Get all sensors from Hue Bridge")
+parser.add_argument("bridge", type=str, help="Hue Bridge IP")
+parser.add_argument("token", type=str, help="Hue API Token")
+
+try:
+ args = parser.parse_args()
+ bridge = args.bridge
+ token = args.token
+
+except argparse.ArgumentError as e:
+ print(str(e))
+
+no_cert_check = ssl.create_default_context()
+no_cert_check.check_hostname=False
+no_cert_check.verify_mode=ssl.CERT_NONE
+
+url = f"https://{bridge}/api/{token}/lights"
+req = urllib.request.Request(url)
+with urllib.request.urlopen(req, context=no_cert_check) as response:
+ content = response.read()
+json_data = json.loads(content)
+
+#p = re.compile("([a-fA-F0-9]{2}:?){8}")
+#sensors = collections.defaultdict(list);
+
+for key in json_data:
+ print(f"{key}: {json_data[key]['name']}")
blob - /dev/null
blob + eb8c886fa608c37bf051cb1ef2fc334efa817b1a (mode 755)
--- /dev/null
+++ get-sensors.py
+#!/usr/bin/env python3
+#
+# Copyright 2019, Mischa Peters <mischa AT high5 DOT nl>, High5!.
+# Version 1.0 - 20191028
+#
+# Requires:
+# - Python 3.x
+#
+import argparse
+import ssl
+import urllib.request
+import json
+import re
+import collections
+
+parser = argparse.ArgumentParser(description="Get all sensors from Hue Bridge")
+parser.add_argument("bridge", type=str, help="Hue Bridge IP")
+parser.add_argument("token", type=str, help="Hue API Token")
+
+try:
+ args = parser.parse_args()
+ bridge = args.bridge
+ token = args.token
+
+except argparse.ArgumentError as e:
+ print(str(e))
+
+no_cert_check = ssl.create_default_context()
+no_cert_check.check_hostname=False
+no_cert_check.verify_mode=ssl.CERT_NONE
+
+url = f"https://{bridge}/api/{token}/sensors"
+req = urllib.request.Request(url)
+with urllib.request.urlopen(req, context=no_cert_check) as response:
+ content = response.read()
+json_data = json.loads(content)
+
+p = re.compile("([a-fA-F0-9]{2}:?){8}")
+sensors = collections.defaultdict(list);
+
+for key in json_data:
+ if "uniqueid" in json_data[key]:
+ if p.search(json_data[key]['uniqueid']):
+ if json_data[key]['type'] == 'ZLLPresence':
+ sensors[json_data[key]['uniqueid'][:-8]].insert(0, key)
+ else:
+ sensors[json_data[key]['uniqueid'][:-8]].append(key)
+
+for key in sensors:
+ #print(f"sens: {key} {sensors[key]}")
+ for i in sensors[key]:
+ if json_data.get(i)['type'] == 'ZLLPresence':
+ print(json_data.get(i)['name'])
+ print(f"{i}: {json_data.get(i)['productname']}")
+ if json_data.get(i)['type'] == 'ZLLLightLevel':
+ print(f"{i}: {json_data.get(i)['productname']}")
+ if json_data.get(i)['type'] == 'ZLLTemperature':
+ print(f"{i}: {json_data.get(i)['productname']}")
+