Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added smart light automation script #192

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions DSA/Sorting/ternarySearch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""
Ternary Search|

We can divide the array into three parts by
taking mid1 and mid2 which can be calculated
as shown below. Initially, l and r will be
equal to 0 and n-1 respectively, where n is
the length of the array.
mid1 = l + (r-l)/3
mid2 = r – (r-l)/3
"""
def ternerySearch(arr,x):
l=0
r=len(arr)-1
while l<=r:
m1= l+(r-l)//3
m2 = r-(r-l)//3
if x<arr[m1]:
r=m1-1
elif x>arr[m2]:
l=m2+1
elif x==arr[m1] or x==arr[m2]:
return True
else:
l=m1+1
r=m2-1
return False


"""
We can apply ternery search on unimodal
functions:-
A function f(x) is a unimodal function
if for some value m, it is monotonically
increasing for x ≤ m and monotonically
decreasing for x ≥ m.
"""
63 changes: 63 additions & 0 deletions random/light_control.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# import phue library
from phue import Bridge
import time

# add ip address of your router
ip_address = ''

#establishing connection
connection = Bridge(ip_address)
list_of_lights = connection.lights


#Switch on all lights
def switch_on():
for light in list_of_lights:
light.on = True
light.hue = 15000
light.saturation = 120

#Switch of all lights
def switch_of():
for light in list_of_lights:
light.on = False


#Toggle specific light
def toggle_light(name):
light = connection.get_light(name)
if light.on:
light.on = True
else:
light.on = False


#Set Timer to on or off
def setTime(hour,minute,On):
T = time.localtime()
curr_hour,curr_minute = T[3],T[4]

if curr_hour >= hour and curr_minute:
if On:
for light in list_of_lights:
light.on = False
else:
for light in list_of_lights:
light.on = False


#Dim light according to the time of day
def naturalLight():
T = time.localtime()
curr_hour = T[3]

if curr_hour >= 6 and curr_hour <= 18:
for light in list_of_lights:
light.on = True
light.hue = 15000
light.saturation = 120
else:
for light in list_of_lights:
light.on = True
light.hue = 150
light.saturation = 50