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 14 forks source link

Sun Event undefined #22

Closed Veldkornet closed 3 years ago

Veldkornet commented 3 years ago

I’m using the HomeAssistant NodeRED Add-On which also has Sun Events bundled in the add-on.

Recently, I noticed that my flows weren’t working anymore, so I went to investigate and found that it was updated to 3.0.0 and hence with all the changes that came with it. I updated my flows as per your examples, and things started to work again.... most of the time.... sometimes it works, sometimes not....

Investigation continues... I first imported the example that you have, but for some reason it doesn’t find the sun-events node 23014CC1-808B-4CBC-BD0C-3267EDD63454

Note sure if this is a problem or not, but I just deleted the unknown node and just dragged the sun-events from out the toolbox. Then, as an output, I set the output to send me a Pushover notification for each sun event as it changed. What have I have found is that sometimes, the event is “undefined” and its different ones each day. After months of use with the 2.0.3, I’ve never had a problem. So I assume that I’m either doing something wrong in the new version or it’s something in 3.0.0. The table below is since I started keeping track of it and I’ll update it as more events come in if needed. I also changed the inject node to hourly, but that didn’t really make a difference.

Event Day 1 Day 2
nadir correct correct
nightEnd correct correct
nauticalDawn correct correct
dawn correct undefined
sunrise correct correct
sunriseEnd undefined undefined
goldenHourEnd undefined undefined
solarNoon correct ?
goldenHour correct ?
sunsetStart correct ?
sunset correct ?
dusk correct ?
nauticalDusk correct ?
night correct ?
freakent commented 3 years ago

Thanks for raising the issue. I’ll certainly fix the error in the sample, that was a last minute change of name before release that didn’t get updated in the samples.

For the undefined, can you explain how you are seeing this? Is it in the msg.payload? What about msg.sunevent? Can you attach your flow to this issue?

Veldkornet commented 3 years ago

Ah, I haven’t tried msg.sunevent directly, I can check if that makes a difference.

I was using msg.payload, and when that didn’t work I set the topic to sunevent and used msg.payload.sunevent. Not sure if it’s supposed to work like that.

[{"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":"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":[["c2b26aab.e326f8"]]},{"id":"c0aa61b0.223ae","type":"inject","z":"32cb8da3.eeffc2","name":"","props":[{"p":"topic","vt":"str"}],"repeat":"3600","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":110,"y":240,"wires":[["58c171f7.59b7a"]]},{"id":"c2b26aab.e326f8","type":"sun events","z":"32cb8da3.eeffc2","testmode":true,"verbose":"N","topic":"sunevent","name":"","x":610,"y":180,"wires":[["9d9573b3.1322a","4cb1360e.65949","e763438b.46b16"]]},{"id":"9d9573b3.1322a","type":"switch","z":"32cb8da3.eeffc2","name":"Which Event?","property":"payload.sunevent","propertyType":"msg","rules":[{"t":"eq","v":"goldenHour","vt":"str"},{"t":"eq","v":"sunset","vt":"str"},{"t":"eq","v":"nauticalDawn","vt":"str"},{"t":"eq","v":"dawn","vt":"str"},{"t":"eq","v":"sunrise","vt":"str"}],"checkall":"true","repair":false,"outputs":5,"x":860,"y":180,"wires":[[],[],[],[],[]]},{"id":"4cb1360e.65949","type":"debug","z":"32cb8da3.eeffc2","name":"","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"payload.sunevent","targetType":"msg","statusVal":"payload.sunevent","statusType":"auto","x":870,"y":80,"wires":[]},{"id":"e763438b.46b16","type":"function","z":"32cb8da3.eeffc2","name":"Construct Message","func":"msg.priority = \"0\"\nmsg.sound = \"gamelan\"\nmsg.payload = \"Sunevent: \" + msg.payload.sunevent\nmsg.topic = \"Sun Event\"\nnode.status({fill:\"blue\",shape:\"ring\",text:\"done\"});\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":850,"y":280,"wires":[[]]}]
freakent commented 3 years ago

I've pushed up a new V3.01 with the fixes to the examples. I have run your flow and I don't see any undefined values. Can you say anything more about how your nodered is set up that might be different to what I have here?

rccipriani commented 3 years ago

Having an issue too, none of the events fire. I attached a debug node to the sunEvents node and nothing.

freakent commented 3 years ago

@rccipriani Are you sending a value to sunevents ? It will not calculate the next day's sunevents unless you send it a payload. Can you post your flow or a screen shot ?

rccipriani commented 3 years ago

@rccipriani Are you sending a value to sunevents ? It will not calculate the next day's sunevents unless you send it a payload. Can you post your flow or a screen shot ?

It calculates the events and they show in the node's status but they never fire. image

freakent commented 3 years ago

@rccipriani It looks like you have connected the output to the input. What were you expecting that to do? Please review the examples and if you still have a problem open a new issue and post your complete flow file.

rccipriani commented 3 years ago

It's not, just how it looks in the screenshot.

rccipriani commented 3 years ago

image

freakent commented 3 years ago

So what's that Orange node labelled 00:01? What does it output and how often? Where are you setting your latitude and longitude? What do you see in the nodered debug window? Do you know how to export your flow from nodered? I have not got much to go on currently.

Veldkornet commented 3 years ago

Can’t really say there’s anything strange with the setup, the add-on runs on a RaspberryPi 4 running HomeAssistant, using a wired connection.

I set up a second node in test mode and it runs through all the events just fine... so for now I’ve updated my switch to listen to msg.sunevent.name, will see if that goes better over the next day or two.

I’ve also removed the GPS coordinates from the sun event node and only pass them through the payload.

Veldkornet commented 3 years ago

Aha, I see something! Even though the “test mode” went through without issues, the payload seems to have an undefined when it was just running normally. Payload is what I’ve been using until now.

I set the following to be sent on every event: "Sun event: " + msg.sunevent.name + ". Payload: " + msg.payload.sunevent

What that resulted in was the following: Sun event: sunsetStart. Payload: sunsetStart Sun event: sunset. Payload: sunset Sun event: dusk. Payload: undefined Sun event: nauticalDusk. Payload: undefined Sun event: night. Payload: undefined

freakent commented 3 years ago

I'm not entirely sure how but it appears if your msg.payload contained just a string value then msg.payload.sunevent would be undefined. I have improved how that situation is checked for and updated the unit test that goes with it. I have published a new version 3.0.2 with this fix. Please update and let me know if you still have a problem.

rccipriani commented 3 years ago

msg.sunevent.name worked for me too. Just upgraded to 3.0.2, will see if the payload is as expected now.

Veldkornet commented 3 years ago

I updated to 3.0.2 this morning FYI, so far so good, just letting it run for a while.

outworlder commented 3 years ago

3.0.2 seems to have resolved the issue for me too.

freakent commented 3 years ago

Ok that’s 3 positives, I guess I can close this issue. Thanks to everyone who helped with this.

Veldkornet commented 3 years ago

Indeed, looks to be okay, no problems since I installed 3.0.2 yesterday morning.