Wanted to check if was day or night and figured I would use:
local altitude = luup.variable_get(SID.SOLAR, 'ALT', ID.OPEN_LUUP)
If altitude is positive it's day, else it's night. However when I read these variables they are incorrect for my locale. The actual values for sunset and midday are correct but do not occur at sunset or midday. I have checked the clock that openLuup uses and it's correct.
Now the time for midday is one hour out and the time for sunset is 13 hours out.
I checked this by getting the UNIX epoch for my location for both sunset and midday and then adding the hours of offset and then called:
local ID = {
OPEN_LUUP = 2
}
local SID = {
OPEN_LUUP = "openLuup",
SOLAR = "solar"
}
--local localTime = my_epoch_for_midday + (3600*1)
local localTime = my_epoch_for_sunset + (3600*13)
local coords = {Epoch = localTime, '', Latitude = '', Longitude = ''}
luup.call_action(SID.SOLAR, "GetSolarCoords", coords, ID.OPEN_LUUP)
local altitude = luup.variable_get(SID.SOLAR, 'ALT', ID.OPEN_LUUP)
local azimuth = luup.variable_get(SID.SOLAR, 'AZ', ID.OPEN_LUUP)
print('New altitude: '..altitude)
print('New azimuth: '..azimuth)
and I get the right answers.
Not sure what I'm doing wrong. Or perhaps there is some code mix up with UTC versus local time. I checked the documentation but no mention of the solar variables.
If I look at the chart it looks like the whole thing is correct but shifted by my timezone. However I wouldn't expect the timezone to come into play in these calculations.
Feature request: would like to see an openLuup variable that is true for day and false for night. eg IsDay