mrgadget / node-red-contrib-eztimer

A simple-yet-flexible timer/scheduler for node-red
MIT License
13 stars 6 forks source link

Night End Not Working #57

Closed mstarks01 closed 2 years ago

mstarks01 commented 2 years ago

I'm using the Night End sun event but it never seems to be triggered. I've Googled around and can't find an official definition of Night End, so I'm not sure when it is actually supposed to trigger. I have seen other posts where some areas may not officially have a night, and the fix, but I don't think that applies to my location (Texas). Any insight would be appreciated.

mrgadget commented 2 years ago

You're right, I've seen this elsewhere - but I wouldn't have thought Texas would've been far enough from the equator to not experience night.

From what I can work out (using info from here) night is when the sun is > 18 deg below the horizon (12-18deg is astronomical twilight - the phase on either side of night).

I use a library called SunCalc to fire these events (events are described here). I'd say the best option is to see if night fires - if that doesn't fire either, I'd say you're not entering that phase of the night.

mstarks01 commented 2 years ago

I took a look at the issues tracker for the suncalc library. This seems to be a known issue. It's odd to think that there may not be a "night" in Texas, but perhaps it simply doesn't meet the astronomical definition, or perhaps it's another variable not being taken into account like elevation.

I wonder if it would be possible to work around this by graying out or not displaying those options which would return null. That way your code would still work predictably and one could use offset times for more precise definitions.

It would also be nice to see the actual time returned from the various options to get a sense of when it would trigger, if at all.

mstarks01 commented 2 years ago

A little more info. This site suggests that there is a night in Texas, so maybe it's just a problem with the library.

mrgadget commented 2 years ago

So I tested this and can't reproduce it. Interested to see how you have your GPS co-ordinates set - my test looked like this: image

And resulted in a node that looked like this: image

Ignore the time shown here - that's effectively your Night End represented in my timezone, so a bit whacky.

Is it possible you have your lat/long reversed? That would put you off the bottom of the south pole somewhere, which would certainly confuse SunCalc!

mstarks01 commented 2 years ago

Thanks for testing. I did a bit more myself and found that the Night End is outputting NaN rather than the OFF I was expecting. Is this by design?

mrgadget commented 2 years ago

By outputting, do you mean the payload when the event is triggered? If so, this is entirely set by the payload setting in the node.

If you're getting NaN, I'd suggest you have a data type of number selected, and have OFF typed in the field like this: image If you want to output a string, you need to select the string data type (using the dropdown) - it should look like this: image Let me know if that helps.

mstarks01 commented 2 years ago

You know what? You're right! I suppose NaN is Not a Number. My old man eyes couldn't see the visual difference between the two. Thank you. I appreciate the node and your time looking into this.

mrgadget commented 2 years ago

Great news, I'm just pleased we could solve it. No problem, happy to help, I enjoy troubleshooting! You're correct - NaN is what the Javascript language (and others) returns when you try and jam non-numeric data into an integer.

Also, having issues laying around like this one helps other people who might run into the same issue - so always pays to reach out.

Cheers.