Skip to content

Commit 78b9b07

Browse files
committed
feat: Manage bypass countdown
1 parent 7c8fda2 commit 78b9b07

File tree

2 files changed

+41
-23
lines changed

2 files changed

+41
-23
lines changed

esp8266-proxy-client.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ substitutions:
4242
power_meter_ip_address: "192.168.1.28"
4343

4444
# Regulator configuration
45-
# Define GPIO pin connected to AC Dimmer for gate and zero crossing detection.
45+
# Define GPIO pin connected to AC Dimmer for gate
4646
regulator_gate_pin: GPIO4
4747

4848
# LEDs -------------------------------------------------------------------------
@@ -53,6 +53,7 @@ substitutions:
5353

5454
relay_regulator_gate_pin: GPIO0
5555
bypass_timer_threshold: "30"
56+
hide_regulators: "False"
5657

5758
packages:
5859
power_meter:

solar_router/engine_progressive_with_bypass.yaml

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,19 @@ switch:
1313
id: activate
1414
on_turn_on:
1515
then:
16-
- number.to_min: full_power_timer
1716
- light.turn_on: green_led
1817
- lambda: id(power_meter_activated) = 1;
1918
on_turn_off:
2019
then:
2120
- light.turn_off: green_led
2221
- number.to_min: router_level
23-
- number.to_max: full_power_timer
2422
- lambda: |-
2523
id(real_power).publish_state(NAN);
2624
id(consumption).publish_state(NAN);
25+
id(bypass_tempo_counter).publish_state(NAN);
2726
id(power_meter_activated) = 0;
27+
id(energy_divertion).turn_off();
28+
id(regulator_opening).publish_state(0);
2829
# Define the bypass relay
2930
# When bypass relay is ON, the regulator opening is set to 0
3031
# When bypass relay is OFF, the regulator opening is set to the value defined by the solar router
@@ -41,6 +42,14 @@ switch:
4142
then:
4243
- script.execute: relay_regulation_control
4344

45+
sensor:
46+
# Sensor tempo decreasing to 0 before starting divertion
47+
- id: bypass_tempo_counter
48+
platform: template
49+
name: "Bypass tempo"
50+
unit_of_measurement: "s"
51+
update_interval: 1s
52+
4453
number:
4554
# Router level from 0 to 100
4655
# This value serves two purposes:
@@ -59,13 +68,6 @@ number:
5968
mode: slider
6069
on_value:
6170
then:
62-
- lambda: |-
63-
if (id(router_level).state >= 100.0 && id(full_power_timer).state >= ${bypass_timer_threshold}) {
64-
id(energy_divertion).turn_on();
65-
} else {
66-
id(energy_divertion).turn_off();
67-
id(regulator_opening).publish_state(id(router_level).state);
68-
}
6971
- if:
7072
condition:
7173
number.in_range:
@@ -82,6 +84,8 @@ number:
8284
- switch.is_on: activate
8385
then:
8486
- light.turn_on: green_led
87+
- script.execute: regulation_control
88+
8589
- platform: template
8690
name: "Regulator Opening"
8791
id: regulator_opening
@@ -92,24 +96,20 @@ number:
9296
optimistic: True
9397
mode: slider
9498
internal: ${hide_regulators}
95-
on_value:
96-
then:
97-
- script.execute: regulation_control
9899

99100
# Define the number of consecutive regulations where regulator is at 100% before activating bypass relay
100101
# When regulator is at 100% and delta is still positive, this counter is incremented
101-
# When counter reach bypass_timer_threshold, bypass relay is activated
102+
# When counter reach full_power_duration, bypass relay is activated
102103
# Counter is reset to 0 when regulator is not at 100% or when delta is negative
103104
- platform: template
104-
name: "Full Power Timer"
105-
id: full_power_timer
105+
name: "Full power duration before bypass"
106+
id: full_power_duration
106107
optimistic: True
107108
min_value: 0
108-
max_value: ${bypass_timer_threshold}
109+
max_value: 300
109110
step: 1
110-
initial_value: 0
111-
restore_value: False
112-
internal: True
111+
initial_value: 30
112+
restore_value: True
113113

114114
# Define the reactivity of router level
115115
- platform: template
@@ -158,7 +158,7 @@ script:
158158
// Safety check: Disable regulation if power readings are invalid or safety is triggered
159159
if (isnan(id(real_power).state) or id(safety_limit)){
160160
id(router_level).publish_state(0);
161-
id(full_power_timer).publish_state(0);
161+
id(bypass_tempo_counter).publish_state(NAN);
162162
return;
163163
}
164164
@@ -170,7 +170,24 @@ script:
170170
id(router_level).publish_state(new_router_level);
171171
172172
if (new_router_level >= 100.0) {
173-
id(full_power_timer).publish_state(id(full_power_timer).state + 1);
173+
if ( isnan( id(bypass_tempo_counter).state ) ) {
174+
id(bypass_tempo_counter).publish_state(id(full_power_duration).state);
175+
}
176+
else
177+
{
178+
if (id(bypass_tempo_counter).state > 0 )
179+
{
180+
id(bypass_tempo_counter).publish_state(id(bypass_tempo_counter).state - 1);
181+
}
182+
}
183+
} else {
184+
id(bypass_tempo_counter).publish_state(NAN);
185+
}
186+
187+
if ( (id(router_level).state >= 100.0) && (id(bypass_tempo_counter).state == 0) ) {
188+
id(energy_divertion).turn_on();
174189
} else {
175-
id(full_power_timer).publish_state(0);
190+
id(energy_divertion).turn_off();
191+
id(regulator_opening).publish_state(id(router_level).state);
176192
}
193+

0 commit comments

Comments
 (0)