Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request/Enhancement: Azimuth (or direction) #25

Closed
boomalator opened this issue Jun 23, 2020 · 14 comments · Fixed by #89
Closed

Request/Enhancement: Azimuth (or direction) #25

boomalator opened this issue Jun 23, 2020 · 14 comments · Fixed by #89

Comments

@boomalator
Copy link

Thank you for your work on this. Very hand so far. I would like certain automations to differ based on where the sun is coming from (for example, if it is pouring in through the side that has windows, or if it is behind the garage). Is it a lot of work to get azimuth or direction? Thank you for considering it.

@pnbruckner
Copy link
Owner

I started working on adding azimuth, and it became a much harder task than I expected. I put the work aside and haven't had a chance to get back to it.

@boomalator
Copy link
Author

Well, if it it were to happen, I'd appreciate it. I'm not well-versed in astronomy, but I can code. :)

@jrb80
Copy link

jrb80 commented Apr 26, 2022

👍 azimuth sensor!

@pyrrolizin
Copy link

fyi: azimuth calculation is part of the normal sun sensor in the Home Assistant.
implementation (since 2016) : home-assistant/core#1951
documentation: azimuth

@pnbruckner
Copy link
Owner

@pyrrolizin, yes, this is true. However, people who use my sun2 custom integration (I would think) don't usually also use the built-in sun integration. These two integrations take different approaches. The built-in sun integration simply calculates attribute values on a periodic basis, where the period is adjusted throughout the day, on a pretty fixed schedule. My custom integration attempts to determine the time between each update, such that the value changes on a consistent basis (e.g., by 0.1 increments.) That is a much harder thing to do (at least, when based on the astral package.) And, unfortunately, it is much harder with azimuth than elevation, which is why I never finished the azimuth implementation.

But, yes, if anyone needs azimuth (even if they're using this custom integration), they'll probably need to use the built-in sun integration to get it.

@pyrrolizin
Copy link

@pnbruckner ah, I see. Thank you for the clarification.

That is a much harder thing to do (at least, when based on the astral package.) And, unfortunately, it is much harder with azimuth than elevation, which is why I never finished the azimuth implementation.

Yes, that is true. I have now read a little deeper into the calculation and your code and can understand your decision very well.

@backcountrymountains
Copy link

So I was looking around for an azimuth calculation and stumbled upon this paper: A solar azimuth formula that renders circumstantial treatment unnecessary without compromising mathematical rigor: Mathematical setup, application and extension of a formula based on the subsolar point and atan2 function

I have not looked into any code, as I am not a programmer, but the paper presents a method to calculate the azimuth based on only lat/lon and time using atan2.

Would this be helpful for sun2?

@pnbruckner
Copy link
Owner

@backcountrymountains, thanks, but the astral Python package (which both this custom integration and the standard built-in integration use) already contains a method to return the azimuth at a given time and location. That's not the issue.

My integration wouldn't just get the azimuth value at some periodic rate. Rather it would attempt to determine when the azimuth will reach incremental values. In essence, it needs to do the inverse of the usual function -- i.e., calculate time based on azimuth, not azimuth based on time. And given the nature of the azimuth curve, the technique I used when doing the same for elevation doesn't work very well, and I've never taken the time to try something else.

I understand that this is a gaping hole in this integration, but I guess I've just not been up to the task when it comes to azimuth.

@cdeharo
Copy link

cdeharo commented Aug 21, 2023

I found this integration because I need to obtain elevation and azimuth for two different locations, but the built-in integration can only be used once, for the default location of HA.

they'll probably need to use the built-in sun integration to get it

This is not possible when the built-in integration is used to track a location and this other integration is used to track a different location, isn't it?

As a workaround, could be possible to have an azimuth based on time while the preferred implementation is not finished?

Thanks for the great work!

@pnbruckner
Copy link
Owner

As a workaround, could be possible to have an azimuth based on time while the preferred implementation is not finished?

Yes, I suppose that's a reasonable thing to do. I'll see if I can find some time to work on that.

@pnbruckner
Copy link
Owner

@cdeharo, et al,

A basic implementation is available in beta release 2.4.0b0. Let me know if you try it and how it works for you.

@cdeharo
Copy link

cdeharo commented Aug 24, 2023

Thank you for implementing so quickly. I have just installed the beta release 2.4.0b0 and it is working as expected!

@pnbruckner
Copy link
Owner

@cdeharo is it still working ok? If so, I'll go ahead and fully release.

@cdeharo
Copy link

cdeharo commented Aug 30, 2023

Yes, everything is still working fine. Thank you for your hard work on this. I'm happy to give you the green light to fully release it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants