@@ -13,18 +13,19 @@ switch:
13
13
id : activate
14
14
on_turn_on :
15
15
then :
16
- - number.to_min : full_power_timer
17
16
- light.turn_on : green_led
18
17
- lambda : id(power_meter_activated) = 1;
19
18
on_turn_off :
20
19
then :
21
20
- light.turn_off : green_led
22
21
- number.to_min : router_level
23
- - number.to_max : full_power_timer
24
22
- lambda : |-
25
23
id(real_power).publish_state(NAN);
26
24
id(consumption).publish_state(NAN);
25
+ id(bypass_tempo_counter).publish_state(NAN);
27
26
id(power_meter_activated) = 0;
27
+ id(energy_divertion).turn_off();
28
+ id(regulator_opening).publish_state(0);
28
29
# Define the bypass relay
29
30
# When bypass relay is ON, the regulator opening is set to 0
30
31
# When bypass relay is OFF, the regulator opening is set to the value defined by the solar router
@@ -41,6 +42,14 @@ switch:
41
42
then :
42
43
- script.execute : relay_regulation_control
43
44
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
+
44
53
number :
45
54
# Router level from 0 to 100
46
55
# This value serves two purposes:
@@ -59,13 +68,6 @@ number:
59
68
mode : slider
60
69
on_value :
61
70
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
- }
69
71
- if :
70
72
condition :
71
73
number.in_range :
@@ -82,6 +84,8 @@ number:
82
84
- switch.is_on : activate
83
85
then :
84
86
- light.turn_on : green_led
87
+ - script.execute : regulation_control
88
+
85
89
- platform : template
86
90
name : " Regulator Opening"
87
91
id : regulator_opening
@@ -92,24 +96,20 @@ number:
92
96
optimistic : True
93
97
mode : slider
94
98
internal : ${hide_regulators}
95
- on_value :
96
- then :
97
- - script.execute : regulation_control
98
99
99
100
# Define the number of consecutive regulations where regulator is at 100% before activating bypass relay
100
101
# 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
102
103
# Counter is reset to 0 when regulator is not at 100% or when delta is negative
103
104
- platform : template
104
- name : " Full Power Timer "
105
- id : full_power_timer
105
+ name : " Full power duration before bypass "
106
+ id : full_power_duration
106
107
optimistic : True
107
108
min_value : 0
108
- max_value : ${bypass_timer_threshold}
109
+ max_value : 300
109
110
step : 1
110
- initial_value : 0
111
- restore_value : False
112
- internal : True
111
+ initial_value : 30
112
+ restore_value : True
113
113
114
114
# Define the reactivity of router level
115
115
- platform : template
@@ -158,7 +158,7 @@ script:
158
158
// Safety check: Disable regulation if power readings are invalid or safety is triggered
159
159
if (isnan(id(real_power).state) or id(safety_limit)){
160
160
id(router_level).publish_state(0);
161
- id(full_power_timer ).publish_state(0 );
161
+ id(bypass_tempo_counter ).publish_state(NAN );
162
162
return;
163
163
}
164
164
@@ -170,7 +170,24 @@ script:
170
170
id(router_level).publish_state(new_router_level);
171
171
172
172
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();
174
189
} 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);
176
192
}
193
+
0 commit comments