Skip to content

Instantly share code, notes, and snippets.

Created July 29, 2017 08:43
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Set a red alarm on a given light when the specified website is down
import os
from phue import Bridge
from time import sleep
from requests import get
import sys
SCRIPT_PATH = os.path.dirname(__file__) # Directory of the current file
KEY_FILE = os.path.join(SCRIPT_PATH, ".python_hue") # Path to hidden key file
def alarm(bridge, light_id, tr_time, blink_count):
default = b.get_light(light_id) # Default state
animIn = {'transitiontime': tr_time,
'on': True,
'bri':254, # Full luminosity
'sat': 254, # Full saturation
'hue': 65535 # Red
animOut = {'transitiontime': tr_time,
'on': True,
'bri':5, # Almost off
'sat': 70, # Less saturation
'hue': 65535 # Still red
sleep_time = float(tr_time + 1) / 10.0
for i in range(0, blink_count):
b.set_light(light_id, animIn)
b.set_light(light_id, animOut)
animOut = {
'on': default['state']['on'],
'sat': default['state']['sat'],
'hue': default['state']['hue'],
'bri': default['state']['bri'],
b.set_light(light_id, animOut) # Reset to default state
if __name__ == "__main__":
b = Bridge(IP_ADDRESS, config_file_path=KEY_FILE)
site_down = False
r = get("http://yourwbesite.tld/") # Or you can use sys.argv to specifiy the url when calling the script
if r.status_code >= 400:
site_down = True
except Exception:
site_down = True
if site_down:
alarm(b, 1, 5, 10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment