TLDR; Is there an efficient way of detecting that the sun elevation has just crossed a certain threshold?
I’d like to run a task when the sun elevation just dipped below or risen above a certain threshold, say 10 degrees, or 15 degrees.
I’m using the astro binding. I know I can detect the sun rise start / stop, dusk, dawn, etc. via the channel trigger, but not a specific elevation.
Currently I am just triggering on the change in Sun elevation, and detecting whether the new elevation is above my threshold, and its last value was below it. While this works, it seems wasteful to fire this rule every time the sun elevation changed which occurred quite often.
FWIW, this is my current rule in jruby, but of course this can be implemented in any supported language
SUN_ELEVATION_THRESHOLD = 5
rule 'sun elevation trigger' do
changed Sun_Elevation
run do |event|
if Sun_Elevation > SUN_ELEVATION_THRESHOLD && event.was <= SUN_ELEVATION_THRESHOLD
# do something when the elevation went above the threshold
elsif Sun_Elevation < SUN_ELEVATION_THRESHOLD && event.was >= SUN_ELEVATION_THRESHOLD
# do something when the elevation dipped below the threshold
end
end
end