Skip to content

Commit

Permalink
fix: Manage manual usage when regulation is off and immediatly activa…
Browse files Browse the repository at this point in the history
…te bypass if 100% is requested
  • Loading branch information
XavierBerger committed Feb 2, 2025
1 parent bbdf1cc commit b12c49f
Showing 1 changed file with 34 additions and 14 deletions.
48 changes: 34 additions & 14 deletions solar_router/engine_progressive_with_bypass.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -92,7 +92,7 @@ number:
- switch.is_on: activate
then:
- light.turn_on: green_led
- script.execute: regulation_control
- script.execute: energy_regulation



Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit b12c49f

Please sign in to comment.