added config file support, hue.conf
This commit is contained in:
parent
e7e27decb5
commit
496ad2f3f6
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
hue-bridge
|
||||
hue-email
|
||||
hue-token
|
||||
_*
|
||||
|
@ -6,7 +6,7 @@
|
||||
# Create a new user on the bridge
|
||||
#
|
||||
# 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
|
||||
# https://developers.meethue.com/develop/get-started-2/
|
||||
@ -19,8 +19,8 @@ import ssl
|
||||
import urllib.request
|
||||
import json
|
||||
|
||||
parser = argparse.ArgumentParser(description="Control light")
|
||||
parser.add_argument("bridge", type=str, help="Hue Bridge IP")
|
||||
parser = argparse.ArgumentParser(description="Create a new developer token on the Hue Bridge")
|
||||
parser.add_argument("bridge", type=str, help="Hue Bridge IP address")
|
||||
|
||||
try:
|
||||
args = parser.parse_args()
|
||||
|
@ -1,14 +1,18 @@
|
||||
#!/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.1 - 20200507 - added config file support
|
||||
#
|
||||
# Control a light based on sensor information
|
||||
# Get ['dark'] from sensor ID and switch on/off light ID
|
||||
# depending where your sensor is located you can use ['daylight']
|
||||
#
|
||||
# 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
|
||||
# https://developers.meethue.com/develop/get-started-2/
|
||||
@ -20,10 +24,11 @@ import argparse
|
||||
import ssl
|
||||
import urllib.request
|
||||
import json
|
||||
import os
|
||||
import configparser
|
||||
|
||||
parser = argparse.ArgumentParser(description="Control light based on light sensor")
|
||||
parser.add_argument("bridge", type=str, help="Hue Bridge IP")
|
||||
parser.add_argument("token", type=str, help="Hue API Token")
|
||||
parser.add_argument("bridgename", type=str, help="Hue Bridge name in specified in hue.conf")
|
||||
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("-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:
|
||||
args = parser.parse_args()
|
||||
bridge = args.bridge
|
||||
token = args.token
|
||||
bridgename = args.bridgename
|
||||
sensor = args.sensor
|
||||
light = args.light
|
||||
action = args.action
|
||||
@ -43,6 +47,12 @@ try:
|
||||
except argparse.ArgumentError as 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.check_hostname=False
|
||||
no_cert_check.verify_mode=ssl.CERT_NONE
|
||||
|
@ -1,12 +1,13 @@
|
||||
#!/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.1 - 20200507 - added config file support
|
||||
#
|
||||
# Get all light IDs
|
||||
#
|
||||
# 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
|
||||
# https://developers.meethue.com/develop/get-started-2/
|
||||
@ -18,19 +19,25 @@ import argparse
|
||||
import ssl
|
||||
import urllib.request
|
||||
import json
|
||||
import os
|
||||
import configparser
|
||||
|
||||
parser = argparse.ArgumentParser(description="Get all group ids from Hue Bridge")
|
||||
parser.add_argument("bridge", type=str, help="Hue Bridge IP")
|
||||
parser.add_argument("token", type=str, help="Hue API Token")
|
||||
parser.add_argument("bridgename", type=str, help="Hue Bridge name in specified in hue.conf")
|
||||
|
||||
try:
|
||||
args = parser.parse_args()
|
||||
bridge = args.bridge
|
||||
token = args.token
|
||||
bridgename = args.bridgename
|
||||
|
||||
except argparse.ArgumentError as 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.check_hostname=False
|
||||
no_cert_check.verify_mode=ssl.CERT_NONE
|
||||
|
19
get-id.py
19
get-id.py
@ -1,12 +1,13 @@
|
||||
#!/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.1 - 20200507 - added config file support
|
||||
#
|
||||
# Collect all information of given id
|
||||
#
|
||||
# For example:
|
||||
# $ get-id.py <bridge IP> <token> -t sensors -i 6
|
||||
# $ get-id.py <bridge name> -t sensors -i 6
|
||||
#
|
||||
# Requires:
|
||||
# - Python 3.x
|
||||
@ -15,18 +16,18 @@ import argparse
|
||||
import ssl
|
||||
import urllib.request
|
||||
import json
|
||||
import os
|
||||
import configparser
|
||||
|
||||
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("bridgename", type=str, help="Hue Bridge name in specified in hue.conf")
|
||||
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("-v", "--verbose", action='store_true', help="verbose")
|
||||
|
||||
try:
|
||||
args = parser.parse_args()
|
||||
bridge = args.bridge
|
||||
token = args.token
|
||||
bridgename = args.bridgename
|
||||
id = args.id
|
||||
type = args.type
|
||||
verbose = args.verbose
|
||||
@ -34,6 +35,12 @@ try:
|
||||
except argparse.ArgumentError as 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.check_hostname=False
|
||||
no_cert_check.verify_mode=ssl.CERT_NONE
|
||||
|
@ -1,13 +1,14 @@
|
||||
#!/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.1 - 20191103 - added ['state']['on']
|
||||
# Version 1.2 - 20200507 - added config file support
|
||||
#
|
||||
# Get all light ids and state
|
||||
#
|
||||
# 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
|
||||
# https://developers.meethue.com/develop/get-started-2/
|
||||
@ -19,21 +20,27 @@ import argparse
|
||||
import ssl
|
||||
import urllib.request
|
||||
import json
|
||||
import os
|
||||
import configparser
|
||||
|
||||
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")
|
||||
parser.add_argument("bridgename", type=str, help="Hue Bridge name in specified in hue.conf")
|
||||
parser.add_argument("-i", "--id", type=int, help="light id#")
|
||||
|
||||
try:
|
||||
args = parser.parse_args()
|
||||
bridge = args.bridge
|
||||
token = args.token
|
||||
bridgename = args.bridgename
|
||||
id = args.id
|
||||
|
||||
except argparse.ArgumentError as 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.check_hostname=False
|
||||
no_cert_check.verify_mode=ssl.CERT_NONE
|
||||
|
@ -1,14 +1,15 @@
|
||||
#!/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.1 - 20191106 - added battery status
|
||||
# Version 1.2 - 20200507 - added config file support
|
||||
#
|
||||
# Get all sensor IDs (ZLLPresence, ZLLLightLevel and ZLLTemperature)
|
||||
# grouped by ZLLPresence name
|
||||
#
|
||||
# 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
|
||||
# https://developers.meethue.com/develop/get-started-2/
|
||||
@ -22,23 +23,29 @@ import urllib.request
|
||||
import json
|
||||
import re
|
||||
import collections
|
||||
import os
|
||||
import configparser
|
||||
|
||||
parser = argparse.ArgumentParser(description="Get all sensor ids from Hue Bridge")
|
||||
parser.add_argument("bridge", type=str, help="Hue Bridge IP")
|
||||
parser.add_argument("token", type=str, help="Hue API Token")
|
||||
parser.add_argument("bridgename", type=str, help="Hue Bridge name in specified in hue.conf")
|
||||
parser.add_argument("-b", "--battery", type=int, help="battery check only, threshold, default 20")
|
||||
parser.add_argument("-v", "--verbose", action='store_true', help="verbose")
|
||||
|
||||
try:
|
||||
args = parser.parse_args()
|
||||
bridge = args.bridge
|
||||
token = args.token
|
||||
bridgename = args.bridgename
|
||||
battery = args.battery
|
||||
verbose = args.verbose
|
||||
|
||||
except argparse.ArgumentError as 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.check_hostname=False
|
||||
no_cert_check.verify_mode=ssl.CERT_NONE
|
||||
|
19
groupctl.py
19
groupctl.py
@ -1,12 +1,13 @@
|
||||
#!/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.1 - 20200507 - added config file support
|
||||
#
|
||||
# Control a group of lights (room)
|
||||
#
|
||||
# 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
|
||||
# https://developers.meethue.com/develop/get-started-2/
|
||||
@ -18,10 +19,11 @@ import argparse
|
||||
import ssl
|
||||
import urllib.request
|
||||
import json
|
||||
import os
|
||||
import configparser
|
||||
|
||||
parser = argparse.ArgumentParser(description="Control group of lights (room)")
|
||||
parser.add_argument("bridge", type=str, help="Hue Bridge IP")
|
||||
parser.add_argument("token", type=str, help="Hue API Token")
|
||||
parser.add_argument("bridgename", type=str, help="Hue Bridge name in specified in hue.conf")
|
||||
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("-v", "--verbose", action='store_true', help="verbose")
|
||||
@ -29,8 +31,7 @@ parser.add_argument("-d", "--debug", action='store_true', help="debug")
|
||||
|
||||
try:
|
||||
args = parser.parse_args()
|
||||
bridge = args.bridge
|
||||
token = args.token
|
||||
bridgename = args.bridgename
|
||||
group = args.group
|
||||
action = args.action
|
||||
verbose = args.verbose
|
||||
@ -39,6 +40,12 @@ try:
|
||||
except argparse.ArgumentError as 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.check_hostname=False
|
||||
no_cert_check.verify_mode=ssl.CERT_NONE
|
||||
|
6
hue.conf
Normal file
6
hue.conf
Normal file
@ -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
|
||||
#
|
||||
# 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.1 - 20200507 - added config file support
|
||||
#
|
||||
# Control a light or plug
|
||||
#
|
||||
# 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
|
||||
# https://developers.meethue.com/develop/get-started-2/
|
||||
@ -18,10 +19,11 @@ import argparse
|
||||
import ssl
|
||||
import urllib.request
|
||||
import json
|
||||
import os
|
||||
import configparser
|
||||
|
||||
parser = argparse.ArgumentParser(description="Control light")
|
||||
parser.add_argument("bridge", type=str, help="Hue Bridge IP")
|
||||
parser.add_argument("token", type=str, help="Hue API Token")
|
||||
parser.add_argument("bridgename", type=str, help="Hue Bridge name in specified in hue.conf")
|
||||
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("-v", "--verbose", action='store_true', help="verbose")
|
||||
@ -29,8 +31,7 @@ parser.add_argument("-d", "--debug", action='store_true', help="debug")
|
||||
|
||||
try:
|
||||
args = parser.parse_args()
|
||||
bridge = args.bridge
|
||||
token = args.token
|
||||
bridgename = args.bridgename
|
||||
light = args.light
|
||||
action = args.action
|
||||
verbose = args.verbose
|
||||
@ -39,6 +40,12 @@ try:
|
||||
except argparse.ArgumentError as 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.check_hostname=False
|
||||
no_cert_check.verify_mode=ssl.CERT_NONE
|
||||
|
@ -1,12 +1,13 @@
|
||||
#!/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.1 - 20200507 - added config file support
|
||||
#
|
||||
# Get temperaure from all sensors
|
||||
#
|
||||
# For exmaple:
|
||||
# $ temperature.py <bridge IP> <token>
|
||||
# $ temperature.py <bridge name>
|
||||
#
|
||||
# Requires:
|
||||
# - Python 3.x
|
||||
@ -18,23 +19,29 @@ import json
|
||||
import re
|
||||
import collections
|
||||
import math
|
||||
import os
|
||||
import configparser
|
||||
|
||||
parser = argparse.ArgumentParser(description="Get temperature from Hue Bridge")
|
||||
parser.add_argument("bridge", type=str, help="Hue Bridge IP")
|
||||
parser.add_argument("token", type=str, help="Hue API Token")
|
||||
parser.add_argument("bridgename", type=str, help="Hue Bridge name in specified in hue.conf")
|
||||
parser.add_argument("-v", "--verbose", action='store_true', help="verbose")
|
||||
parser.add_argument("-d", "--debug", action='store_true', help="debug")
|
||||
|
||||
try:
|
||||
args = parser.parse_args()
|
||||
bridge = args.bridge
|
||||
token = args.token
|
||||
bridgename = args.bridgename
|
||||
verbose = args.verbose
|
||||
debug = args.debug
|
||||
|
||||
except argparse.ArgumentError as 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.check_hostname=False
|
||||
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:
|
||||
# @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)
|
||||
result2=$(/home/mischa/hue/get-sensors.py $(cat /home/mischa/hue-bridge2) $(cat /home/mischa/hue-token2) -b 20)
|
||||
result=$(/home/mischa/hue/get-sensors.py bridge1 -b 20)
|
||||
result2=$(/home/mischa/hue/get-sensors.py bridge2 -b 20)
|
||||
|
||||
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
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user