multiple changes

This commit is contained in:
mischa 2019-11-06 22:18:42 +01:00
parent b49b5e6ed8
commit e79b0f5044
4 changed files with 48 additions and 3 deletions

2
.gitignore vendored
View File

@ -1 +1,3 @@
hue-bridge
hue-email
hue-token

View File

@ -20,7 +20,7 @@ parser = argparse.ArgumentParser(description="Get id information")
parser.add_argument("bridge", type=str, help="Hue Bridge IP")
parser.add_argument("token", type=str, help="Hue API Token")
parser.add_argument("-i", "--id", type=int, default='1', help="id#")
parser.add_argument("-t", "--type", type=str, default='lights', help="lights|sensors|groups")
parser.add_argument("-t", "--type", type=str, default='lights', help="lights|sensors|groups|rules")
parser.add_argument("-v", "--verbose", action='store_true', help="verbose")
try:

43
get-rules.py Executable file
View File

@ -0,0 +1,43 @@
#!/usr/bin/env python3
#
# Copyright 2019, Mischa Peters <mischa AT high5 DOT nl>, High5!.
# Version 1.0 - 20191106 - WIP!
#
# Get all rules
#
# For example:
# $ get-rules.py <bridge IP> <token>
#
# Follow the steps at the Hue Developer site to get the username/token
# https://developers.meethue.com/develop/get-started-2/
#
# Requires:
# - Python >3.6
#
import argparse
import ssl
import urllib.request
import json
parser = argparse.ArgumentParser(description="Get all light ids 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}/rules"
req = urllib.request.Request(url)
with urllib.request.urlopen(req, context=no_cert_check) as response:
content = response.read()
json_data = json.loads(content)
print(json.dumps(json_data, indent=4, sort_keys=True))

View File

@ -3,6 +3,6 @@ PATH=$PATH:/usr/local/bin
#
# Easy invocation of python script
# Add the following to crontab:
# @daily /<path-to-your-script>/wrapper-sensor-battery.sh
# @daily /<path-to-your-script>/wrapper-sensors-battery.sh
#
(/home/mischa/hue/get-sensors.py $(cat /home/mischa/hue-bridge) $(cat /home/mischa/hue-token) -b 60) | mail -s "Hue Battery Status" $(cat /home/mischa/email-address)
(/home/mischa/hue/get-sensors.py $(cat /home/mischa/hue-bridge) $(cat /home/mischa/hue-token) -b 60) | mail -s "Hue Battery Status" $(cat /home/mischa/hue-email)