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)