From dfe891345d788bc2db58b021ee51c0aceacc3d82 Mon Sep 17 00:00:00 2001 From: ltadeu6 Date: Sun, 17 May 2026 15:06:43 -0300 Subject: [PATCH] Handle AC power transitions --- AGENTS.md | 1 + hosts/Nixos/configuration.nix | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 08f5e12..96c0af3 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -622,6 +622,7 @@ Estado atual: - O tempo maximo de execucao e 6 horas; ao expirar, o script desliga `climate.ar` e desliga `input_boolean.secar_roupas`. - Fan mode e definido apenas se o valor existir em `state_attr('climate.ar', 'fan_modes')`; a integracao atual aceita niveis numericos `1..5`. - O script usa fan `3` no `dry`, fan `4` no `cool` e fan `5` no `heat`, sempre com fallback para um nivel abaixo. +- Apos trocar `hvac_mode`, o script espera 10 segundos antes de setpoint/fan para evitar comandos rejeitados durante `POWER_ON`. Cuidados: diff --git a/hosts/Nixos/configuration.nix b/hosts/Nixos/configuration.nix index 7728407..6d38178 100644 --- a/hosts/Nixos/configuration.nix +++ b/hosts/Nixos/configuration.nix @@ -22,10 +22,20 @@ let haSetFanMode = fan_mode: haClimateAction "climate.set_fan_mode" { inherit fan_mode; }; haTurnOffClimate = haClimateAction "climate.turn_off" { }; + haTurnOffClimateIfOn = { + choose = [{ + conditions = [{ + condition = "template"; + value_template = "{{ not is_state('${haAirConditioner}', 'off') }}"; + }]; + sequence = [ haTurnOffClimate ]; + }]; + }; haTurnOffDryingToggle = { action = "input_boolean.turn_off"; target.entity_id = haLaundryDryingToggle; }; + haWaitForClimateReady = { delay = "00:00:10"; }; haWaitForDryingToggleOff = timeout: { wait_template = "{{ is_state('${haLaundryDryingToggle}', 'off') }}"; inherit timeout; @@ -53,25 +63,30 @@ let }; haDryCycle = [ (haSetHvacMode "dry") + haWaitForClimateReady (haSetFanModeIfAvailable "3" "2") ]; haHeatEvaporationCycle = [ (haSetHvacMode "heat") + haWaitForClimateReady (haSetTemperature 25) (haSetFanModeIfAvailable "5" "4") ]; haHeatRecoveryCycle = [ (haSetHvacMode "heat") + haWaitForClimateReady (haSetTemperature 24) (haSetFanModeIfAvailable "5" "4") ]; haCoolPulse = [ (haSetHvacMode "cool") + haWaitForClimateReady (haSetTemperature 22) (haSetFanModeIfAvailable "4" "3") ]; haHotRoomCoolPulse = [ (haSetHvacMode "cool") + haWaitForClimateReady (haSetTemperature 23) (haSetFanModeIfAvailable "4" "3") ]; @@ -450,7 +465,7 @@ in { ]; }; } - haTurnOffClimate + haTurnOffClimateIfOn { choose = [{ conditions = [{ @@ -486,7 +501,7 @@ in { entity_id = haLaundryDryingToggle; to = "off"; }]; - action = [ haTurnOffClimate ]; + action = [ haTurnOffClimateIfOn ]; } ];