Use of $sunrise and $sunset


#1

1) Give a description of the problem
More of a question than a problem, I am trying to understand how to make lights go on/off if some action is triggered before sunrise or after sunset.

2) What is the expected behaviour?
I have a garage ramp with 2 sets of lights, one inside the garage, and one just outside. I want the indoor lights to go on every time the garage door opens (tilt sensor)… And the outdoor lights to go on only if it is earlier than 15 minutes before sunrise, or later than 15 minutes after sunset for that day.

3) What is happening/not happening?
To be honest - I have not tested it yet, I just wrote it, and it would take a bit to test it properly as I would need to be there around sunrise/sunset and test at those times.

But my questions are:

  1. I noticed the variables $nextSunrise and $nextSunset, and I am unsure what I should use… My best guess in my case is to use the default $suntise and $sunset as I want to compare to sunrise/sunset of today, not of the next day.

  2. Initially I used 900 (seconds) instead of 15 (minutes)… But I looked through the community and I think that everyone uses minutes with $sunrise and $sunset… Is this assumption correct please?

**4) Post a Green Snapshot of the piston![image|45x37]

5) Attach logs after turning logging level to Full
No logs as yet…


#2

When you add a condition in webCoRE you’ll see you are offered the option of a Virtual Device, one of which is Time. One of the conditions is is between which lets you choose sunrise and sunset as a preset and add positive and negative offsets in seconds or minutes.

You can safely specify a period that spans midnight, such as sunset to sunrise, as webCoRE will know how to handle it. Some users recommend implementing it as a negation of the sunrise to sunset period but that is exactly what webCoRE does itself.


#3

Few things to be aware of

$sunrise, $sunset are today’s sunrise and sunset. There are 3 cases that can occur

  • something runs that uses these before either has happened today (early in the morning)

    • any scheduling based off of this run will be correct for today
  • it is run after sunrise but before sunset

    • any scheduling for sunset will be correct, but a sunrise setting (for tomorrow) may be off a bit because of the changing nature of sunrise and sunset
  • it is run after sunset today (but still today), so any future scheduling on sunrise or sunset (for tomorrow) may be off a bit because of the changing

So what to do?

  • I addition to your sunrise, sunset scheduling, you could have the piston wake up at say 3:01 AM, and do nothing really except to update the sunrise, sunset schedules for today (to be very accurate)

You can do this but adding an if at the end of your piston

if time occurs at 3:01 am

Piston fires twice
Update/refresh sunrise and sunset variables