timeofday has same values - everytime

Moderator: leecollings

Post Reply
User avatar
Domoberry
Posts: 121
Joined: Tuesday 30 May 2017 19:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.7
Contact:

timeofday has same values - everytime

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

Re: timeofday has same values - everytime

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
User avatar
Domoberry
Posts: 121
Joined: Tuesday 30 May 2017 19:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.7
Contact:

Re: timeofday has same values - everytime

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

Re: timeofday has same values - everytime

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
User avatar
Domoberry
Posts: 121
Joined: Tuesday 30 May 2017 19:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.7
Contact:

Re: timeofday has same values - everytime

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

Who is online

Users browsing this forum: No registered users and 1 guest