Page 1 of 1

Sunrise Sunset - just time without date?

Posted: Mon Jan 11, 2016 4:30 am
by TonyG
Just a quickie - I'm trying to display Sunrise and Sunset time, without dates. I've looked at program options which gives some very useful options for time & date format, but not sunrise sunset?

Detail I know, but ideally I want to use a large font and not crowd the screen.

Cheers,

Tony

Re: Sunrise Sunset - just time without date?

Posted: Mon Jan 11, 2016 2:15 pm
by ScottBot
It would be easy to do with a script (Script Device). You would just need to setup a task that executes every time the sun/rise/set time changes to run the script. You will also need a new property value to store it. But something like this would work.

Code: Select all

' Get the formatted Property Value.  This will be formatted something like 'hh:mm' where hh is in 24 hour format.
szFormatted = GetPropertyValue("System Time.Sunrise Time")

' Let VB break out the time components into its own format
szTime = TimeValue(szFormatted)
nHour = int( datepart("h",szTime) )
nMinute = int( datepart("n",szTime) )

' Set the HouseBot normalized Property value correctly.
SetPropertyValue "Your Device.Your New Property to hold the time", "Hour=" & nHour & ",Minute=" & nMinute

Re: Sunrise Sunset - just time without date?

Posted: Tue Jan 12, 2016 6:50 am
by TonyG
Thanks Scott,

That should do nicely. Haven't put it into practice yet as I know it will take a little longer than it should - but should be good practice for myself.

Re: Sunrise Sunset - just time without date?

Posted: Thu Jan 14, 2016 4:02 am
by TonyG
Scott,

Worked a treat. This is the version that gave me the times in the format ideal for my UI:

' Get the formatted Property Value. This will be formatted something like 'hh:mm' where hh is in 24 hour format.
szFormatted = GetPropertyValue("System Time.Sunrise Time")

' Let VB break out the time components into its own format
szTime = TimeValue(szFormatted)
nHour = int( datepart("h",szTime) )
nMinute = int( datepart("n",szTime) )

' Set the HouseBot normalized Property value correctly.
SetPropertyValue "Sunrise.Simplified Sunrise Time", "0" & nHour & ":" & nMinute

' Get the formatted Property Value. This will be formatted something like 'hh:mm' where hh is in 24 hour format.
szFormatted = GetPropertyValue("System Time.Sunset Time")

' Let VB break out the time components into its own format
szTime = TimeValue(szFormatted)
nHour = int( datepart("h",szTime) )
nMinute = int( datepart("n",szTime) )

' Set the HouseBot normalized Property value correctly.
SetPropertyValue "Sunrise.Simplified Sunset Time", nHour & ":" & nMinute

Thanks again for your prompt help.

Tony