From b12c49f07f0bb2d1de05ed70b77a38e80d927213 Mon Sep 17 00:00:00 2001 From: Xavier Berger Date: Sun, 2 Feb 2025 17:57:54 +0100 Subject: [PATCH] fix: Manage manual usage when regulation is off and immediatly activate bypass if 100% is requested --- .../engine_progressive_with_bypass.yaml | 48 +++++++++++++------ 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/solar_router/engine_progressive_with_bypass.yaml b/solar_router/engine_progressive_with_bypass.yaml index c2397ca..da39972 100644 --- a/solar_router/engine_progressive_with_bypass.yaml +++ b/solar_router/engine_progressive_with_bypass.yaml @@ -18,8 +18,8 @@ switch: on_turn_off: then: - light.turn_off: green_led - - number.to_min: router_level - lambda: |- + id(router_level).publish_state(0); id(real_power).publish_state(NAN); id(consumption).publish_state(NAN); id(bypass_tempo_counter).publish_state(NAN); @@ -92,7 +92,7 @@ number: - switch.is_on: activate then: - light.turn_on: green_led - - script.execute: regulation_control + - script.execute: energy_regulation @@ -154,38 +154,58 @@ script: # Define the reouter level based on power measured and grid exchange target # The value of regulator is a precentage and is then limited to the range 0 100 - lambda: |- - // Safety check: Disable regulation if power readings are invalid or safety is triggered - if (isnan(id(real_power).state) or id(safety_limit)){ + // Safety check: Disable automatic regulation if power readings are invalid or safety is triggered + if ((id(power_meter_activated) == 1) and ( isnan(id(real_power).state)) or id(safety_limit)) + { id(router_level).publish_state(0); id(bypass_tempo_counter).publish_state(NAN); return; } // Calculate the power difference and adjust the regulator opening percentage - double delta = -1*(id(real_power).state-id(target_grid_exchange).state)*id(reactivity).state/1000; + double delta = 0; + if ((id(power_meter_activated) == 1)) + { + delta = -1*(id(real_power).state-id(target_grid_exchange).state)*id(reactivity).state/1000; + } // Determine the new regulator status double new_router_level = id(router_level).state + delta; new_router_level = std::max(0.0, std::min(100.0, new_router_level)); id(router_level).publish_state(new_router_level); - if (new_router_level >= 100.0) { - if ( isnan( id(bypass_tempo_counter).state ) ) { - id(bypass_tempo_counter).publish_state(id(full_power_duration).state); - } + if (new_router_level >= 100.0) + { + if ((id(power_meter_activated) == 0)) + { + // If automatic regulation is off and user push to router level to 100%, bypass is activated immadiately + id(bypass_tempo_counter).publish_state(0); + } else { - if (id(bypass_tempo_counter).state > 0 ) + if ( isnan( id(bypass_tempo_counter).state ) ) { - id(bypass_tempo_counter).publish_state(id(bypass_tempo_counter).state - 1); + id(bypass_tempo_counter).publish_state(id(full_power_duration).state); + } + else + { + if (id(bypass_tempo_counter).state > 0 ) + { + id(bypass_tempo_counter).publish_state(id(bypass_tempo_counter).state - 1); + } } } - } else { + } + else + { id(bypass_tempo_counter).publish_state(NAN); } - if ( (id(router_level).state >= 100.0) && (id(bypass_tempo_counter).state == 0) ) { + if ( (id(router_level).state >= 100.0) && (id(bypass_tempo_counter).state == 0) ) + { id(energy_divertion).turn_on(); - } else { + } + else + { id(energy_divertion).turn_off(); id(regulator_opening).publish_state(id(router_level).state); }