Skip to content

Commit ef44aa2

Browse files
committed
fix: triac regulation
1 parent aaef655 commit ef44aa2

File tree

1 file changed

+25
-24
lines changed

1 file changed

+25
-24
lines changed

solar_router/engine_progressive_with_bypass.yaml

+25-24
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ switch:
2626
id(power_meter_activated) = 0;
2727
id(energy_divertion).turn_off();
2828
id(regulator_opening).publish_state(0);
29-
- script.execute: relay_regulation_control
29+
- script.execute: energy_regulation
3030

3131
# Define the bypass relay
3232
# When bypass relay is ON, the regulator opening is set to 0
@@ -92,9 +92,11 @@ number:
9292
- switch.is_on: activate
9393
then:
9494
- light.turn_on: green_led
95-
- script.execute: energy_regulation
96-
97-
95+
- if:
96+
condition:
97+
- lambda: return id(power_meter_activated) == 0;
98+
then:
99+
- script.execute: energy_regulation
98100

99101
# Define the number of consecutive regulations where regulator is at 100% before activating bypass relay
100102
# When regulator is at 100% and delta is still positive, this counter is incremented
@@ -162,25 +164,18 @@ script:
162164
return;
163165
}
164166
165-
// Calculate the power difference and adjust the regulator opening percentage
166-
double delta = 0;
167+
// If router is activated, calculate the power difference and adjust the regulator opening percentage
167168
if ((id(power_meter_activated) == 1))
168169
{
170+
double delta = 0;
169171
delta = -1*(id(real_power).state-id(target_grid_exchange).state)*id(reactivity).state/1000;
170-
}
171-
// Determine the new regulator status
172-
double new_router_level = id(router_level).state + delta;
173-
new_router_level = std::max(0.0, std::min(100.0, new_router_level));
174-
id(router_level).publish_state(new_router_level);
175-
176-
if (new_router_level >= 100.0)
177-
{
178-
if ((id(power_meter_activated) == 0))
179-
{
180-
// If automatic regulation is off and user push to router level to 100%, bypass is activated immadiately
181-
id(bypass_tempo_counter).publish_state(0);
182-
}
183-
else
172+
173+
// Determine the new regulator status
174+
double new_router_level = id(router_level).state + delta;
175+
new_router_level = std::max(0.0, std::min(100.0, new_router_level));
176+
id(router_level).publish_state(new_router_level);
177+
178+
if (new_router_level >= 100.0)
184179
{
185180
if ( isnan( id(bypass_tempo_counter).state ) )
186181
{
@@ -193,11 +188,16 @@ script:
193188
id(bypass_tempo_counter).publish_state(id(bypass_tempo_counter).state - 1);
194189
}
195190
}
191+
}
192+
else
193+
{
194+
id(bypass_tempo_counter).publish_state(NAN);
196195
}
197-
}
198-
else
196+
}
197+
else
199198
{
200-
id(bypass_tempo_counter).publish_state(NAN);
199+
// If automatic regulation is off, do not manage bypass tempo
200+
id(bypass_tempo_counter).publish_state(0);
201201
}
202202
203203
if ( (id(router_level).state >= 100.0) && (id(bypass_tempo_counter).state == 0) )
@@ -214,4 +214,5 @@ script:
214214
switch.is_on: energy_divertion
215215
then:
216216
lambda: id(regulator_opening).publish_state(0.0);
217-
- script.execute: relay_regulation_control
217+
- script.execute: relay_regulation_control
218+
- script.execute: regulation_control

0 commit comments

Comments
 (0)