Set global variable to sunrise/sunset time


#1

I’m trying to set a global variable to equal sunrise/sunset time, but this doesn’t seem to be possible through the UI, am I missing something?

The idea behind this is that I am setting up 6 time related globals: evening lights on, evening lights off, sunset offset, morning lights on, morning lights off, and sunrise offset. These variables will be used across all of my time based pistons and allow me to set, at a global level, time control for on/off times as well as offset from sunrise/sunset if needed. For the time being, I would like to set (global)EveningLightsOn = sunset + (global)SunsetOffset, and (global)MorningLightsOff = sunrise + (global)SunriseOffset, thus allowing me to simply use the global EveningLightsOn or MorningLightsOff in the piston without having to do the math there.

I realize that I can set local variables to equal sunrise/sunset, but that doesn’t allow me to update timing globally.


#2

Try using

$sunset

and

$sunrise

for the expression


#3

Wow, that was easy! Thanks

The sunset time is working fine, but when I try to set it to sunrise, it’s saving as PM instead of AM :s

image


#4

I’m not 100% on this but you might need to use $nextSunrise and $nextSunset depending on when you do the math.

Also, because your only storing them to Time, instead of Date and Time, unless you only do the Math in the morning (after midnight) and before $sunrise, the math might come out a bit weird as $sunrise might be in the past (seems to change at midnight i think / vers the $nextSunrise and $nextSunset that always seem to update once the time as pasted) , or they might be the next day, and with only a Time variable may not handle that well.


#5

I run something similar, but I set up the time once based on sunset/sunrise (with offset), but I put all of the devices I want into a global variable device group. This way I can just set the entire group on/off as needed.