Skip to content

Commit e890b0b

Browse files
author
Xavier Berger
committed
feat(engine): move activate switch to engine_common
1 parent 158335a commit e890b0b

8 files changed

Lines changed: 49 additions & 87 deletions

solar_router/engine_1dimmer.yaml

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,6 @@
44
packages:
55
- !include engine_common.yaml
66

7-
switch:
8-
# Define is router is active or not
9-
# When switch is ON, pooling timer will trigger every seconds
10-
- platform: template
11-
name: "Activate Solar Routing"
12-
optimistic: true
13-
restore_mode: RESTORE_DEFAULT_OFF
14-
id: activate
15-
on_turn_on:
16-
then:
17-
- light.turn_on: green_led
18-
- lambda: id(power_meter_activated) = 1;
19-
on_turn_off:
20-
then:
21-
- light.turn_off: green_led
22-
- number.to_min: router_level
23-
- lambda: |-
24-
id(real_power).publish_state(NAN);
25-
id(consumption).publish_state(NAN);
26-
id(power_meter_activated) = 0;
27-
287
number:
298
# Router level from 0 to 100
309
# This value serves two purposes:
@@ -59,7 +38,7 @@ number:
5938
- light.turn_off: green_led
6039
- if:
6140
condition:
62-
- switch.is_on: activate
41+
- lambda: return id(power_meter_activated) == 1;
6342
then:
6443
- light.turn_on: green_led
6544
- platform: template

solar_router/engine_1dimmer_1bypass.yaml

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,17 @@ packages:
55
- !include engine_common.yaml
66

77
switch:
8-
# Define is router is active or not
9-
# When switch is ON, pooling timer will trigger every seconds
10-
- platform: template
8+
# Reset values when router based on router activation
9+
- platform: copy
1110
name: "Activate Solar Routing"
12-
optimistic: true
13-
restore_mode: RESTORE_DEFAULT_OFF
14-
id: activate
15-
on_turn_on:
16-
then:
17-
- light.turn_on: green_led
18-
- lambda: id(power_meter_activated) = 1;
11+
internal: True
12+
source_id: activate
13+
id: internal_activate
1914
on_turn_off:
2015
then:
21-
- light.turn_off: green_led
2216
- lambda: |-
2317
id(router_level).publish_state(0);
24-
id(real_power).publish_state(NAN);
25-
id(consumption).publish_state(NAN);
2618
id(bypass_tempo_counter).publish_state(NAN);
27-
id(power_meter_activated) = 0;
2819
id(energy_divertion).turn_off();
2920
id(regulator_opening).publish_state(0);
3021
- script.execute: energy_regulation
@@ -92,7 +83,7 @@ number:
9283
- light.turn_off: green_led
9384
- if:
9485
condition:
95-
- switch.is_on: activate
86+
- lambda: return id(power_meter_activated) == 1;
9687
then:
9788
- light.turn_on: green_led
9889
- if:

solar_router/engine_1dimmer_2switches.yaml

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,30 +32,25 @@ sensor:
3232
- script.execute: regulation_control
3333

3434
switch:
35-
# Define is router is active or not
36-
# When switch is ON, pooling timer will trigger every seconds
37-
- platform: template
35+
# Reset values when router based on router activation
36+
- platform: copy
3837
name: "Activate Solar Routing"
39-
optimistic: true
40-
restore_mode: RESTORE_DEFAULT_OFF
41-
id: activate
38+
internal: True
39+
source_id: activate
40+
id: internal_activate
4241
on_turn_on:
4342
then:
4443
- light.turn_on: green_led
4544
- lambda: |-
4645
id(relay1_tempo_counter).publish_state(id(full_power_duration).state);
4746
id(relay2_tempo_counter).publish_state(id(full_power_duration).state);
48-
id(power_meter_activated) = 1;
4947
on_turn_off:
5048
then:
5149
- light.turn_off: green_led
5250
- lambda: |-
5351
id(router_level).publish_state(0);
54-
id(real_power).publish_state(NAN);
55-
id(consumption).publish_state(NAN);
5652
id(relay1_tempo_counter).publish_state(0);
5753
id(relay2_tempo_counter).publish_state(0);
58-
id(power_meter_activated) = 0;
5954
id(energy_divertion1).turn_off();
6055
id(energy_divertion2).turn_off();
6156
id(regulator_opening).publish_state(0);
@@ -147,7 +142,7 @@ number:
147142
- light.turn_off: green_led
148143
- if:
149144
condition:
150-
- switch.is_on: activate
145+
- lambda: return id(power_meter_activated) == 1;
151146
then:
152147
- light.turn_on: green_led
153148

@@ -168,7 +163,7 @@ number:
168163
then:
169164
- if:
170165
condition:
171-
- switch.is_on: activate
166+
- lambda: return id(power_meter_activated) == 1;
172167
then:
173168
- lambda: |-
174169
id(relay1_tempo_counter).publish_state(id(full_power_duration).state);

solar_router/engine_1dimmer_2switches_1bypass.yaml

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,32 +40,25 @@ sensor:
4040
- script.execute: regulation_control
4141

