Use sunset and sunrise time in lua

Moderator: leecollings

Post Reply
salvation
Posts: 38
Joined: Saturday 06 September 2014 15:34
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

Use sunset and sunrise time in lua

Post 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?
User avatar
jvdz
Posts: 2269
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Use sunset and sunrise time in lua

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Whatsek
Posts: 16
Joined: Saturday 31 May 2014 23:48
Target OS: Raspberry Pi / ODroid
Domoticz version: Latest B
Location: Hilversum, The Netherlands
Contact:

Re: Use sunset and sunrise time in lua

Post by Whatsek »

Thank you for this nice example!
salvation
Posts: 38
Joined: Saturday 06 September 2014 15:34
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

Re: Use sunset and sunrise time in lua

Post by salvation »

Tnx jvzd, I already found that option. But that was not what I was looking for, though the results are the same.
marigo
Posts: 30
Joined: Sunday 31 May 2015 11:04
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Netherlands, Veenendaal
Contact:

Re: Use sunset and sunrise time in lua

Post 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?
User avatar
jvdz
Posts: 2269
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Use sunset and sunrise time in lua

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
User avatar
bizziebis
Posts: 182
Joined: Saturday 19 October 2013 14:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8805
Location: The Netherlands
Contact:

Re: Use sunset and sunrise time in lua

Post by bizziebis »

Save it as a Time script, not as a Device script
marigo
Posts: 30
Joined: Sunday 31 May 2015 11:04
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Netherlands, Veenendaal
Contact:

Re: Use sunset and sunrise time in lua

Post 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
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest