Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

location with TZ Europe/Amsterdam one calculation one hour off #1

Open
westerduin3451 opened this issue Jan 6, 2022 · 16 comments
Open

Comments

@westerduin3451
Copy link

Hi Mat,

thanks for your work, it helps me a lot with my home automation.

At the moment I am struggling with your project "Tracking daylight in NodeRED".

My setup is Home Assistant (Hassio) with the node-red add-on.
When I entre my coordinates and enable timezone the daylight tracker calculation of day and night is one hour off?

SunSet/SunRise info:
{"sunrise":"2022-01-06T08:45:03.000Z"
,"noon":"2022-01-06T12:45:45.000Z"
,"sunset":"2022-01-06T16:46:27.000Z",
"day_lenght":{"in_sec":28884,"in_hhmmss":"08h 01min"}
,"civil_twiligh_start":"2022-01-06T08:07:00.000Z"
,"civil_twiligh_stop":"2022-01-06T17:24:30.000Z"
,"nautical_twilight_start":"2022-01-06T07:23:44.000Z"
,"nautical_twilight_stop":"2022-01-06T18:07:46.000Z"
,"astronomical_twilight_start":"2022-01-06T06:42:44.000Z"
,"astronomical_twilight_stop":"2022-01-06T18:48:47.000Z"
,"timezone":60}

This information seems right/ok.
But the daylight tracker is one hour off / late?.

Did I do something wrong?
Do you have any suggestions, on how I can fix this?

Thanks in advance.
Regards Johan

@notenoughtech
Copy link
Owner

notenoughtech commented Jan 6, 2022 via email

@westerduin3451
Copy link
Author

Hi Mat,

thanks for the quick response.
My timezone = Europe/Amsterdam
How and where do I change 60 into 0?
Will this still work with daylight saving?

@notenoughtech
Copy link
Owner

Hi Johan,

In the setting node (On Start) you should have the timezone = true value which uses your local computer zone to calculate the offset including the current daylight setting. Can you give me your coords you are working with, and what is the result reporting for today's sunset vs what you would expect to see?

@westerduin3451
Copy link
Author

Hi Mat,

The date and time of the Pi I am running shows correct date and time
and the current settings in On Start are as follows

var latitude = "52.10743999864968";
var longitude = "5.011243974118552";
var timezone = true; //set true to use local timezone offset, set false to get values in UTC without daylight saving

flow.set("timezone", timezone);
global.set("longitude", longitude);
global.set("latitude", latitude);

@notenoughtech
Copy link
Owner

Both values in the tracker report the time in seconds

node.warn(timeNow);
node.warn(new Date(sunset).getTime())

You can use these to get the live output but looking at the payloads in debug - all seems to be fine - the most you should get is a delay of 1 min caused by the interval update

@westerduin3451
Copy link
Author

Hmm
node.warn(new Date(sunset).getTime())
reports the same time over and over?

06/01/2022, 11:59:21node: Is it night time yet?
function : (warn)
1641466761578
06/01/2022, 11:59:21node: Is it night time yet?
function : (warn)
1641487587000
06/01/2022, 11:59:21node: 819883bf552b1c33
msg.payload : string[41]
"According to my calculations it's daytime"
06/01/2022, 11:59:22node: Is it night time yet?
function : (warn)
1641466762485
06/01/2022, 11:59:22node: Is it night time yet?
function : (warn)
1641487587000
06/01/2022, 11:59:22node: 819883bf552b1c33
msg.payload : string[41]
"According to my calculations it's daytime"

@westerduin3451
Copy link
Author

code of "is it night time yet?"

var time = global.get("Time");

var sunrise = time.sunrise;
var sunset = time.sunset;

var now = new Date();
var timeNow = now.getTime();

//from sunrise to sunset
if(timeNow >= new Date(sunrise).getTime() && timeNow <= new Date(sunset).getTime()){
msg.payload = "According to my calculations it's daytime";
global.set("time_of_Day", "day");
}

//from sunset to sunrise
if(timeNow > new Date(sunset).getTime() || timeNow < new Date(sunrise).getTime()){
msg.payload = "According to my calculations it's nighttime";
global.set("time_of_Day", "night");
}

node.warn(timeNow);
node.warn(new Date(sunset).getTime())

return msg;

@notenoughtech
Copy link
Owner

The debug values will show you current (in this case) time and sunrise time - obviously sunrise time will be the same for 24h period

@westerduin3451
Copy link
Author

Sorry Mat,
I have no idea what I was thinking silly of me ;-)

@notenoughtech
Copy link
Owner

notenoughtech commented Jan 6, 2022 via email

@westerduin3451
Copy link
Author

OK it's 17:02 and it's still daytime, should it not be night time?

06/01/2022, 17:02:20node: 819883bf552b1c33
msg.payload : string[41]
"According to my calculations it's daytime"
06/01/2022, 17:02:46node: 0de22e8d93416a14
msg.payload : Object
object
sunrise: "2022-01-06T08:45:03.000Z"
noon: "2022-01-06T12:45:45.000Z"
sunset: "2022-01-06T16:46:27.000Z"
day_lenght: object
civil_twiligh_start: "2022-01-06T08:07:00.000Z"
civil_twiligh_stop: "2022-01-06T17:24:30.000Z"
nautical_twilight_start: "2022-01-06T07:23:44.000Z"
nautical_twilight_stop: "2022-01-06T18:07:46.000Z"
astronomical_twilight_start: "2022-01-06T06:42:44.000Z"
astronomical_twilight_stop: "2022-01-06T18:48:47.000Z"
timezone: 60

@notenoughtech
Copy link
Owner

notenoughtech commented Jan 6, 2022 via email

@westerduin3451
Copy link
Author

here are the warn msg

node.warn(timeNow);
node.warn(new Date(sunrise).getTime())
node.warn(new Date(sunset).getTime())

06/01/2022, 17:02:09node: 819883bf552b1c33
msg.payload : string[41]
"According to my calculations it's daytime"
06/01/2022, 17:02:20node: Is it night time yet?
function : (warn)
1641484940068
06/01/2022, 17:02:20node: Is it night time yet?
function : (warn)
1641458703000
06/01/2022, 17:02:20node: Is it night time yet?
function : (warn)
1641487587000

@notenoughtech
Copy link
Owner

notenoughtech commented Jan 6, 2022 via email

@westerduin3451
Copy link
Author

Checked the timezone of the pi and it was correct.
Found out that you have to specify a timezone in the config files of node red as well.
Also set timezone On Start to false and it works.

Thanks for your help Mat.

@notenoughtech
Copy link
Owner

notenoughtech commented Jan 9, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants