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.

sunrise and sunset values
#1
Hi
Can I see sunrise and sunset times for today (in local time)? In some value, group object or as a result of a function?

Thank you
LM5Lp, firmware: 2018.08.22 and 2021.12.15, FlashSYS v2, ARMv7 Processor rev 5 (v7l), kernel 4.4.151 and 4.4.259
Reply
#2
You can use rscalc function from common functions to get sunrise and sunset time in minutes. Then you can convert it to text (or use a day/time object instead):
Code:
latitude = 11.11
longitude = 22.22
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

sunrise_text = string.format('%02d:%02d', sunrise_hour, sunrise_minute)
sunset_text = string.format('%02d:%02d', sunset_hour, sunset_minute)
Reply
#3
Hi
Thank you for your reply but the first two rows are the problem. I don't want two separated stores for geo coordinates. I set these values in the system date/time dialogue. Can I at least read it from here?

The best solution would be if the system took these values from KNX objects provided by my meteo station.
LM5Lp, firmware: 2018.08.22 and 2021.12.15, FlashSYS v2, ARMv7 Processor rev 5 (v7l), kernel 4.4.151 and 4.4.259
Reply
#4
See this post: https://forum.logicmachine.net/showthread.php?tid=997
Reply
#5
Thank you it works.
LM5Lp, firmware: 2018.08.22 and 2021.12.15, FlashSYS v2, ARMv7 Processor rev 5 (v7l), kernel 4.4.151 and 4.4.259
Reply
#6
(22.09.2017, 10:24)admin Wrote: You can use rscalc function from common functions to get sunrise and sunset time in minutes. Then you can convert it to text (or use a day/time object instead):
Code:
latitude = 11.11
longitude = 22.22
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

sunrise_text = string.format('%02d:%02d', sunrise_hour, sunrise_minute)
sunset_text = string.format('%02d:%02d', sunset_hour, sunset_minute)


I've checked this script and probably is something wrong. E.g. for Lublin, PL google maps link:
https://www.google.pl/maps/place/Lublin/...4463?hl=pl

Based on this link I've filled the lat and lng:
Code:
lat = 22.4937308
lng = 51.2181956

sunrise, sunset = rscalc(lat, lng)

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

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

sunrise_text = string.format('%02d:%02d', sunrise_hour, sunrise_minute)
sunset_text = string.format('%02d:%02d', sunset_hour, sunset_minute)
log(sunrise_text, sunset_text)

The result is wrong:
Code:
* arg: 1
 * string: 04:01
* arg: 2
 * string: 15:35

It should be round about 6:23 for sunrise and 17:03 for sunset.
Reply
#7
Does your LM have correct date, time and timezone set?
Reply
#8
(25.02.2018, 10:49)admin Wrote: Does your LM have correct date, time and timezone set?

I think yes. Please see into attached screenshot. I've tested this also with minus values.

Attached Files Thumbnail(s)
   
Reply
#9
Well, LAT = 22.4937308 LNG = 51.2181956 is somewhere in Saudi Arabia Smile You have them in reverse.
Reply
#10
But why google API has such address? See below link:

Code:
https://www.google.pl/maps/place/Lublin/@51.2181956,22.4937308,12z/data=!3m1!4b1!4m5!3m4!1s0x472257141e154061:0x5528ee7af6e8e95f!8m2!3d51.2464536!4d22.5684463?hl=pl


I've checked with also -22 and also not right.

See what I've found in User guide for Spacelynk and what I've found on Google Maps for Lublin. And also on page latlong.net

Attached Files Thumbnail(s)
           
Done is better than perfect
Reply
#11
In the script you posted you have:
Code:
lat = 22.4937308
lng = 51.2181956

Which in fact should be:
Code:
lat = 51.2181956
lng = 22.4937308

With these values today's sunrise/sunset is at 06:20/17:06
Reply
#12
RightWink

I had no problem in my suncalculation script because I had there appriopriate order. But what about positive and negative values? In above screenshot from google there is no sign but should be. Can you maybe add some info about this into your manual?

But if it is about these values I've checked the trend from twilight sensor and 0lux is at 5:50 and 17:50. If it is about sun elevation 0° is at 6:40 and 17:05. What is the goal of this sunset sunrise script? Checking if elevation == 0° or other value?
Done is better than perfect
Reply
#13
There are several types of sunrise/sunset, rscalc gives values when sun is at 0°.
Why do you think there should be a sign in coordinates for a location in Poland? It is above equator and east of Greenwich, so both latitude and longitude are positive numbers.
Reply
#14
Because when I've started to deal with this subject I was using this site(Berlin is also on the East side):
https://www.esrl.noaa.gov/gmd/grad/solcalc/azel.html

and also I remeber that this can be different, so it is good when it is clearly specified in the manual.

Attached Files Thumbnail(s)
   
Done is better than perfect
Reply
#15
Big Grin That's because it a US website. They also have time zone offsets in reverse, Berlin should be UTC +1. Their interpretation of longitude is incorrect and misleading.
Reply
#16
I know such situation like A B and + - in RS-485Wink But google is also US company and NOAA is some governmental departure so sounds very professionalWink Good to know how it is on LM. Thanks AdminWink
Done is better than perfect
Reply
#17
Hi,

Can someone help me, please!
How can I compare (in a if / elseif) the sunrise and sunset results (from Admin's script above) to os.time() to define if it is morning, day ore evening?

Best,
Reply
#18
Code:
latitude = 11.11
longitude = 22.22
sunrise, sunset = rscalc(latitude, longitude)

date = os.date('*t')
now = date.hour * 60 + date.min

-- from 0:00 to sunrise
if now < sunrise then
  alert('before sunrise')
-- from sunset to 23:59
elseif now > sunset then
  alert('after sunset')
else
  alert('day')
end
Reply
#19
(19.03.2018, 07:08)admin Wrote:
Code:
latitude = 11.11
longitude = 22.22
sunrise, sunset = rscalc(latitude, longitude)

date = os.date('*t')
now = date.hour * 60 + date.min

-- from 0:00 to sunrise
if now < sunrise then
 alert('before sunrise')
-- from sunset to 23:59
elseif now > sunset then
 alert('after sunset')
else
 alert('day')
end

Thanks you, Admin!
Reply
#20
(22.09.2017, 10:24)admin Wrote: You can use rscalc function from common functions to get sunrise and sunset time in minutes. Then you can convert it to text (or use a day/time object instead):
Code:
latitude = 11.11
longitude = 22.22
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

sunrise_text = string.format('%02d:%02d', sunrise_hour, sunrise_minute)
sunset_text = string.format('%02d:%02d', sunset_hour, sunset_minute)

Is it possible to get unix time when using rscalc? I'm using the values from the settings (lat, long), but getting 600 as result from sunrise = rascals(latitude).
Reply


Forum Jump: