This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

3 byte date/time
#1
How to fill a 3 byte date/time object with the Sunrise and sunset received from rscalc?

sunrise, sunset = rscalc(latitude, longitude)
Reply
#2
Hi Gert Jan,

Like this:
Code:
longitude = 6.0830219 -- Zwolle
latitude = 52.5167747 -- Zwolle
sunrise, sunset = rscalc(latitude, longitude)

sunrise_hour = math.floor(sunrise / 60)
sunrise_minute = sunrise % 60

sunset_hour = math.floor(sunset / 60)
sunset_minute = sunset % 60

-- get current data as table
now = os.date('*t')

-- system week day starts from sunday, convert it to knx format
wday = now.wday == 1 and 7 or now.wday - 1

-- time table Sunrise
 sunrisetime = {
 day = wday,
 hour = sunrise_hour,
 minute = sunrise_minute,
 second = 0,
}

-- time table Sunset
 sunsettime = {
 day = wday,
 hour = sunset_hour,
 minute = sunset_minute,
 second = 0,
}

grp.update('32/1/4', sunrisetime)
grp.update('32/1/5', sunsettime)
BR,

Erwin
Reply
#3
(04.10.2017, 14:50)Erwin van der Zwart Wrote: Hi Gert Jan,

Like this:
Code:
longitude = 6.0830219 -- Zwolle
latitude = 52.5167747 -- Zwolle
sunrise, sunset = rscalc(latitude, longitude)

sunrise_hour = math.floor(sunrise / 60)
sunrise_minute = sunrise % 60

sunset_hour = math.floor(sunset / 60)
sunset_minute = sunset % 60

-- get current data as table
now = os.date('*t')

-- system week day starts from sunday, convert it to knx format
wday = now.wday == 1 and 7 or now.wday - 1

-- time table Sunrise
 sunrisetime = {
 day = wday,
 hour = sunrise_hour,
 minute = sunrise_minute,
 second = 0,
}

-- time table Sunset
 sunsettime = {
 day = wday,
 hour = sunset_hour,
 minute = sunset_minute,
 second = 0,
}

grp.update('32/1/4', sunrisetime)
grp.update('32/1/5', sunsettime)
BR,

Erwin

thanks
Reply
#4
Hi there,

I am a new beginner and write with a question since I didn't found an answer in the forum.

Thank you for the script Erwin! Works perfect!

And here is the question:
Erwin's script gives the sunrise & sunset in 10. 3 byte time/day. Can I compare them in this format it with now time to switch lights outside and how?
My "new beginner" script does not work (i can maybe copy it here if necessary)

Best regards
Reply
#5
Hi,

There is no need to do that with script, just create a scheduler on your object and use the build-in function in the scheduler to switch your lights on sunrise and sunset with option to offset.

BR,

Erwin
Reply
#6
Thanks Erwin!
Sett up the schedule. Will see how it works on sunrise Smile
Reply
#7
(23.10.2017, 17:18)Erwin van der Zwart Wrote: Hi,

There is no need to do that with script, just create a scheduler on your object and use the build-in function in the scheduler to switch your lights on sunrise and sunset with option to offset.

BR,

Erwin

Are the longtitude an latitude in Date&Time used for Sunrise and sunset calc?
Reply
#8
Yes, but if you're using rscalc function in scripts then you still have to pass coordinates manually.
Reply
#9
(24.10.2017, 06:46)admin Wrote: Yes, but if you're using rscalc function in scripts then you still have to pass coordinates manually.

Yes i understand, but maybe its also possible to get the long&lat settings from date&time to use in the rscalc function?
Reply
#10
Hi,

Yes they are, and if you don’t have entered them the lon/lat of the selected timezone will be used.

BR,

Erwin

(24.10.2017, 06:51)gjniewenhuijse Wrote: Yes i understand, but maybe its also possible to get the long&lat settings from date&time to use in the rscalc function?

See: https://forum.logicmachine.net/showthrea...18#pid5818
Reply
#11
Thanks,

And i see i can use the following script to get these values:
Code:
require('uci')
lat = uci.get('genohm-scada.core.latitude')
lat = tonumber(lat)
lng = uci.get('genohm-scada.core.longitude')
lng = tonumber(lng)

Is it also possible to get the Sunset and Sunrise time without using the rscalc function, because internally the sunset and Sunrise is also used for the scheduler (how is that calculated)?

So i like to get directly, in a script, the Sunrise and Sunset times used in the scheduler.
Reply
#12
Is Sunset / Sunrise schedule going to work if the homelynk is offline or it will only work when the unit is online?
Reply
#13
Hi,

Yes it’s local calculated so it works offline, however i would advice to have a NTP server reachable for time sync or a DCF77 time to be sure controller time is correct,

BR,

Erwin
Reply
#14
(24.10.2017, 20:00)Erwin van der Zwart Wrote: Hi,

Yes it’s local calculated so it works offline, however i would advice to have a NTP server reachable for time sync or a DCF77 time to be sure controller time is correct,

BR,

Erwin

How to get that local calculated times in a script? I would like to have the exactly same times as used in the scheduler.
Reply
#15
You have to do this manually, schedulers use their own internal functions which are not available in scripts.
Reply
#16
(25.10.2017, 06:41)admin Wrote: You have to do this manually, schedulers use their own internal functions which are not available in scripts.

Is this exactly the same calculation?

Because if i display the calculated Sunrise and sunset times in my visualisation they must be the same as the sunset and Sunrise in the schedule.
Reply
#17
The algorithm is the same
Reply


Forum Jump: