Created
April 10, 2026 13:44
-
-
Save yorb/631ab51ebbe5ac639e953b723d95ece8 to your computer and use it in GitHub Desktop.
Home Assistant window open/close notification
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
| template: | |
| - binary_sensor: | |
| - name: "Nice Day" | |
| unique_id: nice_day | |
| availability: > | |
| {{ states('sensor.current_temperature') | is_number and | |
| states('sensor.current_humidity') | is_number }} | |
| state: > | |
| {% set temp = states('sensor.current_temperature') | float(none) %} | |
| {% set min_target = states('input_number.day_min_temp') | float(none) %} | |
| {% set max_target = states('input_number.day_max_temp') | float(none) %} | |
| {% set pollen_idx = states('sensor.allergy_index_today') | float(0) %} | |
| {% set humidity = states('sensor.current_humidity') | float(0) %} | |
| {# Check all three allergen attributes for Pine #} | |
| {% set a1 = state_attr('sensor.allergy_index_today', 'allergen_name_1') | string %} | |
| {% set a2 = state_attr('sensor.allergy_index_today', 'allergen_name_2') | string %} | |
| {% set a3 = state_attr('sensor.allergy_index_today', 'allergen_name_3') | string %} | |
| {% set pine_active = ('Pine' in [a1, a2, a3]) %} | |
| {% if None in [temp, min_target, max_target] %} | |
| false | |
| {% else %} | |
| {% set is_temp_nice = (temp >= (min_target - 4)) and (temp <= (max_target + 4)) %} | |
| {% set is_humidity_nice = humidity < 65 %} | |
| {# Pollen is only bad if index is high AND Pine is one of the top 3 #} | |
| {% set is_pollen_bad = (pollen_idx >= 7.0 and pine_active) %} | |
| {{ is_temp_nice and is_humidity_nice and not is_pollen_bad }} | |
| {% endif %} | |
| attributes: | |
| temp_actual: "{{ states('sensor.current_temperature') }}°F" | |
| temp_range: "{{ (states('input_number.day_min_temp')|float - 4) }} to {{ (states('input_number.day_max_temp')|float + 4) }}" | |
| humidity_actual: "{{ states('sensor.current_humidity') }}%" | |
| pollen_index: "{{ states('sensor.allergy_index_today') }}" | |
| top_allergens: "{{ state_attr('sensor.allergy_index_today', 'allergen_name_1') }}, {{ state_attr('sensor.allergy_index_today', 'allergen_name_2') }}, {{ state_attr('sensor.allergy_index_today', 'allergen_name_3') }}" | |
| pine_detected: "{{ 'Pine' in [state_attr('sensor.allergy_index_today', 'allergen_name_1'), state_attr('sensor.allergy_index_today', 'allergen_name_2'), state_attr('sensor.allergy_index_today', 'allergen_name_3')] }}" |
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
| alias: Notify to open/close windows | |
| description: >- | |
| Sends notifications to users to open windows when it's a nice day and they're | |
| closed, or to close them when the nice day ends and they're open, considering | |
| user presence. | |
| triggers: | |
| - trigger: state | |
| entity_id: | |
| - binary_sensor.nice_day | |
| id: "on" | |
| for: | |
| hours: 0 | |
| minutes: 5 | |
| seconds: 0 | |
| to: | |
| - "on" | |
| - "off" | |
| - trigger: state | |
| entity_id: | |
| - input_select.day_part | |
| to: | |
| - Night | |
| - Morning | |
| conditions: [] | |
| actions: | |
| - choose: | |
| - conditions: | |
| - condition: state | |
| entity_id: binary_sensor.nice_day | |
| state: | |
| - "on" | |
| - condition: state | |
| entity_id: input_boolean.windows_open | |
| state: | |
| - "off" | |
| enabled: true | |
| - condition: state | |
| entity_id: input_select.day_part | |
| state: | |
| - Morning | |
| - Day | |
| - Evening | |
| - Night | |
| sequence: | |
| - action: ai_task.generate_data | |
| metadata: {} | |
| data: | |
| task_name: Nice Day Message | |
| instructions: >- | |
| Write a short message encouraging the user to open the windows. | |
| Use the following information as justification: | |
| Current temperature: {{ states('sensor.current_temperature') }} | |
| Current humidity: {{ states('sensor.current_humidity') }} | |
| Current allergy (pollen) index on a scale of 0-12: {{ | |
| states('sensor.allergy_index_today') }} | |
| The top 3 allergens today (only Pine is a concern for opening | |
| the windows): | |
| {{ state_attr('sensor.allergy_index_today', 'allergen_name_1') | |
| }} | |
| {{ state_attr('sensor.allergy_index_today', 'allergen_name_2') | |
| }} | |
| {{ state_attr('sensor.allergy_index_today', 'allergen_name_3') | |
| }} | |
| response_variable: message | |
| - if: | |
| - condition: person.is_home | |
| target: | |
| entity_id: person.darwin | |
| options: {} | |
| then: | |
| - action: notify.mobile_app_pixel_10_pro | |
| metadata: {} | |
| data: | |
| message: "{{ message.data }}" | |
| - if: | |
| - condition: person.is_home | |
| target: | |
| entity_id: person.sara | |
| options: {} | |
| then: | |
| - action: notify.mobile_app_saras_iphone | |
| metadata: {} | |
| data: | |
| message: "{{ message.data }}" | |
| - conditions: | |
| - condition: state | |
| entity_id: binary_sensor.nice_day | |
| state: | |
| - "off" | |
| - condition: state | |
| entity_id: input_boolean.windows_open | |
| state: | |
| - "on" | |
| - condition: state | |
| entity_id: input_select.day_part | |
| state: | |
| - Morning | |
| - Day | |
| - Evening | |
| - Night | |
| sequence: | |
| - action: ai_task.generate_data | |
| metadata: {} | |
| data: | |
| task_name: Nice Day Message | |
| instructions: >- | |
| Write a short message encouraging the user to close the windows. | |
| Use the following information as justification: | |
| Current temperature: {{ states('sensor.current_temperature') }} | |
| Current humidity: {{ states('sensor.current_humidity') }} | |
| Current allergy (pollen) index on a scale of 0-12: {{ | |
| states('sensor.allergy_index_today') }} | |
| The top 3 allergens today (only Pine is a concern for opening | |
| the windows): | |
| {{ state_attr('sensor.allergy_index_today', 'allergen_name_1') | |
| }} | |
| {{ state_attr('sensor.allergy_index_today', 'allergen_name_2') | |
| }} | |
| {{ state_attr('sensor.allergy_index_today', 'allergen_name_3') | |
| }} | |
| response_variable: message | |
| - if: | |
| - condition: person.is_home | |
| target: | |
| entity_id: person.darwin | |
| options: {} | |
| then: | |
| - action: notify.mobile_app_pixel_10_pro | |
| metadata: {} | |
| data: | |
| message: "{{ message.data }}" | |
| - if: | |
| - condition: person.is_home | |
| target: | |
| entity_id: person.sara | |
| options: {} | |
| then: | |
| - action: notify.mobile_app_saras_iphone | |
| metadata: {} | |
| data: | |
| message: "{{ message.data }}" | |
| mode: single |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment