freakent / node-red-contrib-sunevents

A node for node-red that generates events based on the position of the Sun at the appropriate time of day.
Apache License 2.0
15 stars 13 forks source link

Message Payload is Always "calculating sunevents for..." #28

Closed BillyFKidney closed 3 years ago

BillyFKidney commented 3 years ago

I've attempted to use my own inject node with the proper LAT / LONG payload and the example code.

The debug console shows the following output:

image

I've not been able to use SunEvents v3.0 due to this bug. SunEvents v2.x worked flawlessly

image image
freakent commented 3 years ago

Hi Billy, what seems to be the issue? From the screen shot it looks like it is working as it should. What's the bug?

BillyFKidney commented 3 years ago

Hi Billy, what seems to be the issue? From the screen shot it looks like it is working as it should. What's the bug?

The only response from the node is "calculating" the debug log never shows a sun event.

I never see this:

image
freakent commented 3 years ago

Can you share your flow here? The status is telling you that the next event is goldenhour which will be shortly before dusk. You can always switch on the "make hours seem like minutes" mode to test it quicker.

BillyFKidney commented 3 years ago

Can you share your flow here? The status is telling you that the next event is goldenhour which will be shortly before dusk. You can always switch on the "make hours seem like minutes" mode to test it quicker.

I imported your code from GitHub....no modifications at all.

[{"id":"32cb8da3.eeffc2","type":"tab","label":"Sun Events simple example","disabled":false,"info":""},{"id":"2d8758dc.922e08","type":"inject","z":"32cb8da3.eeffc2","name":"","props":[{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payloadType":"str","x":110,"y":120,"wires":[["58c171f7.59b7a"]]},{"id":"f10b6e96.34bbf","type":"debug","z":"32cb8da3.eeffc2","name":"Your logic goes here","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":800,"y":180,"wires":[]},{"id":"ae9be1e3.2e7ab","type":"sun events","z":"32cb8da3.eeffc2","testmode":true,"verbose":true,"topic":"","name":"","x":590,"y":180,"wires":[["f10b6e96.34bbf"]]},{"id":"58c171f7.59b7a","type":"change","z":"32cb8da3.eeffc2","name":"set GPS coordinates (change node) ","rules":[{"t":"set","p":"payload.latitude","pt":"msg","to":"51.501364","tot":"num"},{"t":"set","p":"payload.longitude","pt":"msg","to":"-0.1440787","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":180,"wires":[["ae9be1e3.2e7ab"]]},{"id":"c0aa61b0.223ae","type":"inject","z":"32cb8da3.eeffc2","name":"","props":[{"p":"topic","vt":"str"}],"repeat":"","crontab":"00 12 * * *","once":false,"onceDelay":0.1,"topic":"","payloadType":"str","x":110,"y":240,"wires":[["58c171f7.59b7a"]]},{"id":"8a69281b.9d7da8","type":"comment","z":"32cb8da3.eeffc2","name":"Sun Events simple example","info":"# Inject node(s)\nThere are two inject nodes in this example, one to initialise sun-events on flow deployment and the other to refresh the Sun-events at a fixed time each day.\n\n# Change node\nYou could just set the latitude and longitude in the msg.payload in an inject node, but since we are using two inject nodes in this example, the change node is used to set the payload from both.\n\n# Sun Events node\nThe Sun-events node will output a series of Sun events msg at the appropriate time of day.\n\n# Debug node\nThe debug node is just here to output the contents of the payload in the debug window, you could obviously replace that with what ever logic you need for your use case. ","x":450,"y":100,"wires":[]}]

I've deployed and tried clicking either inject node

image
BillyFKidney commented 3 years ago

I left the window open and after three minutes the debug node posted:

image

Is it normal to take that long to calculate the SunEvents? My CPU never showed a spike

Synology DiskStation DS1019+ 16GB DDR3L; only VM running is HA

image
freakent commented 3 years ago

It is working as it has always worked. Once a day it should calculate the next 24 hour's events, then at the appropriate time the node outputs an event telling you which event has just occurred. That is how v2.0 worked too.

freakent commented 3 years ago

Only difference is that in v2 it used to output a debug message list all the upcoming events it will emit. Now that we have status message under the node it didn't seem necessary to output an even bigger debug message.

BillyFKidney commented 3 years ago

It is working as it has always worked. Once a day it should calculate the next 24 hour's events, then at the appropriate time the node outputs an event telling you which event has just occurred. That is how v2.0 worked too.

When using V2 it didn't take 3 minutes to calculate the sun events. I wasn't patient enough to realize that was the problem. Any ideas as to why it takes 3 minutes from the injection of the LAT/LONG to getting the next event?

freakent commented 3 years ago

Billy

When using V2 it didn't take 3 minutes to calculate the sun events.

I assure you it’s not taking 3 minutes to calculate. Look at the green light under the node that says the name of the next event to fire. As soon as you see that you know that the next event is ready to fire. I wasn't patient enough to realize that was the problem. Any ideas as to why it takes 3 minutes from the injection of the LAT/LONG to getting the next event?

Let me give you an example based on sunset. If you invoke the node at 12 noon, it will calculate the next 24 hours worth of events and sets up timers for each. At the appropriate time, the sunset timer will will fire. So at sunset I.e 7 or 8 hours after noon (depending on the GPS coordinates you injected) the sunset event will be emitted from the node. The reason your sample is taking 3 minutes is because you are running in test mode. It should be taking 3 hours in normal mode. This behaviour is exactly what this node was designed to do from day 1.

Regards, Martin

On 11 May 2021, at 18:02, Billy @.***> wrote:

 It is working as it has always worked. Once a day it should calculate the next 24 hour's events, then at the appropriate time the node outputs an event telling you which event has just occurred. That is how v2.0 worked too.

When using V2 it didn't take 3 minutes to calculate the sun events. I wasn't patient enough to realize that was the problem. Any ideas as to why it takes 3 minutes from the injection of the LAT/LONG to getting the next event?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

[ { @.": "http://schema.org", @.": "EmailMessage", "potentialAction": { @.": "ViewAction", "target": "https://github.com/freakent/node-red-contrib-sunevents/issues/28#issuecomment-838834280", "url": "https://github.com/freakent/node-red-contrib-sunevents/issues/28#issuecomment-838834280", "name": "View Issue" }, "description": "View this Issue on GitHub", "publisher": { @.": "Organization", "name": "GitHub", "url": "https://github.com" } } ]

BillyFKidney commented 3 years ago

Odd, I'll rebuild some automations and try again tonight.

moshed commented 2 years ago

I came across this because i was expecting the same behavior @BillyFKidney was expecting. would it be possible to add the feature of manually sending the next 24 hours of sun events? I would like to be able to set an offset ie do x 20 minutes before sunset. and need to be able to manually store the sun event times

freakent commented 2 years ago

This module is only designed to take sunevents from the SunCalc library and output events at the appropriate time. If you want a list of events use a function node and a few simples lines of Jvaascript.

let suncalc = global.get('suncalc')   // See https://nodered.org/docs/user-guide/writing-functions#loading-additional-modules
let times = suncalc.getTimes(new Date(), 51.5, -0.1)  // Set the Date, Latitude and Longitude values appropriate to your use case
msg.payload = new Date(times.sunset.getTime() - (20 * 60 * 1000))   // returns Sunset minus 20 mins
return msg;

Sample flow with Function Node. [{"id":"1fa9e797.6867b8","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"1c289d4f.ab9033","type":"inject","z":"1fa9e797.6867b8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":110,"y":100,"wires":[["656973bb.e129dc"]]},{"id":"656973bb.e129dc","type":"function","z":"1fa9e797.6867b8","name":"","func":"let suncalc = global.get('suncalc')\nlet times = suncalc.getTimes(new Date(), 51.5, -0.1)\nmsg.payload = new Date(times.sunset.getTime() - (20 60 1000))\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":300,"y":100,"wires":[["3067af5.8c4af5"]]},{"id":"3067af5.8c4af5","type":"debug","z":"1fa9e797.6867b8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":500,"y":120,"wires":[]}]

moshed commented 2 years ago

wouldn't I need to set the context with global.get first? right now that flow returns nothing because i have nothing stored.

freakent commented 2 years ago

Read the documentation on loading external modules. https://nodered.org/docs/user-guide/writing-functions#loading-additional-modules

On 12 Jul 2021, at 04:21, moshed @.***> wrote:

 wouldn't I need to set the context with global.get first? right now that flow returns nothing because i have nothing stored.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

[ { @.": "http://schema.org", @.": "EmailMessage", "potentialAction": { @.": "ViewAction", "target": "https://github.com/freakent/node-red-contrib-sunevents/issues/28#issuecomment-877939371", "url": "https://github.com/freakent/node-red-contrib-sunevents/issues/28#issuecomment-877939371", "name": "View Issue" }, "description": "View this Issue on GitHub", "publisher": { @.": "Organization", "name": "GitHub", "url": "https://github.com" } } ]

moshed commented 2 years ago

wow! didnt know that. super useful!

thanks so much I will check it out. node-red keeps getting better and better

moshed commented 2 years ago

works great! thanks @freakent

BillyFKidney commented 1 year ago

Read the documentation on loading external modules. https://nodered.org/docs/user-guide/writing-functions#loading-additional-modules On 12 Jul 2021, at 04:21, moshed @.> wrote:  wouldn't I need to set the context with global.get first? right now that flow returns nothing because i have nothing stored. — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe. [ { @.": "http://schema.org", @.": "EmailMessage", "potentialAction": { @.": "ViewAction", "target": "#28 (comment)", "url": "#28 (comment)", "name": "View Issue" }, "description": "View this Issue on GitHub", "publisher": { @.***": "Organization", "name": "GitHub", "url": "https://github.com" } } ]

Please excuse my ignorance here, but I'm still experiencing issues after referencing the external module:

image image image