Skip to content

Instantly share code, notes, and snippets.

@piitaya
Last active August 12, 2024 09:43
Show Gist options
  • Select an option

  • Save piitaya/157eda513ed0c179ed1db465728a0062 to your computer and use it in GitHub Desktop.

Select an option

Save piitaya/157eda513ed0c179ed1db465728a0062 to your computer and use it in GitHub Desktop.
Sun exposition macro
{% 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