added config file support, hue.conf
This commit is contained in:
parent
e7e27decb5
commit
496ad2f3f6
|
@ -1,3 +1,4 @@
|
||||||
hue-bridge
|
hue-bridge
|
||||||
hue-email
|
hue-email
|
||||||
hue-token
|
hue-token
|
||||||
|
_*
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
# Create a new user on the bridge
|
# Create a new user on the bridge
|
||||||
#
|
#
|
||||||
# For example:
|
# For example:
|
||||||
# $ create-new.py <bridge IP>
|
# $ add-newdeveloper.py <bridge IP>
|
||||||
#
|
#
|
||||||
# Follow the steps at the Hue Developer site to get the username/token
|
# Follow the steps at the Hue Developer site to get the username/token
|
||||||
# https://developers.meethue.com/develop/get-started-2/
|
# https://developers.meethue.com/develop/get-started-2/
|
||||||
|
@ -19,8 +19,8 @@ import ssl
|
||||||
import urllib.request
|
import urllib.request
|
||||||
import json
|
import json
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description="Control light")
|
parser = argparse.ArgumentParser(description="Create a new developer token on the Hue Bridge")
|
||||||
parser.add_argument("bridge", type=str, help="Hue Bridge IP")
|
parser.add_argument("bridge", type=str, help="Hue Bridge IP address")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
|
@ -1,14 +1,18 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
#
|
#
|
||||||
# Copyright 2019, Mischa Peters <mischa AT high5 DOT nl>, High5!.
|
# Copyright 2019-2020, Mischa Peters <mischa AT high5 DOT nl>, High5!.
|
||||||
# Version 1.0 - 20191030
|
# Version 1.0 - 20191030
|
||||||
|
# Version 1.1 - 20200507 - added config file support
|
||||||
#
|
#
|
||||||
# Control a light based on sensor information
|
# Control a light based on sensor information
|
||||||
# Get ['dark'] from sensor ID and switch on/off light ID
|
# Get ['dark'] from sensor ID and switch on/off light ID
|
||||||
# depending where your sensor is located you can use ['daylight']
|
# depending where your sensor is located you can use ['daylight']
|
||||||
#
|
#
|
||||||
# For example:
|
# For example:
|
||||||
# $ daylight-trigger.py <bridge IP> <token> -s 50 -l 24
|
# $ daylight-trigger.py <bridge name> -s 50 -l 24
|
||||||
|
#
|
||||||
|
# Add the following to crontab:
|
||||||
|
# */5 * * * * /<path-to-your-script>/daylight-trigger.py <bridge name> -s 50 -l 24 -a dimmed
|
||||||
#
|
#
|
||||||
# Follow the steps at the Hue Developer site to get the username/token
|
# Follow the steps at the Hue Developer site to get the username/token
|
||||||
# https://developers.meethue.com/develop/get-started-2/
|
# https://developers.meethue.com/develop/get-started-2/
|
||||||
|
@ -20,10 +24,11 @@ import argparse
|
||||||
import ssl
|
import ssl
|
||||||
import urllib.request
|
import urllib.request
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
|
import configparser
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description="Control light based on light sensor")
|
parser = argparse.ArgumentParser(description="Control light based on light sensor")
|
||||||
parser.add_argument("bridge", type=str, help="Hue Bridge IP")
|
parser.add_argument("bridgename", type=str, help="Hue Bridge name in specified in hue.conf")
|
||||||
parser.add_argument("token", type=str, help="Hue API Token")
|
|
||||||
parser.add_argument("-s", "--sensor", type=int, required=True, help="sensor id#")
|
parser.add_argument("-s", "--sensor", type=int, required=True, help="sensor id#")
|
||||||
parser.add_argument("-l", "--light", type=int, required=True, help="light id#")
|
parser.add_argument("-l", "--light", type=int, required=True, help="light id#")
|
||||||
parser.add_argument("-a", "--action", type=str, default='on', help="on|off|relax|bright|dimmed|nightlight")
|
parser.add_argument("-a", "--action", type=str, default='on', help="on|off|relax|bright|dimmed|nightlight")
|
||||||
|
@ -32,8 +37,7 @@ parser.add_argument("-d", "--debug", action='store_true', help="debug")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
bridge = args.bridge
|
bridgename = args.bridgename
|
||||||
token = args.token
|
|
||||||
sensor = args.sensor
|
sensor = args.sensor
|
||||||
light = args.light
|
light = args.light
|
||||||
action = args.action
|
action = args.action
|
||||||
|
@ -43,6 +47,12 @@ try:
|
||||||
except argparse.ArgumentError as e:
|
except argparse.ArgumentError as e:
|
||||||
print(str(e))
|
print(str(e))
|
||||||
|
|
||||||
|
config_files = ['./hue.conf', './.hue.conf', '/etc/hue.conf', '/etc/hue/hue.conf', os.path.expanduser('~/.hue.conf'), os.path.expanduser('~/hue.conf')]
|
||||||
|
config = configparser.RawConfigParser()
|
||||||
|
config.read(config_files)
|
||||||
|
bridge = config.get(bridgename, 'ip')
|
||||||
|
token = config.get(bridgename, 'token')
|
||||||
|
|
||||||
no_cert_check = ssl.create_default_context()
|
no_cert_check = ssl.create_default_context()
|
||||||
no_cert_check.check_hostname=False
|
no_cert_check.check_hostname=False
|
||||||
no_cert_check.verify_mode=ssl.CERT_NONE
|
no_cert_check.verify_mode=ssl.CERT_NONE
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
#
|
#
|
||||||
# Copyright 2019, Mischa Peters <mischa AT high5 DOT nl>, High5!.
|
# Copyright 2019-2020, Mischa Peters <mischa AT high5 DOT nl>, High5!.
|
||||||
# Version 1.0 - 20191028
|
# Version 1.0 - 20191028
|
||||||
|
# Version 1.1 - 20200507 - added config file support
|
||||||
#
|
#
|
||||||
# Get all light IDs
|
# Get all light IDs
|
||||||
#
|
#
|
||||||
# For example:
|
# For example:
|
||||||
# $ get-lights.py <bridge IP> <token>
|
# $ get-lights.py <bridge name>
|
||||||
#
|
#
|
||||||
# Follow the steps at the Hue Developer site to get the username/token
|
# Follow the steps at the Hue Developer site to get the username/token
|
||||||
# https://developers.meethue.com/develop/get-started-2/
|
# https://developers.meethue.com/develop/get-started-2/
|
||||||
|
@ -18,19 +19,25 @@ import argparse
|
||||||
import ssl
|
import ssl
|
||||||
import urllib.request
|
import urllib.request
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
|
import configparser
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description="Get all group ids from Hue Bridge")
|
parser = argparse.ArgumentParser(description="Get all group ids from Hue Bridge")
|
||||||
parser.add_argument("bridge", type=str, help="Hue Bridge IP")
|
parser.add_argument("bridgename", type=str, help="Hue Bridge name in specified in hue.conf")
|
||||||
parser.add_argument("token", type=str, help="Hue API Token")
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
bridge = args.bridge
|
bridgename = args.bridgename
|
||||||
token = args.token
|
|
||||||
|
|
||||||
except argparse.ArgumentError as e:
|
except argparse.ArgumentError as e:
|
||||||
print(str(e))
|
print(str(e))
|
||||||
|
|
||||||
|
config_files = ['./hue.conf', './.hue.conf', '/etc/hue.conf', '/etc/hue/hue.conf', os.path.expanduser('~/.hue.conf'), os.path.expanduser('~/hue.conf')]
|
||||||
|
config = configparser.RawConfigParser()
|
||||||
|
config.read(config_files)
|
||||||
|
bridge = config.get(bridgename, 'ip')
|
||||||
|
token = config.get(bridgename, 'token')
|
||||||
|
|
||||||
no_cert_check = ssl.create_default_context()
|
no_cert_check = ssl.create_default_context()
|
||||||
no_cert_check.check_hostname=False
|
no_cert_check.check_hostname=False
|
||||||
no_cert_check.verify_mode=ssl.CERT_NONE
|
no_cert_check.verify_mode=ssl.CERT_NONE
|
||||||
|
|
19
get-id.py
19
get-id.py
|
@ -1,12 +1,13 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
#
|
#
|
||||||
# Copyright 2019, Mischa Peters <mischa AT high5 DOT nl>, High5!.
|
# Copyright 2019-2020, Mischa Peters <mischa AT high5 DOT nl>, High5!.
|
||||||
# Version 1.0 - 20191103
|
# Version 1.0 - 20191103
|
||||||
|
# Version 1.1 - 20200507 - added config file support
|
||||||
#
|
#
|
||||||
# Collect all information of given id
|
# Collect all information of given id
|
||||||
#
|
#
|
||||||
# For example:
|
# For example:
|
||||||
# $ get-id.py <bridge IP> <token> -t sensors -i 6
|
# $ get-id.py <bridge name> -t sensors -i 6
|
||||||
#
|
#
|
||||||
# Requires:
|
# Requires:
|
||||||
# - Python 3.x
|
# - Python 3.x
|
||||||
|
@ -15,18 +16,18 @@ import argparse
|
||||||
import ssl
|
import ssl
|
||||||
import urllib.request
|
import urllib.request
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
|
import configparser
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description="Get id information")
|
parser = argparse.ArgumentParser(description="Get id information")
|
||||||
parser.add_argument("bridge", type=str, help="Hue Bridge IP")
|
parser.add_argument("bridgename", type=str, help="Hue Bridge name in specified in hue.conf")
|
||||||
parser.add_argument("token", type=str, help="Hue API Token")
|
|
||||||
parser.add_argument("-i", "--id", type=int, default='1', help="id#")
|
parser.add_argument("-i", "--id", type=int, default='1', help="id#")
|
||||||
parser.add_argument("-t", "--type", type=str, default='lights', help="lights|sensors|groups|rules")
|
parser.add_argument("-t", "--type", type=str, default='lights', help="lights|sensors|groups|rules")
|
||||||
parser.add_argument("-v", "--verbose", action='store_true', help="verbose")
|
parser.add_argument("-v", "--verbose", action='store_true', help="verbose")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
bridge = args.bridge
|
bridgename = args.bridgename
|
||||||
token = args.token
|
|
||||||
id = args.id
|
id = args.id
|
||||||
type = args.type
|
type = args.type
|
||||||
verbose = args.verbose
|
verbose = args.verbose
|
||||||
|
@ -34,6 +35,12 @@ try:
|
||||||
except argparse.ArgumentError as e:
|
except argparse.ArgumentError as e:
|
||||||
print(str(e))
|
print(str(e))
|
||||||
|
|
||||||
|
config_files = ['./hue.conf', './.hue.conf', '/etc/hue.conf', '/etc/hue/hue.conf', os.path.expanduser('~/.hue.conf'), os.path.expanduser('~/hue.conf')]
|
||||||
|
config = configparser.RawConfigParser()
|
||||||
|
config.read(config_files)
|
||||||
|
bridge = config.get(bridgename, 'ip')
|
||||||
|
token = config.get(bridgename, 'token')
|
||||||
|
|
||||||
no_cert_check = ssl.create_default_context()
|
no_cert_check = ssl.create_default_context()
|
||||||
no_cert_check.check_hostname=False
|
no_cert_check.check_hostname=False
|
||||||
no_cert_check.verify_mode=ssl.CERT_NONE
|
no_cert_check.verify_mode=ssl.CERT_NONE
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
#
|
#
|
||||||
# Copyright 2019, Mischa Peters <mischa AT high5 DOT nl>, High5!.
|
# Copyright 2019-2020, Mischa Peters <mischa AT high5 DOT nl>, High5!.
|
||||||
# Version 1.0 - 20191028
|
# Version 1.0 - 20191028
|
||||||
# Version 1.1 - 20191103 - added ['state']['on']
|
# Version 1.1 - 20191103 - added ['state']['on']
|
||||||
|
# Version 1.2 - 20200507 - added config file support
|
||||||
#
|
#
|
||||||
# Get all light ids and state
|
# Get all light ids and state
|
||||||
#
|
#
|
||||||
# For example:
|
# For example:
|
||||||
# $ get-lights.py <bridge IP> <token>
|
# $ get-lights.py <bridge name>
|
||||||
#
|
#
|
||||||
# Follow the steps at the Hue Developer site to get the username/token
|
# Follow the steps at the Hue Developer site to get the username/token
|
||||||
# https://developers.meethue.com/develop/get-started-2/
|
# https://developers.meethue.com/develop/get-started-2/
|
||||||
|
@ -19,21 +20,27 @@ import argparse
|
||||||
import ssl
|
import ssl
|
||||||
import urllib.request
|
import urllib.request
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
|
import configparser
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description="Get all light ids from Hue Bridge")
|
parser = argparse.ArgumentParser(description="Get all light ids from Hue Bridge")
|
||||||
parser.add_argument("bridge", type=str, help="Hue Bridge IP")
|
parser.add_argument("bridgename", type=str, help="Hue Bridge name in specified in hue.conf")
|
||||||
parser.add_argument("token", type=str, help="Hue API Token")
|
|
||||||
parser.add_argument("-i", "--id", type=int, help="light id#")
|
parser.add_argument("-i", "--id", type=int, help="light id#")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
bridge = args.bridge
|
bridgename = args.bridgename
|
||||||
token = args.token
|
|
||||||
id = args.id
|
id = args.id
|
||||||
|
|
||||||
except argparse.ArgumentError as e:
|
except argparse.ArgumentError as e:
|
||||||
print(str(e))
|
print(str(e))
|
||||||
|
|
||||||
|
config_files = ['./hue.conf', './.hue.conf', '/etc/hue.conf', '/etc/hue/hue.conf', os.path.expanduser('~/.hue.conf'), os.path.expanduser('~/hue.conf')]
|
||||||
|
config = configparser.RawConfigParser()
|
||||||
|
config.read(config_files)
|
||||||
|
bridge = config.get(bridgename, 'ip')
|
||||||
|
token = config.get(bridgename, 'token')
|
||||||
|
|
||||||
no_cert_check = ssl.create_default_context()
|
no_cert_check = ssl.create_default_context()
|
||||||
no_cert_check.check_hostname=False
|
no_cert_check.check_hostname=False
|
||||||
no_cert_check.verify_mode=ssl.CERT_NONE
|
no_cert_check.verify_mode=ssl.CERT_NONE
|
||||||
|
|
|
@ -1,14 +1,15 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
#
|
#
|
||||||
# Copyright 2019, Mischa Peters <mischa AT high5 DOT nl>, High5!.
|
# Copyright 2019-2020, Mischa Peters <mischa AT high5 DOT nl>, High5!.
|
||||||
# Version 1.0 - 20191028
|
# Version 1.0 - 20191028
|
||||||
# Version 1.1 - 20191106 - added battery status
|
# Version 1.1 - 20191106 - added battery status
|
||||||
|
# Version 1.2 - 20200507 - added config file support
|
||||||
#
|
#
|
||||||
# Get all sensor IDs (ZLLPresence, ZLLLightLevel and ZLLTemperature)
|
# Get all sensor IDs (ZLLPresence, ZLLLightLevel and ZLLTemperature)
|
||||||
# grouped by ZLLPresence name
|
# grouped by ZLLPresence name
|
||||||
#
|
#
|
||||||
# For example:
|
# For example:
|
||||||
# $ get-sensors.py <bridge IP> <token>
|
# $ get-sensors.py <bridge name>
|
||||||
#
|
#
|
||||||
# Follow the steps at the Hue Developer site to get the username/token
|
# Follow the steps at the Hue Developer site to get the username/token
|
||||||
# https://developers.meethue.com/develop/get-started-2/
|
# https://developers.meethue.com/develop/get-started-2/
|
||||||
|
@ -22,23 +23,29 @@ import urllib.request
|
||||||
import json
|
import json
|
||||||
import re
|
import re
|
||||||
import collections
|
import collections
|
||||||
|
import os
|
||||||
|
import configparser
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description="Get all sensor ids from Hue Bridge")
|
parser = argparse.ArgumentParser(description="Get all sensor ids from Hue Bridge")
|
||||||
parser.add_argument("bridge", type=str, help="Hue Bridge IP")
|
parser.add_argument("bridgename", type=str, help="Hue Bridge name in specified in hue.conf")
|
||||||
parser.add_argument("token", type=str, help="Hue API Token")
|
|
||||||
parser.add_argument("-b", "--battery", type=int, help="battery check only, threshold, default 20")
|
parser.add_argument("-b", "--battery", type=int, help="battery check only, threshold, default 20")
|
||||||
parser.add_argument("-v", "--verbose", action='store_true', help="verbose")
|
parser.add_argument("-v", "--verbose", action='store_true', help="verbose")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
bridge = args.bridge
|
bridgename = args.bridgename
|
||||||
token = args.token
|
|
||||||
battery = args.battery
|
battery = args.battery
|
||||||
verbose = args.verbose
|
verbose = args.verbose
|
||||||
|
|
||||||
except argparse.ArgumentError as e:
|
except argparse.ArgumentError as e:
|
||||||
print(str(e))
|
print(str(e))
|
||||||
|
|
||||||
|
config_files = ['./hue.conf', './.hue.conf', '/etc/hue.conf', '/etc/hue/hue.conf', os.path.expanduser('~/.hue.conf'), os.path.expanduser('~/hue.conf')]
|
||||||
|
config = configparser.RawConfigParser()
|
||||||
|
config.read(config_files)
|
||||||
|
bridge = config.get(bridgename, 'ip')
|
||||||
|
token = config.get(bridgename, 'token')
|
||||||
|
|
||||||
no_cert_check = ssl.create_default_context()
|
no_cert_check = ssl.create_default_context()
|
||||||
no_cert_check.check_hostname=False
|
no_cert_check.check_hostname=False
|
||||||
no_cert_check.verify_mode=ssl.CERT_NONE
|
no_cert_check.verify_mode=ssl.CERT_NONE
|
||||||
|
|
19
groupctl.py
19
groupctl.py
|
@ -1,12 +1,13 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
#
|
#
|
||||||
# Copyright 2019, Mischa Peters <mischa AT high5 DOT nl>, High5!.
|
# Copyright 2019-2020, Mischa Peters <mischa AT high5 DOT nl>, High5!.
|
||||||
# Version 1.0 - 20191102
|
# Version 1.0 - 20191102
|
||||||
|
# Version 1.1 - 20200507 - added config file support
|
||||||
#
|
#
|
||||||
# Control a group of lights (room)
|
# Control a group of lights (room)
|
||||||
#
|
#
|
||||||
# For example:
|
# For example:
|
||||||
# $ groupctl.py <bridge IP> <token> -g 4 -a on
|
# $ groupctl.py <bridge name> -g 4 -a on
|
||||||
#
|
#
|
||||||
# Follow the steps at the Hue Developer site to get the username/token
|
# Follow the steps at the Hue Developer site to get the username/token
|
||||||
# https://developers.meethue.com/develop/get-started-2/
|
# https://developers.meethue.com/develop/get-started-2/
|
||||||
|
@ -18,10 +19,11 @@ import argparse
|
||||||
import ssl
|
import ssl
|
||||||
import urllib.request
|
import urllib.request
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
|
import configparser
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description="Control group of lights (room)")
|
parser = argparse.ArgumentParser(description="Control group of lights (room)")
|
||||||
parser.add_argument("bridge", type=str, help="Hue Bridge IP")
|
parser.add_argument("bridgename", type=str, help="Hue Bridge name in specified in hue.conf")
|
||||||
parser.add_argument("token", type=str, help="Hue API Token")
|
|
||||||
parser.add_argument("-g", "--group", type=int, required=True, help="group id#")
|
parser.add_argument("-g", "--group", type=int, required=True, help="group id#")
|
||||||
parser.add_argument("-a", "--action", type=str, default='on', help="on|off|relax|bright|dimmed|nightlight")
|
parser.add_argument("-a", "--action", type=str, default='on', help="on|off|relax|bright|dimmed|nightlight")
|
||||||
parser.add_argument("-v", "--verbose", action='store_true', help="verbose")
|
parser.add_argument("-v", "--verbose", action='store_true', help="verbose")
|
||||||
|
@ -29,8 +31,7 @@ parser.add_argument("-d", "--debug", action='store_true', help="debug")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
bridge = args.bridge
|
bridgename = args.bridgename
|
||||||
token = args.token
|
|
||||||
group = args.group
|
group = args.group
|
||||||
action = args.action
|
action = args.action
|
||||||
verbose = args.verbose
|
verbose = args.verbose
|
||||||
|
@ -39,6 +40,12 @@ try:
|
||||||
except argparse.ArgumentError as e:
|
except argparse.ArgumentError as e:
|
||||||
print(str(e))
|
print(str(e))
|
||||||
|
|
||||||
|
config_files = ['./hue.conf', './.hue.conf', '/etc/hue.conf', '/etc/hue/hue.conf', os.path.expanduser('~/.hue.conf'), os.path.expanduser('~/hue.conf')]
|
||||||
|
config = configparser.RawConfigParser()
|
||||||
|
config.read(config_files)
|
||||||
|
bridge = config.get(bridgename, 'ip')
|
||||||
|
token = config.get(bridgename, 'token')
|
||||||
|
|
||||||
no_cert_check = ssl.create_default_context()
|
no_cert_check = ssl.create_default_context()
|
||||||
no_cert_check.check_hostname=False
|
no_cert_check.check_hostname=False
|
||||||
no_cert_check.verify_mode=ssl.CERT_NONE
|
no_cert_check.verify_mode=ssl.CERT_NONE
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
[bridge1]
|
||||||
|
ip = 192.168.100.101
|
||||||
|
token = bridge1token
|
||||||
|
[bridge2]
|
||||||
|
ip = 192.168.100.102
|
||||||
|
token = bridge2token
|
19
lightctl.py
19
lightctl.py
|
@ -1,12 +1,13 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
#
|
#
|
||||||
# Copyright 2019, Mischa Peters <mischa AT high5 DOT nl>, High5!.
|
# Copyright 2019-2020, Mischa Peters <mischa AT high5 DOT nl>, High5!.
|
||||||
# Version 1.0 - 20191102
|
# Version 1.0 - 20191102
|
||||||
|
# Version 1.1 - 20200507 - added config file support
|
||||||
#
|
#
|
||||||
# Control a light or plug
|
# Control a light or plug
|
||||||
#
|
#
|
||||||
# For example:
|
# For example:
|
||||||
# $ lightctl.py <bridge IP> <token> -l 24 -a relax
|
# $ lightctl.py <bridge name> -l 24 -a relax
|
||||||
#
|
#
|
||||||
# Follow the steps at the Hue Developer site to get the username/token
|
# Follow the steps at the Hue Developer site to get the username/token
|
||||||
# https://developers.meethue.com/develop/get-started-2/
|
# https://developers.meethue.com/develop/get-started-2/
|
||||||
|
@ -18,10 +19,11 @@ import argparse
|
||||||
import ssl
|
import ssl
|
||||||
import urllib.request
|
import urllib.request
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
|
import configparser
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description="Control light")
|
parser = argparse.ArgumentParser(description="Control light")
|
||||||
parser.add_argument("bridge", type=str, help="Hue Bridge IP")
|
parser.add_argument("bridgename", type=str, help="Hue Bridge name in specified in hue.conf")
|
||||||
parser.add_argument("token", type=str, help="Hue API Token")
|
|
||||||
parser.add_argument("-l", "--light", type=int, required=True, help="light id#")
|
parser.add_argument("-l", "--light", type=int, required=True, help="light id#")
|
||||||
parser.add_argument("-a", "--action", type=str, default='on', help="on|off|relax|bright|dimmed|nightlight|state")
|
parser.add_argument("-a", "--action", type=str, default='on', help="on|off|relax|bright|dimmed|nightlight|state")
|
||||||
parser.add_argument("-v", "--verbose", action='store_true', help="verbose")
|
parser.add_argument("-v", "--verbose", action='store_true', help="verbose")
|
||||||
|
@ -29,8 +31,7 @@ parser.add_argument("-d", "--debug", action='store_true', help="debug")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
bridge = args.bridge
|
bridgename = args.bridgename
|
||||||
token = args.token
|
|
||||||
light = args.light
|
light = args.light
|
||||||
action = args.action
|
action = args.action
|
||||||
verbose = args.verbose
|
verbose = args.verbose
|
||||||
|
@ -39,6 +40,12 @@ try:
|
||||||
except argparse.ArgumentError as e:
|
except argparse.ArgumentError as e:
|
||||||
print(str(e))
|
print(str(e))
|
||||||
|
|
||||||
|
config_files = ['./hue.conf', './.hue.conf', '/etc/hue.conf', '/etc/hue/hue.conf', os.path.expanduser('~/.hue.conf'), os.path.expanduser('~/hue.conf')]
|
||||||
|
config = configparser.RawConfigParser()
|
||||||
|
config.read(config_files)
|
||||||
|
bridge = config.get(bridgename, 'ip')
|
||||||
|
token = config.get(bridgename, 'token')
|
||||||
|
|
||||||
no_cert_check = ssl.create_default_context()
|
no_cert_check = ssl.create_default_context()
|
||||||
no_cert_check.check_hostname=False
|
no_cert_check.check_hostname=False
|
||||||
no_cert_check.verify_mode=ssl.CERT_NONE
|
no_cert_check.verify_mode=ssl.CERT_NONE
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
#
|
#
|
||||||
# Copyright 2019, Mischa Peters <mischa AT high5 DOT nl>, High5!.
|
# Copyright 2019-2020, Mischa Peters <mischa AT high5 DOT nl>, High5!.
|
||||||
# Version 1.0 - 20191103
|
# Version 1.0 - 20191103
|
||||||
|
# Version 1.1 - 20200507 - added config file support
|
||||||
#
|
#
|
||||||
# Get temperaure from all sensors
|
# Get temperaure from all sensors
|
||||||
#
|
#
|
||||||
# For exmaple:
|
# For exmaple:
|
||||||
# $ temperature.py <bridge IP> <token>
|
# $ temperature.py <bridge name>
|
||||||
#
|
#
|
||||||
# Requires:
|
# Requires:
|
||||||
# - Python 3.x
|
# - Python 3.x
|
||||||
|
@ -18,23 +19,29 @@ import json
|
||||||
import re
|
import re
|
||||||
import collections
|
import collections
|
||||||
import math
|
import math
|
||||||
|
import os
|
||||||
|
import configparser
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description="Get temperature from Hue Bridge")
|
parser = argparse.ArgumentParser(description="Get temperature from Hue Bridge")
|
||||||
parser.add_argument("bridge", type=str, help="Hue Bridge IP")
|
parser.add_argument("bridgename", type=str, help="Hue Bridge name in specified in hue.conf")
|
||||||
parser.add_argument("token", type=str, help="Hue API Token")
|
|
||||||
parser.add_argument("-v", "--verbose", action='store_true', help="verbose")
|
parser.add_argument("-v", "--verbose", action='store_true', help="verbose")
|
||||||
parser.add_argument("-d", "--debug", action='store_true', help="debug")
|
parser.add_argument("-d", "--debug", action='store_true', help="debug")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
bridge = args.bridge
|
bridgename = args.bridgename
|
||||||
token = args.token
|
|
||||||
verbose = args.verbose
|
verbose = args.verbose
|
||||||
debug = args.debug
|
debug = args.debug
|
||||||
|
|
||||||
except argparse.ArgumentError as e:
|
except argparse.ArgumentError as e:
|
||||||
print(str(e))
|
print(str(e))
|
||||||
|
|
||||||
|
config_files = ['./hue.conf', './.hue.conf', '/etc/hue.conf', '/etc/hue/hue.conf', os.path.expanduser('~/.hue.conf'), os.path.expanduser('~/hue.conf')]
|
||||||
|
config = configparser.RawConfigParser()
|
||||||
|
config.read(config_files)
|
||||||
|
bridge = config.get(bridgename, 'ip')
|
||||||
|
token = config.get(bridgename, 'token')
|
||||||
|
|
||||||
no_cert_check = ssl.create_default_context()
|
no_cert_check = ssl.create_default_context()
|
||||||
no_cert_check.check_hostname=False
|
no_cert_check.check_hostname=False
|
||||||
no_cert_check.verify_mode=ssl.CERT_NONE
|
no_cert_check.verify_mode=ssl.CERT_NONE
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
PATH=$PATH:/usr/local/bin
|
|
||||||
#
|
|
||||||
# Easy invocation of python script
|
|
||||||
# Add the following to crontab:
|
|
||||||
# */5 * * * * /<path-to-your-script>/wrapper-daylight-trigger.sh
|
|
||||||
#
|
|
||||||
# ambient light sensor 43 to check
|
|
||||||
# light 7 to control
|
|
||||||
# scene dimmed
|
|
||||||
/home/mischa/hue/daylight-trigger.py $(cat /home/mischa/hue-bridge2) $(cat /home/mischa/hue-token2) -s 43 -l 7 -a dimmed
|
|
|
@ -5,12 +5,12 @@ PATH=$PATH:/usr/local/bin
|
||||||
# Add the following to crontab:
|
# Add the following to crontab:
|
||||||
# @daily /<path-to-your-script>/wrapper-sensors-battery.sh
|
# @daily /<path-to-your-script>/wrapper-sensors-battery.sh
|
||||||
#
|
#
|
||||||
result=$(/home/mischa/hue/get-sensors.py $(cat /home/mischa/hue-bridge) $(cat /home/mischa/hue-token) -b 20)
|
result=$(/home/mischa/hue/get-sensors.py bridge1 -b 20)
|
||||||
result2=$(/home/mischa/hue/get-sensors.py $(cat /home/mischa/hue-bridge2) $(cat /home/mischa/hue-token2) -b 20)
|
result2=$(/home/mischa/hue/get-sensors.py bridge2 -b 20)
|
||||||
|
|
||||||
if [[ -n "$result" ]]; then
|
if [[ -n "$result" ]]; then
|
||||||
echo "${result}" | mail -s "Hue Battery Status $(cat /home/mischa/hue-bridge)" $(cat /home/mischa/hue-email)
|
echo "${result}" | mail -s "Hue Battery Status bridge1" $(cat /home/mischa/hue-email)
|
||||||
fi
|
fi
|
||||||
if [[ -n "$result2" ]]; then
|
if [[ -n "$result2" ]]; then
|
||||||
echo "${result2}" | mail -s "Hue Battery Status $(cat /home/mischa/hue-bridge2)" $(cat /home/mischa/hue-email)
|
echo "${result2}" | mail -s "Hue Battery Status bridge2" $(cat /home/mischa/hue-email)
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue