Page 1 of 1

Use sunset and sunrise time in lua

Posted: Sunday 25 October 2015 7:58
by salvation
Hi,

I was wondering how I could use the sunset and sunrise time in LUA? I've found the timeofday variable daytime, nighttime and sunsetinminutes. But I'm looking to use the time. Just like the option in blocky or the time returned in the json call /json.htm?type=command&param=getSunRiseSet

Code: Select all

{
   "ServerTime" : "Sep 30 2013 17:15:21",
   "Sunrise" : "07:38:00",
   "Sunset" : "19:16:00",
   "status" : "OK",
   "title" : "getSunRiseSet"
}
Anybody know how to achieve this?

Re: Use sunset and sunrise time in lua

Posted: Sunday 25 October 2015 10:03
by jvdz
This is an example which will run at sunset - 10 minutes:

Code: Select all

commandArray = {}
	-- get current time
	timenow = os.date("*t")
	minutesnow = timenow.min + timenow.hour * 60
	-- test for sunset - 10 minutes
	if (minutesnow == timeofday['SunsetInMinutes'] - 10) then
		-- do something
	end
return commandArray
Jos

Re: Use sunset and sunrise time in lua

Posted: Tuesday 27 October 2015 19:39
by Whatsek
Thank you for this nice example!

Re: Use sunset and sunrise time in lua

Posted: Sunday 01 November 2015 19:31
by salvation
Tnx jvzd, I already found that option. But that was not what I was looking for, though the results are the same.

Re: Use sunset and sunrise time in lua

Posted: Friday 02 September 2016 21:43
by marigo
jvdz wrote:This is an example which will run at sunset - 10 minutes:

Code: Select all

commandArray = {}
	-- get current time
	timenow = os.date("*t")
	minutesnow = timenow.min + timenow.hour * 60
	-- test for sunset - 10 minutes
	if (minutesnow == timeofday['SunsetInMinutes'] - 10) then
		-- do something
	end
return commandArray
Jos
If I use this lua script and send an e-mail when it's 10 minutes to sunset then I will get 8 e-mails

Code: Select all

commandArray['SendEmail']='Sunset-test#Het is 10 minuten voor zonsondergang#[email protected]'
What am I doing wrong?

Re: Use sunset and sunrise time in lua

Posted: Friday 02 September 2016 22:24
by jvdz
How is the script ran?
Is in an script in the internal editor and did you change the dropdownbox below LUA to Time?

Jos

Re: Use sunset and sunrise time in lua

Posted: Friday 02 September 2016 22:25
by bizziebis
Save it as a Time script, not as a Device script

Re: Use sunset and sunrise time in lua

Posted: Sunday 04 September 2016 16:09
by marigo
Hmmm, I think that's were I went wrong. I have changed the script name from "device" to "time".
In about a few hours I can update this tread and let you know if it worked. :)

EDIT: it works perfect now! Thank you all for the replies.

script name: script_time_sunset-test.lua

Code: Select all

commandArray = {}
   -- get current time
   timenow = os.date("*t")
   minutesnow = timenow.min + timenow.hour * 60
   -- test for sunset - 10 minutes
   if (minutesnow == timeofday['SunsetInMinutes'] - 10) then
      commandArray['SendEmail']='Sunset-test#Het is 10 minuten voor zonsondergang#[email protected]'
   end
return commandArray