4242
switch:
43-
# Define is router is active or not
44-
# When switch is ON, pooling timer will trigger every seconds
45-
- platform: template
43+
# Reset values when router based on router activation
44+
- platform: copy
4645
name: "Activate Solar Routing"
47-
optimistic: true
48-
restore_mode: RESTORE_DEFAULT_OFF
49-
id: activate
46+
internal: True
47+
source_id: activate
48+
id: internal_activate
5049
on_turn_on:
5150
then:
52-
- light.turn_on: green_led
5351
- lambda: |-
5452
id(relay1_tempo_counter).publish_state(id(full_power_duration).state);
5553
id(relay2_tempo_counter).publish_state(id(full_power_duration).state);
5654
id(relay3_tempo_counter).publish_state(id(full_power_duration).state);
57-
id(power_meter_activated) = 1;
5855
on_turn_off:
5956
then:
60-
- light.turn_off: green_led
6157
- lambda: |-
6258
id(router_level).publish_state(0);
63-
id(real_power).publish_state(NAN);
64-
id(consumption).publish_state(NAN);
6559
id(relay1_tempo_counter).publish_state(0);
6660
id(relay2_tempo_counter).publish_state(0);
6761
id(relay3_tempo_counter).publish_state(0);
68-
id(power_meter_activated) = 0;
6962
id(energy_divertion1).turn_off();
7063
id(energy_divertion2).turn_off();
7164
id(energy_divertion3).turn_off();
@@ -183,7 +176,7 @@ number:
183176
- light.turn_off: green_led
184177
- if:
185178
condition:
186-
- switch.is_on: activate
179+
- lambda: return id(power_meter_activated) == 1;
187180
then:
188181
- light.turn_on: green_led
189182

@@ -204,7 +197,7 @@ number:
204197
then:
205198
- if:
206199
condition:
207-
- switch.is_on: activate
200+
- lambda: return id(power_meter_activated) == 1;
208201
then:
209202
- lambda: |-
210203
id(relay1_tempo_counter).publish_state(id(full_power_duration).state);

solar_router/engine_1switch.yaml

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,15 @@ packages:
55
- !include engine_common.yaml
66

77
switch:
8-
# Define is router is active or not
9-
# When switch is ON, activate power meter (each time power meter is updated the energy regulation will run)
10-
# When switch is OFF, deactivate power meter, turn off divertion and reset counters
11-
- platform: template
8+
# Reset values when router based on router activation
9+
- platform: copy
1210
name: "Activate Solar Routing"
13-
optimistic: true
14-
restore_mode: RESTORE_DEFAULT_OFF
15-
id: activate
16-
on_turn_on:
17-
then:
18-
- lambda: |-
19-
id(power_meter_activated) = 1;
20-
id(green_led).turn_on();
11+
internal: True
12+
source_id: activate
13+
id: internal_activate
2114
on_turn_off:
2215
then:
2316
- lambda: |-
24-
id(real_power).publish_state(NAN);
25-
id(consumption).publish_state(NAN);
26-
id(power_meter_activated) = 0;
27-
id(green_led).turn_off();
2817
id(start_tempo_counter).publish_state(NAN);
2918
id(stop_tempo_counter).publish_state(NAN);
3019
id(router_level).publish_state(0);
@@ -82,7 +71,7 @@ number:
8271
- light.turn_off: green_led
8372
- if:
8473
condition:
85-
- switch.is_on: activate
74+
- lambda: return id(power_meter_activated) == 1;
8675
then:
8776
- light.turn_on: green_led
8877

solar_router/engine_common.yaml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,29 @@
11
# ----------------------------------------------------------------------------------------------------
22
# User interaction
33
# ----------------------------------------------------------------------------------------------------
4-
54
globals:
65
# By default, if no temperature package is used, safety_limit is disabled
76
- id: safety_limit
87
type: bool
98
initial_value: "false"
109

10+
switch:
11+
# Define is router is active or not
12+
- platform: template
13+
name: "Activate Solar Routing"
14+
optimistic: true
15+
restore_mode: RESTORE_DEFAULT_OFF
16+
id: activate
17+
on_turn_on:
18+
then:
19+
- light.turn_on: green_led
20+
- lambda: id(power_meter_activated) = 1;
21+
on_turn_off:
22+
then:
23+
- light.turn_off: green_led
24+
- lambda: |-
25+
id(power_meter_activated) = 0;
26+
1127
sensor:
1228
- platform: copy
1329
source_id: real_power
@@ -19,7 +35,7 @@ sensor:
1935
- logger.log: "Real power updated, run energy_regulation if activated"
2036
- if:
2137
condition:
22-
switch.is_on: activate
38+
- lambda: return id(power_meter_activated) == 1;
2339
then:
2440
script.execute: energy_regulation
2541

@@ -43,7 +59,7 @@ time:
4359
then:
4460
- if:
4561
condition:
46-
switch.is_on: activate
62+
- lambda: return id(power_meter_activated) == 1;
4763
then:
4864
- light.turn_off: yellow_led
4965
- if:

solar_router/power_meter_home_assistant.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
packages:
2-
- !include power_meter_common.yaml
1+
<<: !include power_meter_common.yaml # keep this include like this (it allows to overwrite real_power)
32

43
# ----------------------------------------------------------------------------------------------------
54
# Define sensor for power collection

solar_router/scheduler_forced_run.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ switch:
1818
then:
1919
- if:
2020
condition:
21-
- switch.is_off: activate
21+
- lambda: return id(power_meter_activated) == 0;
2222
then:
2323
# Set router level to 0 then Enable router
2424
- number.set:
@@ -119,7 +119,7 @@ time:
119119
- if:
120120
condition:
121121
and:
122-
- switch.is_off: activate
122+
- lambda: return id(power_meter_activated) == 0;
123123
# End Hour and minutes are reached
124124
- lambda: |-
125125
// End Hour and minutes are reached

0 commit comments

Comments
 (0)