diff --git a/blueprints/automation/wd-close-weather-notification.yaml b/blueprints/automation/wd-close-weather-notification.yaml index 9bf5659..2e4bdfe 100644 --- a/blueprints/automation/wd-close-weather-notification.yaml +++ b/blueprints/automation/wd-close-weather-notification.yaml @@ -1,164 +1,166 @@ blueprint: - name: Open Windows/Doors Weather Notification + name: "Open Windows/Doors Weather Notification" description: >- - Sends a notification if selected windows or doors are open when the weather changes - to a specific state (e.g., raining) or the temperature crosses a set threshold. + Sends notifications when windows/doors are open during specific weather conditions + or temperature thresholds. domain: automation input: openings: name: Windows & Doors - description: Select all windows and doors you want to monitor. - selector: - entity: - domain: binary_sensor - device_class: - - door - - window - - opening - multiple: true - - notify_target: - name: Notification Target - description: Select the device, group, or service to send the notification to. + description: Select all windows and doors to monitor selector: target: + entity: + domain: binary_sensor + device_class: + - door + - window + - opening - # --- Optional Weather Trigger --- - weather_sensor: - name: (Optional) Weather Sensor - description: The weather entity to monitor (e.g., weather.home). + notify_service: + name: Notification Service + description: The notification service to use (e.g., notify.mobile_app_phone) + selector: + text: + + # Weather Trigger Section + weather_entity: + name: Weather Entity + description: Weather entity to monitor (e.g., weather.home) selector: entity: domain: weather - default: + required: false - weather_trigger_states: - name: Weather Trigger States - description: If a weather sensor is selected, notify when the weather changes to any of these states. + weather_states: + name: Trigger Weather States + description: Notify when weather changes to any of these states selector: select: multiple: true options: - - "cloudy" - - "fog" - - "hail" - - "lightning" - - "lightning-rainy" - - "partlycloudy" - - "pouring" - - "rainy" - - "snowy" - - "snowy-rainy" - - "sunny" - - "windy" - - "windy-variant" - - "exceptional" + - clear-night + - cloudy + - exceptional + - fog + - hail + - lightning + - lightning-rainy + - partlycloudy + - pouring + - rainy + - snowy + - snowy-rainy + - sunny + - windy + - windy-variant default: ["rainy", "pouring", "snowy"] - # --- Optional Temperature Trigger --- + # Temperature Trigger Section temperature_sensor: - name: (Optional) Temperature Sensor - description: The temperature sensor to monitor (e.g., sensor.outside_temperature). + name: Temperature Sensor + description: Temperature sensor to monitor (e.g., sensor.outside_temperature) selector: entity: domain: sensor device_class: temperature - default: + required: false - temp_above: - name: Notify if Temperature is Above - description: Trigger a notification if the temperature rises above this value. + temp_high_threshold: + name: High Temperature Threshold + description: Notify if temperature exceeds this value selector: number: min: -20 - max: 40 - unit_of_measurement: "°C" + max: 50 + step: 0.5 + unit_of_measurement: °C + mode: box default: 25 - temp_below: - name: Notify if Temperature is Below - description: Trigger a notification if the temperature drops below this value. + temp_low_threshold: + name: Low Temperature Threshold + description: Notify if temperature drops below this value selector: number: min: -20 - max: 40 - unit_of_measurement: "°C" + max: 50 + step: 0.5 + unit_of_measurement: °C + mode: box default: 10 -# --- Triggers --- -# The automation will run when any of these conditions are met. trigger: - # 1. Trigger when the weather sensor's state changes. + # Weather state change trigger - platform: state - entity_id: !input weather_sensor + entity_id: !input weather_entity id: weather_change + if: | + {{ is_state_attr(trigger.entity_id, 'state', '') == false }} - # 2. Trigger when temperature goes above the threshold. + # Temperature triggers - platform: numeric_state entity_id: !input temperature_sensor - above: !input temp_above - id: temp_hot + above: !input temp_high_threshold + id: temp_high - # 3. Trigger when temperature goes below the threshold. - platform: numeric_state entity_id: !input temperature_sensor - below: !input temp_below - id: temp_cold + below: !input temp_low_threshold + id: temp_low -# --- Conditions --- -# The action will only run if ALL of these conditions are true. condition: - # 1. Check if an input was actually provided for the trigger that ran. - - condition: template - value_template: >- - {{ (trigger.id == 'weather_change' and iif(states(input_weather_sensor), true, false)) or - (trigger.id in ['temp_hot', 'temp_cold'] and iif(states(input_temperature_sensor), true, false)) }} + # Check if any of the monitored openings are open + - condition: or + conditions: + - condition: state + entity_id: "{{ trigger.entity_id }}" + state: 'on' + for: '00:00:05' - # 2. Check if at least one of the selected doors/windows is 'on' (open). - - condition: template - value_template: "{{ expand(input_openings) | selectattr('state', 'eq', 'on') | list | count > 0 }}" - -# --- Actions --- -# What the automation will do when triggered and conditions are met. action: - # Define variables to use in the message. - variables: - open_entities: "{{ expand(input_openings) | selectattr('state', 'eq', 'on') | map(attribute='name') | list }}" - open_count: "{{ open_entities | count }}" - # Use 'choose' to run different actions based on what triggered the automation. + open_entities: > + {{ expand('binary_sensor') | selectattr('state', 'eq', 'on') | + selectattr('entity_id', 'in', input_openings.entity) | + map(attribute='name') | list }} + open_count: "{{ open_entities | length }}" + - choose: - # Case 1: Weather changed - conditions: - condition: trigger id: weather_change - # Also check if the new weather state is in our list of trigger states - condition: template - value_template: "{{ trigger.to_state.state in input_weather_trigger_states }}" + value_template: >- + {{ state_attr(trigger.entity_id, 'state') in input_weather_states }} sequence: - - service: notify.notify + - service: "{{ input.notify_service }}" data: - target: !input notify_target - message: "It's {{ trigger.to_state.state }} outside! {{ open_count }} opening(s) are open: {{ open_entities | join(', ') }}." - title: "Open Window/Door Alert" + message: >- + Weather alert: {{ state_attr(trigger.entity_id, 'state') | title }} + detected with {{ open_count }} opening(s) open: {{ open_entities | join(', ') }} + title: "Openings Alert" - # Case 2: Temperature is too high - conditions: - condition: trigger - id: temp_hot + id: temp_high sequence: - - service: notify.notify + - service: "{{ input.notify_service }}" data: - target: !input notify_target - message: "It's getting warm ({{ states(input_temperature_sensor) }}°C)! {{ open_count }} opening(s) are open: {{ open_entities | join(', ') }}." - title: "Open Window/Door Alert" + message: >- + High temperature ({{ states(input.temperature_sensor) }}°C) detected + with {{ open_count }} opening(s) open: {{ open_entities | join(', ') }} + title: "High Temperature Alert" - # Case 3: Temperature is too low - conditions: - condition: trigger - id: temp_cold + id: temp_low sequence: - - service: notify.notify + - service: "{{ input.notify_service }}" data: - target: !input notify_target - message: "It's getting cold ({{ states(input_temperature_sensor) }}°C)! {{ open_count }} opening(s) are open: {{ open_entities | join(', ') }}." - title: "Open Window/Door Alert" \ No newline at end of file + message: >- + Low temperature ({{ states(input.temperature_sensor) }}°C) detected + with {{ open_count }} opening(s) open: {{ open_entities | join(', ') }} + title: "Low Temperature Alert" + +mode: single