[CODE] Heliotrope: a plugin that tracks the sun

Edit: Code is now on Github.

Here’s a simple plugin which displays the sun’s apparent position from your location on the earth. For my location, it is correct within about 0.1 degrees (even in UI4 with its single-precision floats).

Astronomical terminology:
Azimuth is the bearing around the horizon of the sun. Azimuth of 0 is true north, 90 is east, 180 is due south, and 270 (this plugin displays -90) is west. Azimuth will be around +90 at sunrise, about 0 or 180 around noon, depending on your hemisphere, and around -90 at sunset.
Altitude is the height of the sun above the horizon. 90 is straight up (zenith). 0 is right on the horizon. Negative numbers are below the horizon. Because the sun is 0.5 degrees across, sunrise/set instants are actually when the altitude is -0.25 degrees.

Despite the astronomical theme, the Heliotrope plugin has almost nothing in common with Ap15e’s DAD plugin. Heliotrope doesn’t require Net access, and it updates throughout the day. It doesn’t display rise and set times, but you can set events for when the sun’s altitude goes below -0.25 degrees (sunset) or above -0.25 degrees (sunrise), or for any other altitude.

Installation instructions:

  1. Download the four files from GitHub - futzle/MiOS-Heliotrope: Plugin for MiOS home automation gateways to create devices which track the sun
  2. Install all four files in MiOS Developers > Luup Files.
  3. Create a new device in MiOS Developers > Create Device. Use D_Heliotrope1.xml for the device file.
  4. Save.

Edit: New version with improved accuracy.

Nice addition to the astronomical toolkit for Vera. Thanks for sharing your code.

You might find it interesting to compare the output of your plugin with the results of [tt]timeutils.sun_position([time] [, place])[/tt] (cf. [tt]http://code.mios.com/trac/mios_genericutils/wiki/TimeUtils[/tt]).

BTW, I would suggest changing [tt]luup.log(“I_HolidayVirtualSwitch start”)[/tt] to avoid confusion. :slight_smile:

I’d completely forgotten about that. They appear to be mostly in agreement, though my code also adjusts for atmospheric refraction, which adds a couple of minutes to the daylight length at most latutudes. Fascinating how very different that code is from mine, too. We’ve both taken different approaches to the single-precision floating-point limit of OpenWrt in UI4.

Oh well, it was a good learning experience for me.

BTW, I would suggest changing [tt]luup.log("I_HolidayVirtualSwitch start")[/tt] to avoid confusion. :)

Yeah yeah. Pedant.

Azimuth for SouthWest is -135 degrees?

Yep. I’m just using the result of the atan2() function, which returns results in the range [-π, +π], and scaling it to degrees. It occurs to me that this might be irritating for people in the northern hemisphere, who will get a discontinuity in the azimuth around noon, where it jumps from +180 to -180. Would it make more sense if the azimuth could be normalized into the range [0, 360]?

IMHO the azimuth should be normalized.

[tt]www.iau.org/static/resolutions/IAU1938_French.pdf[/tt] has a definition of azimuth, but I don’t know what’s the correct definition of azimuth nowadays.

Yeah yeah. Pedant.
if (FORMULA:find("^%-") == nil) then
	FORMULA = "+" .. FORMULA
end

fails for

FORMULA = "+0-2+3-5"

[quote=“Ap15e, post:7, topic:168560”] if (FORMULA:find("^%-") == nil) then FORMULA = "+" .. FORMULA end

fails for

FORMULA = "+0-2+3-5" [/quote]

I know you’re being facetious, but I agree that someone, somewhere, will try to put a leading + onto the string. It shall be fixed.

Hi Futzie,

I have installed the Heliotrope plugin and it appears to have installed ok except it does no show the azimuth or altitude. Could you offer any suggestions as to what may be wrong here?

Thanks

Warren

Hi Warren,

I’ll need more to go on. Have you set your location on your Vera (Toolbox > Location)? Did you restart the Luup engine at least twice, and wait one minute? Do you get Right Ascension and Declination (in the first tab of the dialog)? Is there anything in the Luup log?

Hi Futzle,

Sorry I am new to this so Iam not sure what informaqtion is useful.

The location is set based on the the drop down selections, luup has been restarted twice.

The only information showing in the first tab of the dialogue (Control tab) is “Device settings”, no other text.

Thanks

Warren

Hi Warren,

It’s sounding like the plugin is missing one or more files.

Check two things:

  1. In MiOS Developers > Luup Files, check that you can see all of the files that were in the zipfile (D_Heliotrope1.xml; D_Heliotrope1.json; I_Heliotrope1.xml; S_AstronomicalPosition1.xml). If any are missing, or have paths attached to them, upload them again.

  2. On the Advanced tab for your new device, double-check the spelling in the device_file entry (D_Heliotrope1.xml with no other punctuation or spaces, not even trailing). Copy-and-paste it to ensure that you don’t type it wrong.

Hi Futzle,

Thank you very much for the suggestions, it works! The problem seems to be with IE9 it loads the files with the path attached, after downloading Firefox and going through the same process it now works fine.

Thanks again.

Warren

Hi Futzle,

Do I need any special syntax in a scene to make it work?

What I have tried so far including several variations does not seem to work.

For example if a set an event to run when “Sun goes below Altitude” with Degrees set to say “-12” it does not trigger?

Thanks

Warren

Hi Warren,

I made a scene that had one event: “Sun goes below altitude” with argument “-5”. It triggered after sunset when the altitude crossed from -5.something to -6.something degrees. So it’s only working on the integer portion of the altitude, which I seem to recall is a known bug.

It’s hard to say why it’s not working for you. Try the simplest example you can think of (something like mine) and see if it still doesn’t work.

Hi Futzle,

I have been running this plugin for a couple of weeks now and it is working perfectly.

Thank you for taking the time to create this plugin.

Warren

Now updated for UI5. The plugin should work identically for UI4. Download links on the first message of the topic.

@futzle,

Is it possible to include Azimuth (as a feature request) to the trigger drop down?

Indeed, that is a feature I plan to include. I have to rethink the discontinuity, because some people will want it at 0° and others will want it at 180°. Probably I will just do both.

For my purpose, I was hoping to be able to set triggers to keep a weather camera pointed 180 degrees out of the the sun by moving it every 15 degrees (or so) of Azimuth.
If we are able to input the trigger degrees, that would be awesome. If not, no worries…