We have moved at community.getvera.com

Author Topic: Any help regarding time period scripting  (Read 666 times)

Offline sre

  • Full Member
  • ***
  • Posts: 110
  • Karma: +0/-1
Any help regarding time period scripting
« on: December 26, 2015, 01:15:14 pm »
Hi,

I had the program as per below.  I took the script mostly off from here but valur of my 'mEnd' variable is totally an unexpected figure.  I was expecting 15 minutes past sunrise.  What am I doing wrong ?  any help ?

Quote

LuaTest 1.6

Lua file: /etc/cmh-ludl/luatest.lua

Results
No errors
Runtime: 1.0 ms
Code returned: false

Print output
Timezone: -5 hours     
City: Orleans     
Latitude: 45.467     
Longitude: -75.517     
Sunrise: Sun Dec 27 07:41:13 2015     
Sunset: Sat Dec 26 16:24:17 2015     
mEnd:776     
mNow: 790     
mStart: 15     

Code
   1   local pStart = "00:15"   -- Start of time period
   2   local pEndOffset = 15           -- End of time period, minutes offset from sunrise
   3   local allow = true       -- true runs scene during period, false blocks it
   4   local hS, mS = string.match(pStart,"(%d+)%:(%d+)")
   5   local mStart = (hS * 60) + mS
   6   local mEnd = math.floor( (luup.sunrise() % 86400) / 60 ) + pEndOffset
   7   local tNow = os.date("*t")
   8   local mNow = (tNow.hour * 60) + tNow.min
   9   
  10   print("Timezone: " .. luup.timezone .. " hours")
  11   print("City: " .. luup.city)
  12   print("Latitude: " .. luup.latitude)
  13   print("Longitude: " .. luup.longitude)
  14   local srtime = os.date("%c",luup.sunrise())
  15   print("Sunrise: " .. srtime)
  16   local sstime = os.date("%c",luup.sunset())
  17   print("Sunset: " .. sstime)
  18   
  19   print ("mEnd:" .. mEnd)
  20   print ("mNow: " .. mNow)
  21   print ("mStart: " .. mStart)
  22   
  23   if ((mNow >= mStart) and (mNow <= mEnd)) then
  24        return true
  25   else 
  26        return false
  27   end
  28   
  29   

unquote