Page 1 of 1

timeofday has same values - everytime

Posted: Tuesday 20 June 2017 22:08
by Domoberry
Hi Forum,

Probably a stupid question, but since I cannot figure it out...

I'm using:

Code: Select all

print("Sunset in minutes = " .. timeofday['SunsetInMinutes'])
and this always returns:
2017-06-20 21:56:07.977 LUA: Sunset in minutes = 1317

regardless of the time of the day; it is always 1317
I printed the table contents using some table-print function, which always gives:
{
SunriseInMinutes= 321,
SunsetInMinutes= 1317,
Daytime= "true",
Nighttime= "false",
}


Also checked the time on my RPI:
pi@raspberrypi:~ $ date
Tue Jun 20 22:02:33 CEST 2017
which seems to be OK

As well as the time in Domoticz:
2017-06-20 22:03:23 ☀▲05:21 ▼21:57

There must be something obvious I overlooked. Any tip for me?

Re: timeofday has same values - everytime

Posted: Tuesday 20 June 2017 22:13
by jvdz
Domoberry wrote:Hi Forum,
regardless of the time of the day; it is always 1317
Why are you expecting the time the SunSets to change during the day? ;)
What exactly are you looking for here or what do you want to test for?

Jos

Re: timeofday has same values - everytime

Posted: Tuesday 20 June 2017 22:28
by Domoberry
I new I missed something...

I wrongly assumed that 'TimeOfDay['SunsetInMinutes'] would be a nifty little table telling me when to expect for example sunset, e.g. 'sunset will be in xxx minutes' :oops:

1321 minutes equals to 21 hours and 57 which... is when... the sun sets. My bad.

(what I was trying to do was to find a simple way to do something like 'the light should be off between xx:xx and yy:yy and behave as per the rest of the script on other times. So started looking for the various time-related functions and thought I give the hint in the lua Domoticz template a try)

To avoid me misusing the forum again - and make this post still somewhat useful - which 'reference manual' is the best for the Domoticz-Lua newbee?

Re: timeofday has same values - everytime

Posted: Wednesday 21 June 2017 18:22
by jvdz
So you still can have lights behave taking that value into account and simply calculate with the current time.
I use something like this in a script to act on times around sunset:

Code: Select all

timenow = os.date("*t")
minutesnow = timenow.min + timenow.hour * 60
if minutesnow >= timeofday['SunsetInMinutes'] + 10
and minutesnow < timeofday['SunsetInMinutes'] then
	-- do something between sunset and 10 minutes after 
end
Jos

Re: timeofday has same values - everytime

Posted: Thursday 22 June 2017 21:29
by Domoberry
Hi Jos,

Thanks for the suggestion, I like the use of timenow = os.date("*t") and the resulting table! Makes things easier!
Got the time based thingy to work and... gathered new knowledge on the way.
Thanks, W.ytze