@@ -26,7 +26,7 @@ switch:
26
26
id(power_meter_activated) = 0;
27
27
id(energy_divertion).turn_off();
28
28
id(regulator_opening).publish_state(0);
29
- - script.execute : relay_regulation_control
29
+ - script.execute : energy_regulation
30
30
31
31
# Define the bypass relay
32
32
# When bypass relay is ON, the regulator opening is set to 0
@@ -92,9 +92,11 @@ number:
92
92
- switch.is_on : activate
93
93
then :
94
94
- 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
98
100
99
101
# Define the number of consecutive regulations where regulator is at 100% before activating bypass relay
100
102
# When regulator is at 100% and delta is still positive, this counter is incremented
@@ -162,25 +164,18 @@ script:
162
164
return;
163
165
}
164
166
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
167
168
if ((id(power_meter_activated) == 1))
168
169
{
170
+ double delta = 0;
169
171
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)
184
179
{
185
180
if ( isnan( id(bypass_tempo_counter).state ) )
186
181
{
@@ -193,11 +188,16 @@ script:
193
188
id(bypass_tempo_counter).publish_state(id(bypass_tempo_counter).state - 1);
194
189
}
195
190
}
191
+ }
192
+ else
193
+ {
194
+ id(bypass_tempo_counter).publish_state(NAN);
196
195
}
197
- }
198
- else
196
+ }
197
+ else
199
198
{
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);
201
201
}
202
202
203
203
if ( (id(router_level).state >= 100.0) && (id(bypass_tempo_counter).state == 0) )
@@ -214,4 +214,5 @@ script:
214
214
switch.is_on : energy_divertion
215
215
then :
216
216
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