From 511b83fc712b104de0e2c6e1668bc7f8ef6a5b92 Mon Sep 17 00:00:00 2001 From: Carlo Costanzo Date: Tue, 24 Nov 2026 15:38:23 -0500 Subject: [PATCH] Coordinate humidity cycles and HVAC alerts around open doors --- config/custom_templates/downstairs_hvac.jinja | 10 +- config/packages/alarm.yaml | 21 ++-- config/packages/climate.yaml | 110 +++++++++++++----- config/script/downstairs_hvac.yaml | 6 + config/script/hvac_control.yaml | 11 ++ 5 files changed, 118 insertions(+), 40 deletions(-) diff --git a/config/custom_templates/downstairs_hvac.jinja b/config/custom_templates/downstairs_hvac.jinja index e95213d7..fbfab2dc 100644 --- a/config/custom_templates/downstairs_hvac.jinja +++ b/config/custom_templates/downstairs_hvac.jinja @@ -10,7 +10,7 @@ (preset == 'eco' or target == expected.get('temperature'))))) | to_json }} {%- endmacro %} -{% macro downstairs_policy() -%} +{% macro downstairs_policy(drying=none) -%} {% set stamp = as_timestamp(now()) %} {% set expected = states('input_text.downstairs_hvac_expected') | from_json({}) %} {% set hold = states('input_text.downstairs_hvac_override') | from_json({}) %} @@ -58,6 +58,14 @@ {% elif held and hold.get('kind') == 'temperature' %} {% set ns.target = hold.get('temperature', ns.target) %} {% set ns.reason = 'manual temperature' %} + {% elif not guest and is_state('group.family', 'home') and + (is_state('timer.downstairs_humidity_cycle', 'active') if drying is none else drying) %} + {% set humidity = states('sensor.downstairs_humidity') | float(none) %} + {% set room = states('sensor.downstairs_temperature') | float(none) %} + {% if humidity is not none and 58 < humidity <= 100 and room is not none and room > 75 %} + {% set ns.target = 75 %} + {% set ns.reason = 'humidity cycle' %} + {% endif %} {% endif %} {{ dict(valid=ns.valid, mode=ns.mode, preset=ns.preset, temperature=ns.target if ns.mode == 'cool' and ns.preset == 'none' else none, diff --git a/config/packages/alarm.yaml b/config/packages/alarm.yaml index 1645ee7a..3887bc31 100755 --- a/config/packages/alarm.yaml +++ b/config/packages/alarm.yaml @@ -10,6 +10,7 @@ # Alarm sensors, customization, and automations for home security. # ------------------------------------------------------------------- # Notes: Turns HVAC off when doors/windows are open and restores cool mode after closure (weather-gated for downstairs). +# Notes: Speaks once when HVAC is paused per continuous opening; closing is quiet. ###################################################################### homeassistant: customize_glob: @@ -265,17 +266,19 @@ automation: - service: script.reconcile_hvac_state data: reason: "entry point left open" - - service: script.speech_engine + # Leave reconciliation eligible for later openings; gate only speech. + - condition: state + entity_id: group.entry_points + state: 'on' + - condition: template + value_template: >- + {{ as_timestamp(this.attributes.last_triggered, 0) + < as_timestamp(states.group.entry_points.last_changed) }} + - action: script.speech_engine data: value1: >- - {% set opening = state_attr(trigger.entity_id, "friendly_name")%} - {%- macro opening_sentence(opening) -%} - {{"Since the " ~ opening +" has been left open, I will turn off the air conditioners until you close it" }} - [Give a snarky reason for this action] - {%- endmacro -%} - {{opening_sentence(opening)}} - call_outside_weather: 1 - call_inside_weather: 1 + Pausing the HVAC while the {{ trigger.to_state.name }} is open. + [Say only one short sentence about the HVAC pause. Skip greetings and other updates.] #-------------------------------------------#------------------------------------------- - alias: 'Turn HVAC back on when all doors/windows are closed.' id: 66833291-c504-4651-aac9-3cdbf98d20ea diff --git a/config/packages/climate.yaml b/config/packages/climate.yaml index b4ae55ec..c4d8e617 100644 --- a/config/packages/climate.yaml +++ b/config/packages/climate.yaml @@ -18,9 +18,12 @@ # holds last until bedtime or 08:00; manual Off lasts until resumed. # Notes: Restoring helpers retain the bed period, manual intent and verified # command fingerprint because Nest exposes none of that ownership metadata. +# Notes: After one hour above 60% RH, allow a 20-minute drying cycle, at most once per two hours. +# Stop at 58% RH or 75F and reconcile the current schedule. Manual and safety rules take priority. # Notes: Fresh-air opportunities can notify while downstairs cooling is idle or running, before sunset. # One daily passive parents push uses a stable tag; the notice clears when # conditions stop qualifying. Helpers preserve daily allowance and active notice. +# Notes: Per-thermostat speech is quiet while an entry point is open and for 10 minutes after all close. # Notes: Filter history helpers restore across restarts; reset scripts seed the prior input_datetime when history is empty. # Notes: The snooze notification pattern is also covered at https://youtu.be/y47KSflS1aw. # Video: https://youtu.be/nScl2JxYSB8 @@ -263,6 +266,12 @@ input_boolean: name: Fresh Air Notice Active icon: mdi:window-open-variant +timer: + downstairs_humidity_cycle: + name: Downstairs Humidity Cycle + duration: "00:20:00" + restore: true + input_select: downstairs_hvac_period: name: Downstairs HVAC Bed Period @@ -729,22 +738,38 @@ automation: - alias: 'AC Status Announcement' id: 7812fdaf-a3f8-498b-8f07-28e977e528fe + mode: queued + max: 10 trigger: - - platform: state + - trigger: state entity_id: - climate.downstairs - climate.upstairs from: 'off' - - platform: state + to: [cool, heat, heat_cool] + - trigger: state entity_id: - climate.downstairs - climate.upstairs + from: [cool, heat, heat_cool] to: 'off' action: - - service: script.speech_engine + # Covers both the 5-minute close timer and time for the thermostats to settle. + - condition: state + entity_id: group.entry_points + state: 'off' + for: "00:10:00" + - action: script.speech_engine data: - NestStatus: "The {{ trigger.entity_id.split('.')[1].split('_')[0]}} {{ trigger.entity_id.split('.')[1].split('_')[1]}} has now been turned on for {{(trigger.to_state.state)}}." - call_window_check: 1 + value1: >- + {% set location = state_attr(trigger.entity_id, 'friendly_name') | default(trigger.entity_id.split('.')[1], true) %} + {% set mode = trigger.to_state.state %} + {% if mode == 'off' %} + The {{ location }} thermostat is now set to off. + {% else %} + The {{ location }} thermostat is now set to {{ 'heat and cool' if mode == 'heat_cool' else mode }} mode. + This describes the thermostat setting; it does not say the system is running. + {% endif %} - alias: Prevent Upstairs Nest Below 76 id: 7812fdaf-a3f8-498b-8f07-28e977e528ff @@ -859,6 +884,21 @@ automation: entity_id: climate.downstairs from: unavailable id: recovery + - trigger: state + entity_id: timer.downstairs_humidity_cycle + to: ['active', 'idle'] + - trigger: state + entity_id: + - sensor.downstairs_humidity + - sensor.downstairs_temperature + - group.entry_points + - group.family + - binary_sensor.powerwall_grid_status + to: null + id: drying_input + conditions: + - condition: template + value_template: "{{ trigger.id != 'drying_input' or is_state('timer.downstairs_humidity_cycle', 'active') }}" action: - if: - condition: trigger @@ -977,30 +1017,40 @@ automation: - alias: 'Humidity Control' id: AC_Humidity_Control + description: Start a bounded downstairs drying cycle after an uninterrupted hour above 60% RH. mode: single - trigger: - - platform: numeric_state - entity_id: sensor.downstairs_humidity - above: 60 - - platform: time - at: "02:00:00" - condition: - - condition: time - after: "01:00:00" - before: "08:00:00" - - condition: numeric_state - entity_id: sensor.downstairs_humidity - above: 60 - - condition: template #Only needed in the winter months - value_template: "{{ now().month in [10, 11, 12, 1, 2, 3] }}" - - condition: template # Only run if AC is idle (prevents fighting other automations) - value_template: "{{ state_attr('climate.downstairs', 'hvac_action') == 'idle' }}" - - condition: template # Never run if the grid is down and running on powerwall. - value_template: "{{ states('binary_sensor.powerwall_grid_status')|lower == 'on' }}" + triggers: + - trigger: time_pattern + minutes: "*" + conditions: - condition: state - entity_id: group.entry_points - state: 'off' - action: - - action: script.reconcile_downstairs_hvac - data: - reason: humidity review within bed and manual comfort limits + entity_id: timer.downstairs_humidity_cycle + state: idle + - condition: template + value_template: >- + {{ as_timestamp(now()) - as_timestamp(this.attributes.get('last_triggered'), 0) >= 7200 }} + - condition: state + entity_id: climate.downstairs + attribute: hvac_action + state: idle + - condition: humidity.is_value + target: + entity_id: sensor.downstairs_humidity + options: + threshold: + type: above + value: + number: 60 + for: + hours: 1 + - condition: template + value_template: >- + {% from 'downstairs_hvac.jinja' import downstairs_matches, downstairs_policy %} + {% set expected = states('input_text.downstairs_hvac_expected') | from_json({}) %} + {{ expected.get('confirmed', false) and as_timestamp(now()) >= expected.get('settle_until', 0) + and (downstairs_matches(expected) | from_json) + and (downstairs_policy(drying=true) | from_json).reason == 'humidity cycle' }} + actions: + - action: timer.start + target: + entity_id: timer.downstairs_humidity_cycle diff --git a/config/script/downstairs_hvac.yaml b/config/script/downstairs_hvac.yaml index e39ff6d6..4115ed85 100644 --- a/config/script/downstairs_hvac.yaml +++ b/config/script/downstairs_hvac.yaml @@ -63,6 +63,12 @@ reconcile_downstairs_hvac: {% from 'downstairs_hvac.jinja' import downstairs_policy %} {{ downstairs_policy() | from_json }} expected: "{{ states('input_text.downstairs_hvac_expected') | from_json({}) }}" + # End the drying request as soon as comfort, manual intent, or safety takes priority. + - if: "{{ is_state('timer.downstairs_humidity_cycle', 'active') and desired.reason != 'humidity cycle' }}" + then: + - action: timer.cancel + target: + entity_id: timer.downstairs_humidity_cycle - condition: template value_template: "{{ desired.valid }}" - variables: diff --git a/config/script/hvac_control.yaml b/config/script/hvac_control.yaml index d9af6cbd..21f0c714 100644 --- a/config/script/hvac_control.yaml +++ b/config/script/hvac_control.yaml @@ -24,6 +24,11 @@ reconcile_hvac_state: - action: script.turn_on target: entity_id: script.reconcile_downstairs_hvac + # A group can appear after presence during startup; never treat missing as closed. + # Grid-off must still bypass this wait so the safety shutoff is immediate. + - wait_template: >- + {{ states('group.entry_points') in ['on', 'off'] + or is_state('binary_sensor.powerwall_grid_status', 'off') }} - choose: - conditions: - condition: state @@ -59,6 +64,9 @@ reconcile_hvac_state: entity_id: input_boolean.guest_mode state: 'off' sequence: + - condition: state + entity_id: group.entry_points + state: 'off' - service: climate.set_hvac_mode target: entity_id: climate.upstairs @@ -74,6 +82,9 @@ reconcile_hvac_state: topic: "CLIMATE" message: "HVAC reconciled to away targets ({{ reconcile_reason }})." default: + - condition: state + entity_id: group.entry_points + state: 'off' - service: climate.set_hvac_mode target: entity_id: climate.upstairs