maros / Zway-Astronomy

Zway automation module for astronomy calculations
2 stars 0 forks source link

Setting local timezone breaks the module. #3

Closed zymurgybc closed 8 years ago

zymurgybc commented 8 years ago

I have two Raspberry Pi's running a zway server and Home Assistant and a PC with mqtt, and found when I rebuilt my zway recently, the astronomy module is giving me weird numbers. I know from my old zway and HomeAssistant installs that as the sun passes +10° in altitude is a good time to start switching lights. Recently the zway was showing me a negative altitude and falling in the morning. As I am on the west coast of Canada (GMT-8), that would make sense if my calculation was from 9am GMT and my local time was only 1am. I dealt with a similar issue getting HomeAssistant and my Mqtt servers to agree found the problem was timezones and used pyTZ to fix it. To check, I altered the index.js, about line 113, where you assign "now" and get better values. Not sure this is the ideal fix, but seems simple.

var now = new Date().getUTCDate();

maros commented 8 years ago

Afaict the calculation works correctly. I live in a timezone which currently is GMT+2 and the values displayed are OK for my location. Please check if the outputs of

http://YOURZWAYIP:8083/ZAutomation/api/v1/system/time/get and ssh pi@YOURZWAYIP date # on the console

are correct and display your current timezone and time. The fix you suggested just returns the current day of month - i doubt that this works!?

zymurgybc commented 8 years ago

Yes, I don't think my fix is working; at the time I tried it, it seemed more right than without, but it results in a constant altitude which is a worse problem. I reverted my local change an hour or so ago.

I checked both the API and console and they are both showing the correct local timezone information, but zway is back to reporting an altitude of -16° and increasingly negative as the sun rises above my horizon.

That seems wrong, to me. Unless I'm just bonkers, but it was working nicely before when my lights could turn off after sunrise.

Thanks for the response; I do appreciate the check, even when my suggestion was flawed. :-)

Ted On Jul 12, 2016 10:37 PM, "Maroš Kollár" notifications@github.com wrote:

Afaict the calculation works correctly. I live in a timezone which currently is GMT+2 and the values displayed are correct for my location (and not GMT+0). Please check if the outputs of

http://YOURZWAYIP:8083/ZAutomation/api/v1/system/time/get and ssh pi@YOURZWAYIP date # on the console

are correct and display the correct timezone and time. The fix you suggested just returns the current day of month - i doubt that this works!?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/maros/Zway-Astronomy/issues/3#issuecomment-232261112, or mute the thread https://github.com/notifications/unsubscribe/AA_Plgj62tzZVJ43FobrbqtGJ8GIMGNPks5qVHmngaJpZM4JLAJG .

maros commented 8 years ago

Please run the following code in your nodejs repl on the commandline (line by line) and report back the output.

suncalc = require("/opt/z-way-server/automation/userModules/Astronomy/suncalc.js");
date = new Date();
suncalc.getPosition(new Date(),48.1,16.3); // Replace with your lat and lng
zymurgybc commented 8 years ago

pi@razberry:~ $ nodejs --version v0.10.29 pi@razberry:~ $ npm --version 1.4.21

suncalc = require("/opt/z-way-server/automation/userModules/Astronomy/suncalc.js"); { getPosition: [Function], times: [ [ -0.833, 'sunrise', 'sunset' ], [ -0.3, 'sunriseEnd', 'sunsetStart' ], [ -6, 'dawn', 'dusk' ], [ -12, 'nauticalDawn', 'nauticalDusk' ], [ -18, 'nightEnd', 'night' ], [ 6, 'goldenHourEnd', 'goldenHour' ] ], addTime: [Function], getTimes: [Function], getMoonPosition: [Function], getMoonIllumination: [Function], getMoonTimes: [Function] } date = new Date(); Wed Jul 13 2016 20:43:38 GMT-0700 (PDT) suncalc.getPosition(new Date(),48.4284,123.3656); // Replace with your lat and lng { azimuth: -0.08439119577763561, altitude: 1.1025270180741202 }

Currently the sun is above my horizon, but setting, as I could still see lit walls outside.

http://www.sunearthtools.com/dp/tools/pos_sun.php tells me sunset is in the next few minutes.

SunRise: 05:27:27 * 55.21° | SunSet: 21:10:55 * 304.61°

On Wed, Jul 13, 2016 at 12:05 PM, Maroš Kollár notifications@github.com wrote:

Please run the following code in your nodejs repl on the commandline (line by line) and report back the output.

suncalc = require("/opt/z-way-server/automation/userModules/Astronomy/suncalc.js"); date = new Date(); suncalc.getPosition(new Date(),48.1,16.3); // Replace with your lat and lng

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/maros/Zway-Astronomy/issues/3#issuecomment-232454987, or mute the thread https://github.com/notifications/unsubscribe/AA_PlufqfrDHAL9hD4hAkeiGeyuo-619ks5qVTblgaJpZM4JLAJG .

zymurgybc commented 8 years ago

I may have found the user error :-( the 123 degrees is west of GMT, so it should be negative... the positive would put me about 8 or 16 hours off my local expectations depending on direction. I'll see how that does in the AM.

Ted

On Wed, Jul 13, 2016 at 8:59 PM, Ted Heatherington zymurgy.bc@gmail.com wrote:

pi@razberry:~ $ nodejs --version v0.10.29 pi@razberry:~ $ npm --version 1.4.21

suncalc = require("/opt/z-way-server/automation/userModules/Astronomy/suncalc.js"); { getPosition: [Function], times: [ [ -0.833, 'sunrise', 'sunset' ], [ -0.3, 'sunriseEnd', 'sunsetStart' ], [ -6, 'dawn', 'dusk' ], [ -12, 'nauticalDawn', 'nauticalDusk' ], [ -18, 'nightEnd', 'night' ], [ 6, 'goldenHourEnd', 'goldenHour' ] ], addTime: [Function], getTimes: [Function], getMoonPosition: [Function], getMoonIllumination: [Function], getMoonTimes: [Function] } date = new Date(); Wed Jul 13 2016 20:43:38 GMT-0700 (PDT) suncalc.getPosition(new Date(),48.4284,123.3656); // Replace with your lat and lng { azimuth: -0.08439119577763561, altitude: 1.1025270180741202 }

Currently the sun is above my horizon, but setting, as I could still see lit walls outside.

http://www.sunearthtools.com/dp/tools/pos_sun.php tells me sunset is in the next few minutes.

SunRise: 05:27:27 * 55.21° | SunSet: 21:10:55 * 304.61°

On Wed, Jul 13, 2016 at 12:05 PM, Maroš Kollár notifications@github.com wrote:

Please run the following code in your nodejs repl on the commandline (line by line) and report back the output.

suncalc = require("/opt/z-way-server/automation/userModules/Astronomy/suncalc.js"); date = new Date(); suncalc.getPosition(new Date(),48.1,16.3); // Replace with your lat and lng

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/maros/Zway-Astronomy/issues/3#issuecomment-232454987, or mute the thread https://github.com/notifications/unsubscribe/AA_PlufqfrDHAL9hD4hAkeiGeyuo-619ks5qVTblgaJpZM4JLAJG .