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

Functionality suggestions #4

Closed roybosch closed 4 years ago

roybosch commented 4 years ago

Hi, I started using your node today. It seems to be one of the best out there. If have some ideas about functionality that could make it even better, based on what I'm using it for:

  1. Adding a "output on startup" option;
  2. Adding a "output on interval" option;
  3. Adding a input connection point, to make output based on incoming input possible;
  4. Choosing which of the messages should be send and which shouldn't;

I'm using this node to change a input_select list. I'm now unable to force-check the sunstatus, but I have to wait for output of the node, which apparently takes a long time.

Thanks in advance!

Roy

freakent commented 4 years ago

Hi Roy, I am embarrassed to say I haven't touched this code in 5 years! Although it continues to run the lighting in my house without a hitch. I am not even sure that it is compatible with the latest version of Node-Red. I will not be offended if you want to clone/fork my repo and build on it. One day I might even find the time to jump back in.

roybosch commented 4 years ago

Hi!

I noticed, but I figured that I could always try :D It seems to be compatible, as it did output some data. Tonight I'll see if my flow works.

Unfortunately I don't have the needed programming skills to change your code. Otherwise I'd have tried it.

Thanks for your quick reply, have a nice day!

Roy

freakent commented 4 years ago

@roybosch I am making some updates to a V2. Can you explain in more detail with a use case each of the updates you suggested? I don't really understand how you re trying to use this. If a node outputs a message, and you don't subscribe then it is ignored.

roybosch commented 4 years ago

Hi! Nice to hear that. Currently I'm using another solution, which isn't great but I got it working. I'll follow your progress, because the mentioned features could simplify my flows a lot!

I'll describe some use cases, referring to the numbered list of my first post:

1. Adding a "output on startup" option;

2. Adding a "output on interval" option;

3. Adding a input connection point, to make output based on incoming input possible;

4. Choosing which of the messages should be send and which shouldn't.

I hope this helps. If not, I'm happy to explain further!

Roy

freakent commented 4 years ago

@roybosch Thanks for taking time to write this all out. I'll respond to each.

  1. When the node is deployed it does two things right away. It goes through all the events working out which ones have already passed and sets a timer for those that are expected later today. Then it schedules itself to run again at midnight to repeat the same scheduling process each day. While it is doing the work it does output plenty of debugging messages both the the console and to the debug panel.

  2. The right way to do this is to store the events output by this node. I actually use mosquitto and push a persistent message on to a topic that says whether my lights should be on or not. So the curent state is always in mosquitto. Maybe I should share my flow so you can do similar.

  3. like 2, the best way is to store this in a persitent topic on Mosquito. I have a node that monitors the sunevents and at dusk sets the value on mosquitto. Any other flow can pull that value from mosquitto as needed. I am thinking of making the lat and long parameters that can be set in the flow. So everyday it would use the available lat and long. I am thinking of usecases on a boat.

  4. You are correct it currently outputs every sunevent that the underlying suncalc node outputs. It is actually possible to add your own events based on sun's angle (I have breakfast in my test data). There is no functional downside to emitting event on each sun event, maybe a slight performance over head but it is very slight. Maybe this is another case I should share my flow, as I just ignore the other events I am not interested in.

roybosch commented 4 years ago

Storing it in mosquitto isn't an option I've thought about. I'm going to explore that. Also, I'm very interested in your flows, always looking for improvements on my own flows!

recklessnl commented 4 years ago

I'd like to chip in and say I agree with @roybosch - of course you can go about it in a roundabout way and use MQTT for these things, but it would be really nice to have the sunevents node support these features, so that you don't need to worry about that.

Points 1 to 3 are essential for me, and would make the node a TON better.

Point 4 I think isn't that necessary, as a simple switch node after sunevents filters out everything you don't want, but it certainly can't hurt.

freakent commented 4 years ago

I don’t consider Mosquitto a round about way. MQTT is the right tool for the job. And I think the way I have designed this node now follows the “general guidance” for nodes provided by node-red team. https://nodered.org/docs/creating-nodes/ Also to make the node continue to emit the same information continually would be very in efficient. You would have to choose an interval (every second, every minute, etc who knows what the right value should be), the more often you emit the same value the less efficient the whole thing becomes. Your flow would also have to deal with duplicate events, assuming like me you don’t want to keep turning your lights on every day 10 seconds. In a system like this we should make a distinction between managing events and managing state. MQTT persistent topic is definitely the right way to go.

I did go through this thought process at the time and your suggestions have brought all that thinking back to memory. Don’t think for a minute that I am not interested in feedback or suggestions, I most certainly am. For example, I am putting some thought in the Moon Events suggestion made in another issue.

freakent commented 4 years ago

I haven’t tested my own existing flow with this new version yet. But I assume I could put my flows file in an “examples” directory. Or would a screen shot in the Readme file be more useful ?

freakent commented 4 years ago

I have added a screen shot of my flow to the docs folder. My Raspberry PI set up is really messed up and I can't update my live system to the latest node-red yet so my actual flow file would not be any good for you. Hopefully a screen shot helps for now.