Logic Machine Forum
sunrise and sunset values - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: General (https://forum.logicmachine.net/forumdisplay.php?fid=2)
+--- Thread: sunrise and sunset values (/showthread.php?tid=1010)

Pages: 1 2


sunrise and sunset values - Thomas - 22.09.2017

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


RE: sunrise and sunset values - admin - 22.09.2017

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)



RE: sunrise and sunset values - Thomas - 25.09.2017

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.


RE: sunrise and sunset values - admin - 25.09.2017

See this post: https://forum.logicmachine.net/showthread.php?tid=997


RE: sunrise and sunset values - Thomas - 04.10.2017

Thank you it works.


RE: sunrise and sunset values - buuuudzik - 25.02.2018

(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/@51.2181956,22.4937308,12z/data=!3m1!4b1!4m5!3m4!1s0x472257141e154061:0x5528ee7af6e8e95f!8m2!3d51.2464536!4d22.5684463?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.


RE: sunrise and sunset values - admin - 25.02.2018

Does your LM have correct date, time and timezone set?


RE: sunrise and sunset values - buuuudzik - 25.02.2018

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


RE: sunrise and sunset values - admin - 26.02.2018

Well, LAT = 22.4937308 LNG = 51.2181956 is somewhere in Saudi Arabia Smile You have them in reverse.


RE: sunrise and sunset values - buuuudzik - 26.02.2018

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


RE: sunrise and sunset values - admin - 26.02.2018

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


RE: sunrise and sunset values - buuuudzik - 26.02.2018

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?


RE: sunrise and sunset values - admin - 27.02.2018

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.


RE: sunrise and sunset values - buuuudzik - 27.02.2018

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.


RE: sunrise and sunset values - admin - 27.02.2018

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.


RE: sunrise and sunset values - buuuudzik - 27.02.2018

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


RE: sunrise and sunset values - Mrinj - 18.03.2018

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,


RE: sunrise and sunset values - admin - 19.03.2018

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



RE: sunrise and sunset values - Mrinj - 19.03.2018

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


RE: sunrise and sunset values - FatMax - 14.12.2018

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