Python Forum
Time based control of phillips hue
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Time based control of phillips hue
#2
something like this

import requests
import time

colors = {'white':'{"on":true,"bri":255,"sat":0,"hue":0}',
          'blue':'{"on":true,"bri":255,"sat":255,"hue":46920}',
          'red':'{"on":true,"bri":255,"sat":255,"hue":0}',
          'yellow':'{"on":true,"bri":255,"sat":255,"hue":12750}'}

hour = time.localtime().tm_hour

if hour > 19:
    color = colors['yellow']
elif hour > 6:
    color = colors['white']
elif hour > 1:
    color = colors['blue']
else:
    color = colors['red']


# ----- alternative to above if/elif/else block -----

time_colors = {(0,2):'red', (2,7):'blue', (7, 20):'white', (20,24):'yellow'}
color_schema  = {hour:color for hours, color in time_colors.items() for hour in range(hours[0], hours[1])}
color = colors[color_schema[hour]]


# ----- end of the alternative -----


headers = {
    'Accept': 'application/json',
}

requests.put('http://192.168.1.47/api/xxxxxxxxxxxxxxxxxxx/lights/2/state', headers=headers, data=color)
Reply


Messages In This Thread
Time based control of phillips hue - by Kimzer - Dec-22-2017, 04:38 PM
RE: Time based control of phillips hue - by buran - Dec-22-2017, 06:40 PM
RE: Time based control of phillips hue - by Larz60+ - Dec-22-2017, 07:16 PM
RE: Time based control of phillips hue - by Kimzer - Dec-22-2017, 07:35 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Update Date based on Time/String stevezemlicka 1 2,057 Jan-08-2021, 06:54 PM
Last Post: Gribouillis
  Split gps files based on time (text splitting) dervast 0 1,917 Nov-09-2020, 09:19 AM
Last Post: dervast
  Time based loops Owenix 4 3,823 Sep-20-2018, 05:37 PM
Last Post: Owenix
  Phillips hue simple on script Kimzer 6 4,628 Jan-16-2018, 07:53 AM
Last Post: Kimzer

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020