Announcement

Collapse
No announcement yet.

Solar Position Script

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Ltek
    replied
    Originally posted by sparkman View Post

    Yes, these numbers by themselves are somewhat meaningless. I use these numbers along with other factors such as light levels to determine whether to open or close shades.
    How are you doing it?


    Might be interesting to have a comprehensive script (like the zwave lock script) with a single screen defining possible variables for each 'space'...
    in-room LUX
    window/door facing (compass direction)
    outside shading factor (trees, overhangs, etc)
    inside shading factor (type of window coverings)
    etc
    ... using those with the solar position to calculate when it is light or dark in each 'space'.

    or maybe I just use LUX.

    Leave a comment:


  • sparkman
    replied
    Originally posted by Ltek View Post
    This can be very handy (I used a plugin like this on Vera)... though I found more data is needed to make it accurate.
    Yes, these numbers by themselves are somewhat meaningless. I use these numbers along with other factors such as light levels to determine whether to open or close shades.

    Leave a comment:


  • Ltek
    replied
    This can be very handy (I used a plugin like this on Vera)... though I found more data is needed to make it accurate. Each side of the house, and in some cases each door/window/room will have a different directional facing, plants, overhangs, size of window, etc ... all this changes the light hitting windows/doors or entering a space.
    For instance: my front Door is set back with close walls and large overhang... very low ambient light door most of the day; but at times angle of the sun can be blinding

    ... all of this needs to be taken into account.

    Thinking Out loud...
    Most of my motion sensors have LUX readings, I've yet to that data
    -- maybe LUX + Sun Position would render the best results?
    -- maybe a profile for each space (room / area) which creates a vDevice to tell us what the light level in that space is. <

    Leave a comment:


  • sparkman
    replied
    Originally posted by langenet View Post
    That's embarrassing... Yes, I had to change the time zone to 5 .. So the numbers now line up and my virtual devices show 224.7 and 22.2. while the site shows 224.5 and 21.68. Close enough for the government!

    Great work. Thanks for all your help!

    Robert
    You're welcome and glad it's working for you!

    Cheers
    Al

    Leave a comment:


  • langenet
    replied
    That's embarrassing... Yes, I had to change the time zone to 5 .. So the numbers now line up and my virtual devices show 224.7 and 22.2. while the site shows 224.5 and 21.68. Close enough for the government!

    Great work. Thanks for all your help!

    Robert

    Leave a comment:


  • sparkman
    replied
    langenet What are you using as the Time Zone value on that web page and where do you think the sun is approx. in real life?

    Leave a comment:


  • langenet
    replied
    Right now the site shows 233.67 and altitude of 16.13. My virtual devices show 220 and 24.5. My Latitude is 45.42 an my long is 75.67.

    Leave a comment:


  • sparkman
    replied
    Originally posted by langenet View Post
    Can you share a link Al? I'm using https://planetcalc.com/4270/ but the numbers don't jive...
    This is one of the ones I tried: https://planetcalc.com/320/

    Right now, it shows Azimuth 173.27 and altitude 27.19. My virtual devices show 173.8 and 27.5, so close enough for my purposes. How far is yours off? Likely a timezone adjustment issue.

    Leave a comment:


  • langenet
    replied
    Can you share a link Al? I'm using https://planetcalc.com/4270/ but the numbers don't jive...

    Leave a comment:


  • sparkman
    replied
    Originally posted by langenet View Post
    Al, I implemented you script - thank you. But how are you verifying the data? Doing the math or is there a site you're verifying against?
    I found a few sites I verified it with and also the sunset/sunrise times it calculates are very close to what HS has for sunset/sunrise times. When the azimuth value becomes a negative number, it is sunset and when it becomes positive, it is sunrise.

    Leave a comment:


  • langenet
    replied
    Al, I implemented you script - thank you. But how are you verifying the data? Doing the math or is there a site you're verifying against?

    Leave a comment:


  • sparkman
    replied
    Originally posted by langenet View Post
    Al... this is great. Thanks. I'm looking at this as my next automation project so I can close off the blinds to save my baby grand from the impending heat... Can elaborate what you're using for blind control?

    Thanks,

    Robert
    Hi Robert, I'm using Bali cellular shades with AutoView motors/controls. They are Z-Wave based. Bali Blinds can be bought through Costco, Home Depot, Lowe's and blinds.ca.

    Cheers
    Al

    Leave a comment:


  • langenet
    replied
    Al... this is great. Thanks. I'm looking at this as my next automation project so I can close off the blinds to save my baby grand from the impending heat... Can elaborate what you're using for blind control?

    Thanks,

    Robert

    Leave a comment:


  • sparkman
    started a topic Solar Position Script

    Solar Position Script

    Below is a script that will calculate the solar azimuth and altitude (i.e. the position of the sun in the sky) and put the values in two virtual devices. These devices can then be used to determine whether to close blinds/shades, etc. I found the base code on the internet and have been running it here for a couple of days and seems to be relatively accurate (at least for my location). To use it, create two virtual devices (see screenshots below), and edit the script with the reference IDs of those devices and also your local lat/long. I run the script using a recurring event (every 5 minutes, but adjust to whatever you want for an update time). It's only been tested on Windows and may need some minor mods to work on linux.


    Click image for larger version

