pnbruckner / ha-sun2

Home Assistant Sun2 Sensor
The Unlicense
236 stars 22 forks source link

Add azimuth_at_time and time_at_azimuth sensor #120

Closed gpongelli closed 6 months ago

gpongelli commented 8 months ago

Hi, I've just discovered this useful component, but I've seen it misses sensors like "azimut_at_time" and "time_at_azimuth" that could be useful as same as their existing equivalent related to elevation.

Hope this will be implemented 😃

pnbruckner commented 8 months ago

azimuth_at_time should be easy enough, but not sure about the opposite. Can you describe what you see as the use case for these?

gpongelli commented 8 months ago

Azimuth_at_time is probably the one I have an use case for: having some bedroom’s covers at NE, I would change their close position during the year when the sun hit them at early morning.

so with new method I can do things like:

If azimuth_at_time(sunrise_or_dawn_datetime_or_timestamp)<90:
  Close position=5
Else:
  Close position=20

With value 90 (it’s an example) identified from online sun calculators site, using same time format existing for elevation.

thanks.

pnbruckner commented 8 months ago

I've already added azimuth sensors for sunrise & sunset. See https://github.com/pnbruckner/ha-sun2/releases/tag/3.3.0b1

gpongelli commented 8 months ago

I've already added azimuth sensors for sunrise & sunset. See https://github.com/pnbruckner/ha-sun2/releases/tag/3.3.0b1

good to know, I'm on 3.2.1 so I didn't see them, waiting for next release 👍

pnbruckner commented 6 months ago

Rising & setting azimuth sensors have been added. The time_at_azimuth sensor will probably not be easy to implement. Since neither that, nor azimuth_at_time for other times, seem to be "in demand", I'm going to close. But if anyone feels strongly that either are useful and needed, I could reconsider.

DavidAntonin commented 1 month ago

I would need the elevation_at_time and azimuth_at_time functions to determine the position of the sun at half hour intervals every day at midnight and determine the solar generation attenuation based on that - for Solcast integration. From fall to spring, when the sun is lower it shades my neighbors houses and trees. I know their azimuth and elevation relative to the solar panels, and so knowing the sun's position, I can determine the shading of the solar panels

pnbruckner commented 1 month ago

elevation_at_time and azimuth_at_time functions

They would not be functions. They would create sensors. If you need both values at half hour intervals, you would need 96 sensors!

heinemannj commented 1 month ago

I'm developing right now an Home Energy Management System (HEMS) https://github.com/heinemannj/huawei_solar_hems .

I have to calculate several setpoints for today and for tomorrow to provide EMHASS https://github.com/davidusb-geek/emhass an prediction horizon for tomorrow afternoon/evening :

          sun_rising_time_today: "{{ state_attr('sensor.hems_sun_rising', 'today')|as_datetime|as_local }}"
          sun_setting_time_today: "{{ state_attr('sensor.hems_sun_setting', 'today')|as_datetime|as_local }}"
          solar_noon_time_today: "{{ state_attr('sensor.hems_sun_solar_noon', 'today')|as_datetime|as_local }}"
          prediction_end_time_today: "{{ state_attr('sensor.hems_sun_prediction_end', 'today')|as_datetime|as_local }}"
          prediction_end_time_tomorrow: "{{ state_attr('sensor.hems_sun_prediction_end', 'tomorrow')|as_datetime|as_local }}"
          pv_excess_start_time_today: "{{ state_attr('sensor.hems_sun_pv_excess_start', 'today')|as_datetime|as_local }}"
          pv_excess_end_time_today: "{{ state_attr('sensor.hems_sun_pv_excess_end', 'today')|as_datetime|as_local }}"

Actually I'm using sun2 time_at_elevation sensors, but obviously this will not work for an SSE PV orientation (-41°):

  sun2:
  - unique_id: hems
    sensors:
      - unique_id: prediction_end
        time_at_elevation: 25
        direction: setting
        icon: mdi:weather-sunset-down
        name: Prediction end
      - unique_id: pv_excess_end
        time_at_elevation: 15
        direction: setting
        icon: mdi:weather-sunset-down
        name: PV excess end
      - unique_id: pv_excess_start
        time_at_elevation: 15
        direction: rising
        icon: mdi:weather-sunset-up
        name: PV excess start

Above based on sun2 time_at_azimuth sensors will solve the issue in an perfect way. Please support this feature request - From my perspective it really make sense.

pnbruckner commented 1 month ago

@heinemannj, sorry, I'm not really following you. E.g., what is "an SSE PV orientation (-41°)"? I'm also not following how a time_at_azimuth sensor could help you. But I guess that's not really important. As I've said before, implementing such a sensor would not be easy, since the astral package does not provide an equivalent function, and trying to find a point on the azimuth curve can be tricky, at least using the same technique I used for the elevation curve. I still don't think I'm seeing enough demand to justify spending the time on it. However, if someone else would like to submit a PR, I'd be happy to consider accepting it.