Last active
August 12, 2024 09:43
-
-
Save piitaya/157eda513ed0c179ed1db465728a0062 to your computer and use it in GitHub Desktop.
Sun exposition macro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {% macro is_exposed(orientation) %} | |
| {% set is_sunrise = as_timestamp(now()) < as_timestamp(today_at("12:00")) %} | |
| {% set azimuth = states('sensor.sun_solar_azimuth') | float(0) %} | |
| {% set elevation = states('sensor.sun_solar_elevation') | float(0) %} | |
| {% set max_sun_angle = states('input_number.shutter_max_sun_angle') | float(0) %} | |
| {% if is_sunrise %} | |
| {% set min_sun_elevation = states('input_number.shutter_min_sun_elevation_sunrise') | float(0) %} | |
| {% else %} | |
| {% set min_sun_elevation = states('input_number.shutter_min_sun_elevation_sunset') | float(0) %} | |
| {% endif %} | |
| {{ (orientation - azimuth) | abs <= max_sun_angle and elevation >= min_sun_elevation }} | |
| {% endmacro %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment