I currently have a process that has a random event that turns on a lamp, but I want that lamp only to turn on between sunset & sunrise.
Ideally I would prefer a node that would pass an input to the output between sunrise & sunset, but have not found a single node that has that capability,
I have found the following nodes; cronplus & suncalc.
cronplus seems overly complicated for what I need. Two additional issues, even though I specified my time-zone, at the bottom of the node it displays a time that's not related to anything, and I don't know what the node input does (an inject node does not produce any output).
suncalc appears to function; as it can produce a 0 or 1 output every minute depending on sunrise/sunset, which I could use to set a global var, but I tried accessing it directly from a function-node with the following code:
var suncalc = global.get('suncalc');
node.error(suncalc)
var location = { latitude: 40.392, longitude: -74.1843 };
var times = suncalc.getTimes(new Date(), location.latitude, location.longitude);
var sunrise = times.sunrise.getTime();
var sunset = times.sunset.getTime();
var now = new Date().getTime();
The code returned this error:
function : (error)
"TypeError: Cannot read properties of undefined (reading 'getTimes')";
and node.error(suncalc) returned "" empty for var suncalc.
Any suggestions would be appreciated,
X.