Python Forum
Sending different color codes in python at certain times
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sending different color codes in python at certain times
#3
Not quite what i was after. This is how i currently do it, but its way too slow and sluggish.

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
 
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]]

 
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
RE: Sending different color codes in python at certain times - by Kimzer - Jun-17-2018, 03:22 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Sending a text from Python sawtooth500 2 289 Apr-14-2024, 01:56 PM
Last Post: sawtooth500
  Turtle Star Fill Color Yellow-White Interchanging Color Effect codelab 9 1,181 Oct-25-2023, 09:09 AM
Last Post: codelab
Photo Visual studio code unable to color syntax on python interpreter tomtom 4 7,128 Mar-02-2022, 01:23 AM
Last Post: tomtom
  Sending string commands from Python to a bluetooth device Rovelin 13 9,797 Aug-31-2021, 06:40 PM
Last Post: deanhystad
  How to set LD_LIBRARY_PATH on python codes? aupres 1 8,610 Mar-25-2021, 08:49 AM
Last Post: buran
  Automating to run python script 100 times by changing parameters pmt 1 2,649 Dec-29-2020, 10:31 AM
Last Post: andydoc
  Sending Out Email via Python JoeDainton123 1 4,844 Aug-31-2020, 12:54 AM
Last Post: nilamo
  How to load log.txt directly into python codes? sparkt 6 3,061 Aug-21-2020, 03:51 PM
Last Post: sparkt
  Python sockets : Client sending to the server nico31780 0 2,393 May-17-2020, 07:56 PM
Last Post: nico31780
  problems sending BIN file with XMODEM python shaya2103 0 2,887 Nov-23-2019, 10:27 AM
Last Post: shaya2103

Forum Jump:

User Panel Messages

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