如何解决创建一个函数以获取S形曲线的值
我想创建一个pyhton脚本,为连接到Home Assistant的某些Philips Hue灯模拟日出。
我要实现的是按照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,updatesecs)
任何将亮度/开尔文设置为S形而不是线性的想法都值得赞赏。
解决方法
您可以简单地遍历最终的df并使用亮度和开尔文值,每个间隔睡眠一分钟左右,然后调用您的api。
val someDF = Seq(
(8,"abc"),(64,"sdf"),(-27,"yui")
).toDF("number","word")
def numberValidation(numberValidation:Any): Boolean=
numberValidation match{
case int :Integer => true
case _ => false}
def wordValidatoin(wordValidation:Any): Boolean=
wordValidation match{
case str: String => true
case _ => false}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。