-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathengine_1switch.yaml
218 lines (200 loc) · 6.75 KB
/
engine_1switch.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# ----------------------------------------------------------------------------------------------------
# User interaction
# ----------------------------------------------------------------------------------------------------
<<: !include engine_common.yaml
switch:
# Define is router is active or not
# When switch is ON, activate power meter (pooling timer will trigger every seconds)
# When switch is OFF, deactivate power meter, turn off divertion and reset counters
- platform: template
name: "Activate Solar Routing"
optimistic: true
restore_mode: RESTORE_DEFAULT_OFF
id: activate
on_turn_on:
then:
- lambda: |-
id(power_meter_activated) = 1;
id(green_led).turn_on();
on_turn_off:
then:
- lambda: |-
id(real_power).publish_state(NAN);
id(consumption).publish_state(NAN);
id(power_meter_activated) = 0;
id(start_tempo_counter).publish_state(NAN);
id(stop_tempo_counter).publish_state(NAN);
id(router_level).publish_state(0);
# Define if energy has to be diverted or not.
# Reset counter, manage router level (0 or 100) and manage LEDs
- platform: template
name: "Energy divertion"
id: energy_divertion
optimistic: True
internal: ${hide_regulators}
on_turn_on:
then:
- script.execute: relay_regulation_control
on_turn_off:
then:
- script.execute: relay_regulation_control
number:
# Router level 0 OR 100
# This value serves two purposes:
# 1. When solar routing is disabled: Acts as a manual control to set the router level
# 2. When solar routing is enabled: Automatically updated to reflect the current router level
# Note: Manual adjustments via slider while routing is enabled are not recommended as they will be
# immediately overridden by the solar router's automatic control
- platform: template
id: router_level
name: "Router Level"
step: 100
min_value: 0
initial_value: 0
max_value: 100
unit_of_measurement: "%"
optimistic: True
on_value:
then:
- if:
condition:
number.in_range:
id: router_level
above: 1
then:
- switch.turn_on: energy_divertion
- lambda: |-
id(start_tempo_counter).publish_state(NAN);
id(stop_tempo_counter).publish_state(NAN);
- light.turn_on:
id: green_led
effect: blink
else:
- switch.turn_off: energy_divertion
- lambda: |-
id(start_tempo_counter).publish_state(NAN);
id(stop_tempo_counter).publish_state(NAN);
- light.turn_off: green_led
- if:
condition:
- switch.is_on: activate
then:
- light.turn_on: green_led
# Define the power level to start divertion
- platform: template
name: "Start power level"
id: start_power_level
optimistic: True
restore_value: True
mode: box
min_value: 0
max_value: 999999
initial_value: 1200
unit_of_measurement: "W"
step: 1
# Define the tempo before closing the relay
- platform: template
name: "Start tempo"
id: start_tempo
optimistic: True
restore_value: True
mode: box
min_value: 0
max_value: 300
initial_value: 10
unit_of_measurement: "s"
step: 1
# Define the power level to stop divertion
- platform: template
name: "Stop power level"
id: stop_power_level
optimistic: True
restore_value: True
mode: box
min_value: 0
max_value: 999999
initial_value: 0
unit_of_measurement: "w"
step: 1
# Define the tempo before oprning the relay
- platform: template
name: "Stop tempo"
id: stop_tempo
optimistic: True
restore_value: True
mode: box
min_value: 0
max_value: 300
initial_value: 10
unit_of_measurement: "s"
step: 1
sensor:
# Sensor tempo decreasing to 0 before starting divertion
- id: start_tempo_counter
platform: template
name: "Start tempo"
unit_of_measurement: "s"
update_interval: 1s
# Sensor tempo decreasing to 0 before stoping divertion
- id: stop_tempo_counter
platform: template
name: "Stop tempo"
unit_of_measurement: "s"
update_interval: 1s
# ----------------------------------------------------------------------------------------------------
# Define scripts for energy regulation
# ----------------------------------------------------------------------------------------------------
script:
# ...
- id: energy_regulation
mode: single
then:
# Energy export is negative
- lambda: |-
if (isnan(id(real_power).state) or id(safety_limit)){
// If we can have information about grid exchange or if safety_limit is active, do not divert any energy
id(router_level).publish_state(0);
return;
}
if (id(real_power).state < -id(start_power_level).state)
{
// Energy divertion is needed
if ( id(router_level).state >= 100 ){
// Energy divertion is already done
id(start_tempo_counter).publish_state(NAN);
return;
}
id(stop_tempo_counter).publish_state(NAN);
if ( isnan(id(start_tempo_counter).raw_state) ){
id(start_tempo_counter).publish_state(id(start_tempo).state);
}
id(start_tempo_counter).publish_state(id(start_tempo_counter).state - 1);
if (id(start_tempo_counter).state <= 0)
{
id(router_level).publish_state(100);
id(start_tempo_counter).publish_state(NAN);
}
return;
}
if (id(real_power).state > -id(stop_power_level).state)
{
// If energy divertion need to be stopped
if (id(router_level).state <= 0){
// Energy divertion is already stopped
id(stop_tempo_counter).publish_state(NAN);
return;
}
id(start_tempo_counter).publish_state(NAN);
if ( isnan(id(stop_tempo_counter).raw_state) ){
id(stop_tempo_counter).publish_state(id(stop_tempo).state);
}
id(stop_tempo_counter).publish_state(id(stop_tempo_counter).state - 1);
if (id(stop_tempo_counter).state <= 0)
{
id(router_level).publish_state(0);
id(stop_tempo_counter).publish_state(NAN);
}
return;
}
id(start_tempo_counter).publish_state(NAN);
id(stop_tempo_counter).publish_state(NAN);