1
$\begingroup$

I recently installed motorized solar blinds on various windows in our house to reduce solar gain during the summer months. I have integrated the blinds with my hubitat home automation system, and am writing a python script to control the blinds. I've got lat/lon coordinates for my house, and I've determined that my house faces 145 degrees SE. I'm trying to figure out how to use astropy to determine which side(s) of the house the sun is shining on (if any) at the current time. My house shape is basically square, so the windows are basically either parallel or perpendicular to the direction the house faces.

I've found this example for getting the solar zenith. I'm assuming I need to use something like this example, plus the azimuth, adjusted somehow for the direction my house faces, to figure out which windows are getting sun at a given time, but I'm still working out the math. Thanks in advance for your help.

$\endgroup$
0

1 Answer 1

3
$\begingroup$

The code below will give you the alt-az coordinates for any specified location for any specified time. From there, I think the easiest method to determine which side of the house it will hit is to subtract 145deg from the AZ, so that 0 means it's hitting the front dead on. I'll call this the "front angle".

If the front angle is between 270 and 90 (passing through 0), it's hitting the front. Between 0 and 180 the left, between 90 and 270 the back, and between 180 and 0 the right.

You'll also want to validate the sun's altitude is > 0

#!/usr/bin/python
import astropy.units as u
from astropy.time import Time
from astropy.coordinates import EarthLocation, AltAz
from astropy.coordinates import get_sun

louisville = EarthLocation.from_geodetic(-85.7636,38.2464000,0)
utcoffset = -4*u.hour  # Eastern Daylight Time
time = Time('2012-7-12 20:00:00') - utcoffset
aaframe=AltAz(obstime=time,location=louisville)

sun=get_sun(time)

sunaa=sun.transform_to(aaframe)
print(f"Sun Alt, Az = {sunaa.alt} {sunaa.az}")

frontAngle=sunaa.az-145*u.deg

if(frontAngle<0): frontAngle=frontAngle+360*u.deg
print(f"Front Angle = {frontAngle}")

if (frontAngle.is_within_bounds('270d', '360d') or frontAngle.is_within_bounds('0d', '90d')): print("front")
if (frontAngle.is_within_bounds('0d', '180d')): print("left")
if (frontAngle.is_within_bounds('90d', '270d')): print("back")
if (frontAngle.is_within_bounds('180d', '360d')): print("right")
$\endgroup$
5
  • $\begingroup$ Thanks! It's not clear to me how to check for the case where it "passes through zero". Can you modify the above code with four if statements showing how to check for front/left/right/back? $\endgroup$
    – cayblood
    Apr 26, 2022 at 20:46
  • $\begingroup$ Never mind, I think I understand now. I just suggested an edit to your code. Let me know if that is what you were thinking. $\endgroup$
    – cayblood
    Apr 26, 2022 at 21:13
  • $\begingroup$ Yep, that's it. $\endgroup$ Apr 26, 2022 at 23:59
  • $\begingroup$ Maybe change those 4 final if statements into an if... elif ... else block. $\endgroup$
    – PM 2Ring
    Apr 27, 2022 at 9:41
  • $\begingroup$ You don't want these to be elif's because there's overlap. $\endgroup$ Apr 27, 2022 at 13:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .