I am trying to write a script to check if "now" is between sunrise and sunset, but I have problem to calculate the time difference (or maybe the time difference is not needed at all, it would be just enough to check with a IF and < >), anyway.
- Code: Select all
import datetime
sunrise = indigo.server.calculateSunrise()
sunset = indigo.server.calculateSunset()
now = datetime.datetime.now()
huePlugin = indigo.server.getPlugin("com.nathansheldon.indigoplugin.HueLights")
timeDelta1 = now - sunrise # if < 0, is bright enough
timeDelta2 = now - sunset # # if > 0, it is bright enough
indigo.server.log("timeDelta1" + timeDelta1)
indigo.server.log("timeDelta2: " + timeDelta2.strftime("%H:%M:%S"))
scala1 = indigo.devices[7081105]
scala4 = indigo.devices[1015827393] # "Scala-4"
isNight = indigo.variables[1390212289]
logMsg = ""
indigo.server.log("isNight: " + isNight.value)
# from here it is to be modified and use some variables, not yet implemented
# if ((isDark and scala1.brightness == 0) or (isNight == "true" and scala1.brightness == 0)):
if (isNight == "true" and scala1.brightness == 0):
indigo.server.log("Motion KG: Is Dark or night is ON and Scala-1 is OFF, I will switch lights ON")
huePlugin.executeAction("setCT", deviceId=7081105, props={"brightness":10, "temperature":2000})
huePlugin.executeAction("setCT", deviceId= 1015827393, props={"brightness":10, "temperature":2000})
time.sleep(45)
huePlugin.executeAction("setBrightness", deviceId=7081105, props={"brightness":0, "rate":10})
huePlugin.executeAction("setBrightness", deviceId= 1015827393, props={"brightness":0, "rate":10})
indigo.server.log("45 seconds elapsed, I will switch off lights now")
else:
logMsg = "Motion KG: None of the conditions are satisfied, I will not switch the lights ON"
indigo.server.log(logMsg)
I am trying to print those line to check the values:
- Code: Select all
indigo.server.log("timeDelta1" + timeDelta1)
indigo.server.log("timeDelta2: " + timeDelta2.strftime("%H:%M:%S"))
But I get:
- Code: Select all
Script Error trigger "Movimento Notte KG (Python)" script error in file Motion-KG.py:
Script Error can only concatenate str (not "datetime.timedelta") to str
Script Error Exception Traceback (most recent call shown last):
Motion-KG.py, line 13, at top level
TypeError: can only concatenate str (not "datetime.timedelta") to str
Thanks
Marco