Simple Outdoor Light Timer Issues


#1

I have designed a very simple first piston. It is meant to turn on my front door (outdoor) lights and my garage outdoor lights 30 minutes before sunset and turn them both off at 30 minutes past the next sunrise. Here is my piston:

execute
if /* #1 /
Time is between 30 minutes to sunset and 30 minutes past {$nextSunrise} /
#6 /
then
with /
#4 /
Front Door Lights and Garage Door Lights
do
Turn on; /
#5 /
end with;
else
with /
#2 /
Front Door Lights and Garage Door Lights
do
Turn off; /
#7 */
end with;
end if;
end execute;

The issue I have is that …

  1. The lights turn on at 30 minutes before sunset and turn off at 30 minutes past sunrise the next day.
  2. The next day the lights turn on at 30 minutes before sunset and do NOT turn off at 30 minutes past sunrise the next day.
    So, the pattern is that this piston seems to work every OTHER day. Works well on day 1, not on day 2, works on day 3, you get the idea.

I can submit the logs if anyone wants to see them. Any ideas? Thanks Jeff


#2

Try using the preset Sunrise instead of the system variable, $nextSunrise. The presets of Sunset and Sunrise work correctly when the time range spans midnight … so “Time is between 30 mins. to Sunset and 30 mins. past Sunrise” should work.

You have to be careful with the system variables, $sunset and $sunrise … they are the values for the current day; I think $nextSunrise doesn’t get set until $sunrise has past, but I’ve never used it to find out :slight_smile: … but it might explain why your piston works every other day because on the day it doesn’t work, $nextSunrise is probably in the past.


#3

I agree with @elf. The presets simplify it.

If for some reason you want to use the system variables, you can invert that one line like this:

IF Time is NOT between 30 minutes past {$sunrise} and 30 minutes to {$sunset}

Notice I switched the order of the two, and added the word NOT.
Also, with this method, you would use $sunrise, not $nextSunrise.

This keeps the system variables from spanning midnight.


#4

Thanks @elf. I was trying to “force” my piston to use today’s sunset (-30 minutes) as a start and tomorrow’s sunrise (+30 minutes) as an end. I didn’t want the piston to fail because it started with today’s sunset (-30 minutes) and ended with today’s sunrise (+30 minutes) which (in this case) would have the end before the start. So, I figured I would use the system variable $nextSunrise. Seemed reasonable. I have replaced $nextSunrise with Sunrise and hope, as you say, that the piston will work correctly when the time range spans midnight. Thanks again.


#5

Thanks WCmore. Let me try @elf’s approach first. I was worried that my piston might fail because it started with today’s sunset (-30 minutes) and ended with today’s sunrise (+30 minutes) which (in this case) would have the end before the start. So, I figured I would use the system variable $nextSunrise. Seemed reasonable. I have replaced $nextSunrise with Sunrise and hope, as @elf says, that the piston will work correctly when the time range spans midnight. If not, I will try your approach. Appreciate the advice.


#6

One other food for thought…
Day to day, there is usually only a minute or 2 variance on sunrise or sunset times…
(In other words, the typical human can not tell the difference if the piston fired a minute early or late)


#7

Ahhhh, so just set a fixed time on one day and a fixed time off the next day and be done with it. Perhaps I was trying to be too sophisticated. Still, when I compare my little piston with the mega-pistons I see out there, sophisticated is not the word I would use! Thanks again, great to have some experienced programmers at my back.


#8

There are many ways to skin a cat. I usually look at the day as midnight to midnight…
(even though that does not sync with my sleep day)

In other words, I program off at sunrise TODAY, and on at sunset today.
In hundreds of thousands of lines of code, I have never even once used nextSunrise for anything.


#9

Makes sense. I will keep it in mind if @elf’s “spanning midnight” does not work. Thanks


#10

It should (it better) work, LOL … I have several working pistons that use “Sunset to Sunrise” … they’ve been working fine since Adrian implemented the presets.


#11

Thanks. I have made the changes and will test it over the next few days. I’ll let you know if (when) it works!


#12

Here is an example of one the I wrote. It has been working flawlessly for months now. It will also bring the lights up to 100% for 10 minutes when someone arrives then drop them down to 5% so the neighbors won’t be bothered.


#13

Thanks @ tw1st3d7550. Very nice coding. Something that I can aspire to. J


#14

Everyone. Thank you all for your help in this. I made the changes that @elf recommended and the piston has been running for about 4 weeks now. It works almost perfectly. I say almost because every two or three days, my outdoor lights (that have already been ON since sunset last night) turn ON then turn OFF at exactly the same time at sunrise the next day. I say exactly the same time based on the fact that I get two SMS messages at the same time, one for ON then one for OFF but I suppose that these might be separated by one scan of the Smartthings hub. This doesn’t happen every day. One day the lights will come ON and the next day OFF then that evening ON and the next morning ON & OFF. So, sometimes I get this ON & OFF sequence every other day for a few days then every day for a couple of days. It doesn’t really affect the result, the outdoor light still turn ON in the evening and OFF in the morning but it would be nice to clear up my coding to eliminate this. Thoughts?