Page 1 of 1

Is Daylight Not Dark?

PostPosted: Tue Nov 03, 2020 4:39 am
by Hackencrash
Is Daylight the opposite of Dark or is it some random minutes after sunrise and before sunset depending on season?

I am trying to perfect a better set of light level variables based on an outside luminance sensor. Lights, blinds and curtains can then be fine-tuned for a better experience. For instance, winter months or miserable weather makes it darker and causes difficulties when just relying on sunrise and sunset values alone.

However, I need a backup plan should my luminance sensor fail, so I would like to understand the actual logic behind the Daylight and Dark variables, and if they are different, how would I trigger on the Dark variable that does not appear in the variables list?

:)

Re: Is Daylight Not Dark?

PostPosted: Tue Nov 03, 2020 4:57 am
by autolog
To my knowledge, there is only one readOnly variable: isDaylight which can be true (daytime) or false (nighttime)? :)

Re: Is Daylight Not Dark?

PostPosted: Tue Nov 03, 2020 5:05 am
by Hackencrash
Thanks Jon. So do you know how isDaylight is calculated?

Re: Is Daylight Not Dark?

PostPosted: Tue Nov 03, 2020 5:42 am
by autolog
Hackencrash wrote:
Thanks Jon. So do you know how isDaylight is calculated?

Not specifically but it is based on the sunset and sunrise at your location that Indigo calculates.

You specify your location in the Sunset & Sunrise tab in Indigo's preferences.

There are also two Indigo server commands for returning the sunset and sunrise times, see here: Server Properties and Commands (indigo.server.*) :)

Re: Is Daylight Not Dark?

PostPosted: Tue Nov 03, 2020 11:23 am
by Hackencrash
Ah OK thanks Jon.

To summarise, the isDaylight variable is true on or after Sunrise and false on or after Sunset.

I thought it would be a bit too much to ask to take into account the variation in light intensity that results from the angle at which the sun’s rays hit the Earth depending on time of year! (although there are charts for this) :D

I can see a plug-in coming, no I can’t! I think I’ll stick to my luminance sensor and use isDaylight as a failsafe :)

Thanks again

Re: Is Daylight Not Dark?

PostPosted: Tue Nov 03, 2020 1:04 pm
by DaveL17
I believe someone actually took a stab at this at one point. You might find something in the forums.

Found it: https://www.indigodomo.com/pluginstore/110/

Re: Is Daylight Not Dark?

PostPosted: Tue Nov 03, 2020 1:06 pm
by Hackencrash
OMG this looks exactly what I was after!

Thanks DaveL17 :)

Re: Is Daylight Not Dark?

PostPosted: Tue Nov 03, 2020 1:09 pm
by FlyingDiver
I wrote this code a while back. Requires install of the ephem library (pip install ephem).

Code: Select all
import ephem

varAzimuth    = indigo.variables[717359973] # "Azimuth"
varElevation  = indigo.variables[719196174] # "Elevation"

(latitude, longitude) = indigo.server.getLatitudeAndLongitude()

obs=ephem.Observer()
obs.lat=str(latitude)
obs.long=str(longitude)
sun = ephem.Sun(obs)

azimuth = float(sun.az) * 57.2957795      # convert radians to degrees
elevation = float(sun.alt) * 57.2957795

indigo.variable.updateValue(varAzimuth, str(azimuth))
indigo.variable.updateValue(varElevation, str(elevation))

#indigo.server.log(u"Latitude: {}, Longitude: {}".format(latitude, longitude))
#indigo.server.log(u"Sun Azimuth: {}, elevation: {}".format(azimuth, elevation))


I use it to close a specific shade in my house when the sun elevation gets below a certain threshold, and the azimuth is within a certain range. If I don't the sun shines over my shoulder and reflects off my main computer screen. ;)

Re: Is Daylight Not Dark?

PostPosted: Tue Nov 03, 2020 1:16 pm
by Hackencrash
Alright so I need to create two Indigo variables with different ID's to yours and the Azimuth is the left and right stuff and Elevation being the up and down stuff. I'm going to give this a go!

Thanks!
:D

Re: Is Daylight Not Dark?

PostPosted: Tue Nov 03, 2020 1:17 pm
by FlyingDiver
I run that script in an Indigo scheduler action every 10 minutes (I think). Then I have a trigger that fires when the elevation field goes below a certain value to close the shade.