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

added timeshift option #17

Closed Tobix99 closed 3 years ago

Tobix99 commented 3 years ago

Hey,

so I added the ability to shift the fire event forward and backwards in time, so that you can trigger some things earlier. I mainly use this for my home automation to slowly turn on the lights. But before the lights would turn on to late and in the begging it would be too dark.

I've never written any Plugins for Nodered, so I'm not sure if I did the HTML stuff correctly.

The value for the time shift is a string, consisting of an operator and a value, e.g. +15.

In the lib I get a substring of the timeshift obj and decide with the first char to add or subtract minutes. The other chars are the minutes to add/substract.

I also fixed the test cmd (but no test are defined, sooooo....)

freakent commented 3 years ago

Can you explain what you mean by a timeshift? If the event is due to fire at say 12:15 for example, when do you fire it?

Tobix99 commented 3 years ago

Can you explain what you mean by a timeshift? If the event is due to fire at say 12:15 for example, when do you fire it?

It depends what you have selected in the drop down menu (if you click on the sunevents node). There you can specify how many minutes you want to add or subtract from the event.

So for example I select 15 minutes earlier and the event ist due to fire at 12:15, then the event will be fires at 12:00

So you can "shift" your Sunset in "time" forward or backwards and trigger NodeRed Automations earlier or later.

freakent commented 3 years ago

OK, I don't understand the use case for that. If Sunset is at 18:15 why would I want it to fire at 18:30? As each day gets longer or shorter a fixed 15 minutes will have a very different affect. Have you considered taking the output of this node into another node to achieve what you are looking for?

This feels like it is starting to divert from the general guidance from the node-red team: https://nodered.org/docs/creating-nodes/

Tobix99 commented 3 years ago

No I want to fire the event earlier, so sunset is 18:15 but I want to fire the event 15 minutes before sunset. So my smartlight can fade in over the time of 15 minutes and than be on when the sunset occurrs. If I want to fire it later I can use the delay Node (I know) but I can’t fire the event before.

So this is a Offset function to offset the time of the event.

freakent commented 3 years ago

I see. The sunset start or dusk events would already give you close enough to what you are looking for without this extra complexity. Maybe you should look at the Suncalc library which is doing all the real work here.