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

Output current state (most recent sun event) on input. #31

Closed deggle closed 2 years ago

deggle commented 2 years ago

It would be really useful for me (and perhaps others) if the node was able to send an output on every input. This output could include the current (most recent) state, perhaps along with other information (the time that state occurred, maybe the an array of the next 24 hours of states etc). Enabled by a tick box such as "[X] Send output on every input message?" or similar.

The rational for this is that if I have a variable (e.g. MQTT topic) which tracks changes in state and one is missed it would be helpful not to skip the current state entirely if the nodes are restarted (at which point I'd like to be able to set the most recent event name. I appreciate that technically this is about events which are time-based, and it's not really a 'state' thing, but I do think there are use cases where this would be good.

freakent commented 2 years ago

Hi, This has been suggested before, but I don't feel it's the right solution to mix events and states. The purpose of this node is to output events at the time the event happens. I would also argue that events like sunset, sunrise are not states, they are points in time. States would be things like "Lights on" or "Lights Off" and are specific to your particular use case.

If you want an array of sunevents to initialise your state, you can simply include a function node in your flow to retrieve an array the Suncalc library. I provided an example here: https://github.com/freakent/node-red-contrib-sunevents/issues/28#issuecomment-877872960