我想创建一个pyhton脚本,模拟我的一些连接到家庭助理的飞利浦色调灯的日出
我试图实现的是,遵循亮度和开尔文值的s/s形曲线
我希望亮度从1到100(%),开尔文值从2500到4000
我当前的脚本以线性方式执行此操作:
#import time
def sunrise(entity_id, minutes, updatesecs=10, startbrightness=1, endbrightness=100, startkelvin=2500, endkelvin=4000):
# Set current brightness and kelvin to the staring values
currentbrightness=startbrightness
currentkelvin=startkelvin
# Calculate the needed iterations for the while loop
numberofiterations=minutes*60/updatesecs
kelvinincreasebyiteration=(endkelvin-startkelvin)/numberofiterations
i=0
while(i<=numberofiterations):
# Set new brightness value
currentbrightness = currentbrightness+endbrightness/numberofiterations
currentkelvin = currentkelvin+kelvinincreasebyiteration
if currentbrightness <= endbrightness:
#print(round(currentbrightness)) # This value will be used for setting the brightness
#print(round(currentkelvin))
service_data = {"entity_id": entity_id, "kelvin": currentkelvin, "brightness_pct": currentbrightness, "transition": updatesecs-1}
hass.services.call("light", "turn_on", service_data, False)
time.sleep(updatesecs)
else:
break
entity_id = data.get("entity_id")
minutes = data.get("minutes")
updatesecs = data.get("updatesecs")
sunrise(entity_id,minutes,updatesecs)
如果您有任何使用s形值而不是线性值设置亮度/开尔文的想法,我们将不胜感激
您可以简单地迭代最终df,使用亮度和开尔文值,每个间隔睡眠一分钟左右,然后调用api
相关问题 更多 >
编程相关推荐