-
Notifications
You must be signed in to change notification settings - Fork 0
/
pumps.yaml
198 lines (186 loc) · 5.22 KB
/
pumps.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
packages:
pump_1: !include pump_1.yaml
pump_2: !include pump_2.yaml
globals:
- id: pumps_enabled
type: bool
restore_value: yes
initial_value: "false"
- id: pump_is_on
type: bool
restore_value: no
initial_value: "false"
- id: single_activation_is_on
type: bool
restore_value: no
initial_value: "false"
- id: pump_automation_is_on
type: bool
restore_value: no
initial_value: "false"
switch:
- platform: template
name: ${device_name_upper}.enable
id: ${device_name}_enable
lambda: |-
if (id(pumps_enabled) == true)
return true;
else
return false;
turn_on_action:
then:
- globals.set:
id: pumps_enabled
value: "true"
turn_off_action:
then:
- globals.set:
id: pumps_enabled
value: "false"
- switch.turn_off: ${device_name}_automation
- switch.turn_off: ${device_name}_activate
- switch.turn_off: ${device_name}_single_activation
- platform: template
name: ${device_name_upper}.activate
id: ${device_name}_activate
internal: true
lambda: |-
if (id(pump_is_on) == true)
return true;
else
return false;
turn_on_action:
then:
- lambda: |-
if (id(pumps_enabled) == true)
{
id(${device_name}_pump_1).turn_on();
id(${device_name}_pump_2).turn_on();
id(pump_is_on) = true;
}
else
{
id(${device_name}_pump_1).turn_off();
id(${device_name}_pump_2).turn_off();
id(pump_is_on) = false;
}
turn_off_action:
then:
- lambda: |-
id(${device_name}_pump_1).turn_off();
id(${device_name}_pump_2).turn_off();
id(pump_is_on) = false;
- platform: template
name: ${device_name_upper}.single_activation
id: ${device_name}_single_activation
lambda: |-
if (id(single_activation_is_on) == true)
return true;
else
return false;
turn_on_action:
then:
if:
condition:
lambda: |-
if(id(pumps_enabled) == true)
return true;
else
return false;
then:
- lambda: |-
id(${device_name}_activate).turn_on();
id(single_activation_is_on) = true;
- delay: !lambda "return id(${device_name}_duration).state * 1000;"
- lambda: |-
id(${device_name}_activate).turn_off();
id(single_activation_is_on) = false;
else:
- lambda: |-
id(single_activation_is_on) = false;
turn_off_action:
then:
- lambda: |-
id(${device_name}_activate).turn_off();
id(single_activation_is_on) = false;
- platform: template
name: ${device_name_upper}.automation
id: ${device_name}_automation
icon: mdi:water-pump
lambda: |-
if (id(pump_automation_is_on) == true)
return true;
else
return false;
turn_on_action:
then:
- script.stop: ${device_name}_automation_script
- globals.set:
id: pump_automation_is_on
value: "true"
turn_off_action:
then:
- switch.turn_off: ${device_name}_activate
- globals.set:
id: pump_automation_is_on
value: "false"
- script.stop: ${device_name}_automation_script
number:
- platform: template
min_value: "0"
max_value: ${pump_duration_max}
step: "1"
id: ${device_name}_duration
name: ${device_name_upper}.duration
optimistic: true
mode: box
restore_value : true
initial_value: ${pump_duration_initial}
update_interval: "10s"
unit_of_measurement: "s"
on_value:
then:
- script.stop: ${device_name}_automation_script
- platform: template
min_value: "1"
max_value: ${pump_interval_max}
step: "1"
id: ${device_name}_interval
name: ${device_name_upper}.interval
optimistic: true
mode: box
restore_value : true
initial_value: ${pump_interval_initial}
update_interval: "10s"
unit_of_measurement: "s"
on_value:
then:
- script.stop: ${device_name}_automation_script
script:
- id: ${device_name}_automation_script
then:
- while:
condition:
lambda: |-
if(id(pump_automation_is_on) == true &&
id(pumps_enabled) == true)
return true;
else
return false;
then:
- switch.turn_on: ${device_name}_single_activation
- delay: !lambda "return id(${device_name}_interval).state * 1000;"
interval:
- interval: 1 s
then:
- if:
condition:
lambda: |-
if(id(${device_name}_automation_script).is_running() == false &&
id(pump_automation_is_on) == true &&
id(pumps_enabled) == true)
return true;
else
return false;
then:
- script.execute: ${device_name}_automation_script