Announcement

Collapse
No announcement yet.

sunrise/sunset script

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

  • Fuego
    replied
    He did ask for it as part of larger (alarm) script, though

    Anyway, here is my VB.NET flavour tuppence-worth:

    Code:
    Private Function IsSun(Optional ByVal TimeToCheck As Date = Nothing) As Boolean
        If TimeToCheck = Nothing Then
            TimeToCheck = Now
        End If
        Return TimeToCheck >= hs.SunriseDt And TimeToCheck < hs.SunsetDt
    End Function

    Leave a comment:


  • Rupp
    replied
    A script is not required to do this. You could set up and event that triggers on Daytime or Nighttime.

    Leave a comment:


  • DanWheeler
    replied
    thank you for that script! it's the only one anywhere in the forum that actually works. There are all kinds of peculiarities with sunset/sunrise that cause problems but this script really works.

    Leave a comment:


  • glabbeek
    replied
    That works!


    thanks a lot.

    Leave a comment:


  • Guest's Avatar
    Guest replied
    Try this out, I threw it together in about 15 min. so did not have much time to debug it.

    Code:
    sub main()
    
    dim currenttime
    dim sunset
    dim sunrise
    dim sunrisediff
    dim sensetdiff
    
    sunset = hs.sunset
    sunrise = hs.sunrise
    currenttime = formatdatetime (time, vbshorttime)
    
    sunrisediff = datediff("n", currenttime, sunrise)
    sunsetdiff = datediff("n", currenttime, sunset)
    if (sunrisediff <= 0) and (sunsetdiff >= 0) then
    hs.speak "It is light outside"
    else
    hs.speak "It is dark outside."
    end if
    
    
    end sub

    Leave a comment:


  • glabbeek
    started a topic sunrise/sunset script

    sunrise/sunset script

    As part of the script that I am writting to use with my alarm system, I want to compare whether the current time is before or after sunrise/sunset.

    Here is what I came up with, but it does not work correct.

    sub main()

    dim currenttime
    dim sunset
    dim sunrise


    sunset = hs.sunset
    sunrise = hs.sunrise
    currenttime = formatdatetime (time, vbshorttime)


    msgbox currenttime & " sr: " & sunrise & " ss: " & sunset
    if (curerenttime <= sunrise) or (currenttime >= sunset) then
    hs.speak "It is dark outside"
    else
    hs.speak "It is light outside."
    end if


    end sub


    Can anybody help me out on this.

    Regards Willem-bram
Working...
X