Name:	Capture.PNG
Views:	306
Size:	41.4 KB
ID:	1286065
    Click image for larger version

Name:	Capture1.PNG
Views:	249
Size:	69.0 KB
ID:	1286066
    Click image for larger version

Name:	Capture2.PNG
Views:	248
Size:	57.3 KB
ID:	1286067
    Code:
     'From c code posted here: http://www.psa.es/sdg/sunpos.htm
     'VB.NET Conversion posted here: http://www.vbforums.com/showthread.php?832645-Solar-position-calculator
     'converted for HomeSeer use by Sparkman v1.0
    
    Imports System.Math
    
    Sub Main(ByVal Parms As String)
        Dim Debug As Boolean = False
        Dim logName As String = "Solar Position"
        Dim dLatitude As Double = 51.1
        Dim dLongitude As Double = -115.1
        Dim hsAzimuthDevice As Integer = 1234
        Dim hsAltitudeDevice As Integer = 1235
    
        Dim pi As Double = 3.14159265358979
        Dim rad As Double = pi / 180
        Dim dEarthMeanRadius As Double = 6371.01
        Dim dAstronomicalUnit As Double = 149597890
    
        Dim iYear As Integer = DateTime.UtcNow.Year
        Dim iMonth As Integer = DateTime.UtcNow.Month
        Dim iDay As Integer = DateTime.UtcNow.Day
        Dim dHours As Double = DateTime.UtcNow.Hour
        Dim dMinutes As Double = DateTime.UtcNow.Minute
        Dim dSeconds As Double = DateTime.UtcNow.Second
    
        Dim dZenithAngle As Double
        Dim dZenithAngleParallax As Double
        Dim dAzimuth As Double
        Dim dAltitudeAngle As Double
        Dim dElapsedJulianDays As Double
        Dim dDecimalHours As Double
        Dim dEclipticLongitude As Double
        Dim dEclipticObliquity As Double
        Dim dRightAscension As Double
        Dim dDeclination As Double
        Dim dY As Double
        Dim dX As Double
        Dim dJulianDate As Double
        Dim liAux1 As Integer
        Dim liAux2 As Integer
        Dim dMeanLongitude As Double
        Dim dMeanAnomaly As Double
        Dim dOmega As Double
        Dim dSin_EclipticLongitude As Double
        Dim dGreenwichMeanSiderealTime As Double
        Dim dLocalMeanSiderealTime As Double
        Dim dLatitudeInRadians As Double
        Dim dHourAngle As Double
        Dim dCos_Latitude As Double
        Dim dSin_Latitude As Double
        Dim dCos_HourAngle As Double
        Dim dParallax As Double
    
        Try
    
            ' Calculate difference in days between the current Julian Day and JD 2451545.0, which is noon 1 January 2000 Universal Time
            ' Calculate time of the day in UT decimal hours
            dDecimalHours = dHours + (dMinutes + dSeconds / 60.0) / 60.0
            ' Calculate current Julian Day
            liAux1 = (iMonth - 14) \ 12
            liAux2 = (1461 * (iYear + 4800 + liAux1)) \ 4 + (367 * (iMonth - 2 - 12 * liAux1)) \ 12 - (3 * ((iYear + 4900 + liAux1) \ 100)) \ 4 + iDay - 32075
            dJulianDate = CDbl(liAux2) - 0.5 + dDecimalHours / 24.0
            ' Calculate difference between current Julian Day and JD 2451545.0
            dElapsedJulianDays = dJulianDate - 2451545.0
            If Debug Then hs.writelog(logName,"Elapsed Julian Days Since 2000/01/01: " & CStr(dElapsedJulianDays))
    
            ' Calculate ecliptic coordinates (ecliptic longitude and obliquity of the ecliptic in radians but without limiting the angle to be less than 2*Pi
            ' (i.e., the result may be greater than 2*Pi)
            dOmega = 2.1429 - 0.0010394594 * dElapsedJulianDays
            dMeanLongitude = 4.895063 + 0.017202791698 * dElapsedJulianDays ' Radians
            dMeanAnomaly = 6.24006 + 0.0172019699 * dElapsedJulianDays
            dEclipticLongitude = dMeanLongitude + 0.03341607 * Math.Sin(dMeanAnomaly) + 0.00034894 * Math.Sin(2 * dMeanAnomaly) - 0.0001134 - 0.0000203 * Math.Sin(dOmega)
            dEclipticObliquity = 0.4090928 - 0.000000006214 * dElapsedJulianDays + 0.0000396 * Math.Cos(dOmega)
            If Debug Then hs.writelog(logName,"Ecliptic Longitude: " & CStr(dEclipticLongitude))
            If Debug Then hs.writelog(logName,"Ecliptic Obliquity: " & CStr(dEclipticObliquity))
    
            ' Calculate celestial coordinates ( right ascension and declination ) in radians but without limiting the angle to be less than 2*Pi (i.e., the result may be greater than 2*Pi)
            dSin_EclipticLongitude = Math.Sin(dEclipticLongitude)
            dY = Math.Cos(dEclipticObliquity) * dSin_EclipticLongitude
            dX = Math.Cos(dEclipticLongitude)
            dRightAscension = Math.Atan2(dY, dX)
            If dRightAscension < 0.0 Then
                dRightAscension = dRightAscension + (2 * pi)
            End If
            dDeclination = Math.Asin(Math.Sin(dEclipticObliquity) * dSin_EclipticLongitude)
            If Debug Then hs.writelog(logName,"Declination: " & CStr(dDeclination))
    
            ' Calculate local coordinates ( azimuth and zenith angle ) in degrees
            dGreenwichMeanSiderealTime = 6.6974243242 + 0.0657098283 * dElapsedJulianDays + dDecimalHours
            dLocalMeanSiderealTime = (dGreenwichMeanSiderealTime * 15 + dLongitude) * rad
            dHourAngle = dLocalMeanSiderealTime - dRightAscension
            If Debug Then hs.writelog(logName,"Hour Angle: " & CStr(dHourAngle))
            dLatitudeInRadians = dLatitude * rad
            dCos_Latitude = Math.Cos(dLatitudeInRadians)
            dSin_Latitude = Math.Sin(dLatitudeInRadians)
            dCos_HourAngle = Math.Cos(dHourAngle)
            dZenithAngle = (Math.Acos(dCos_Latitude * dCos_HourAngle * Math.Cos(dDeclination) + Math.Sin(dDeclination) * dSin_Latitude))
            dY = -Math.Sin(dHourAngle)
            dX = Math.Tan(dDeclination) * dCos_Latitude - dSin_Latitude * dCos_HourAngle
            dAzimuth = Math.Atan2(dY, dX)
            If dAzimuth < 0.0 Then
                dAzimuth = dAzimuth + (2 * pi)
            End If
            dAzimuth = dAzimuth / rad
    
            If Debug Then hs.writelog(logName,"Azimuth: " & CStr(dAzimuth))
            hs.setdevicevaluebyref(hsAzimuthDevice,dAzimuth,True)
    
            ' Parallax Correction
            dParallax = (dEarthMeanRadius / dAstronomicalUnit) * Math.Sin(dZenithAngle)
            dZenithAngleParallax = (dZenithAngle + dParallax) / rad
            dAltitudeAngle = (dZenithAngleParallax * -1) + 90
    
            If Debug Then hs.writelog(logName,"Altitude Angle: " & CStr(dAltitudeAngle))
            hs.setdevicevaluebyref(hsAltitudeDevice,dAltitudeAngle,True)
    
        Catch ex As Exception
            hs.WriteLog(logName, "Exception " & ex.ToString)
        End Try
    
    End Sub
Working...
X