Logic Machine Forum
3 byte date/time - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: 3 byte date/time (/showthread.php?tid=1023)



3 byte date/time - gjniewenhuijse - 04.10.2017

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

sunrise, sunset = rscalc(latitude, longitude)


RE: 3 byte date/time - Erwin van der Zwart - 04.10.2017

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


RE: 3 byte date/time - gjniewenhuijse - 04.10.2017

(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


RE: 3 byte date/time - Mrinj - 23.10.2017

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


RE: 3 byte date/time - Erwin van der Zwart - 23.10.2017

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


RE: 3 byte date/time - Mrinj - 23.10.2017

Thanks Erwin!
Sett up the schedule. Will see how it works on sunrise Smile


RE: 3 byte date/time - gjniewenhuijse - 24.10.2017

(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?


RE: 3 byte date/time - admin - 24.10.2017

Yes, but if you're using rscalc function in scripts then you still have to pass coordinates manually.


RE: 3 byte date/time - gjniewenhuijse - 24.10.2017

(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?


RE: 3 byte date/time - Erwin van der Zwart - 24.10.2017

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/showthread.php?tid=997&pid=5818#pid5818


RE: 3 byte date/time - gjniewenhuijse - 24.10.2017

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.


RE: 3 byte date/time - Mrinj - 24.10.2017

Is Sunset / Sunrise schedule going to work if the homelynk is offline or it will only work when the unit is online?


RE: 3 byte date/time - Erwin van der Zwart - 24.10.2017

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


RE: 3 byte date/time - gjniewenhuijse - 25.10.2017

(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.


RE: 3 byte date/time - admin - 25.10.2017

You have to do this manually, schedulers use their own internal functions which are not available in scripts.


RE: 3 byte date/time - gjniewenhuijse - 25.10.2017

(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.


RE: 3 byte date/time - admin - 25.10.2017

The algorithm is the same