-
Notifications
You must be signed in to change notification settings - Fork 4
/
tubby.yaml
217 lines (203 loc) · 4.81 KB
/
tubby.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
esphome:
name: tubby
name_add_mac_suffix: true
libraries:
- tflm_esp32
includes:
- light_sleep.h
on_boot:
- priority: 100
then:
- output.turn_on: led
globals:
- id: sleep_blocked
type: bool
restore_value: no
initial_value: 'true'
output:
- platform: gpio
pin: 13
id: led
esp32:
board: um_feathers2
framework:
type: arduino
packages:
wifi: !include wifi.yaml
# Enable logging
logger:
level: INFO
api:
password: ""
ota:
password: ""
# Sensor settling time from Power On
custom_component:
- lambda: |-
//auto me = new LightSleep(3000000); //3 seconds
auto me = new LightSleep(900000000); //15 minutes
return {me};
components:
- id: custom_id
deep_sleep:
id: deep_sleep_1
sleep_duration: 15min
# Enable Home Assistant API
binary_sensor:
- platform: homeassistant
name: "OTA state from Home Assistant"
entity_id: input_boolean.ota
publish_initial_state: true
id: ota_1
on_state:
- if:
condition:
lambda: 'return !x;'
then:
- globals.set:
id: sleep_blocked
value: 'false'
button:
- platform: restart
name: "Restart"
id: esphomerestart
number:
- platform: template
entity_category: "diagnostic"
name: "ORP Cal"
min_value: 0
max_value: 3300
step: 1
optimistic: true
initial_value: 21
restore_value: true
id: "orp_offset"
- platform: template
entity_category: "diagnostic"
name: "pH 4 Cal"
min_value: 0
max_value: 3300
step: 1
optimistic: true
initial_value: 1906
restore_value: true
id: "ph_4"
- platform: template
entity_category: "diagnostic"
name: "pH 7 Cal"
min_value: 0
max_value: 3300
step: 1
optimistic: true
initial_value: 1385
restore_value: true
id: "ph_7"
- platform: template
entity_category: "diagnostic"
name: "pH 10 Cal"
min_value: 0
max_value: 3300
step: 1
optimistic: true
initial_value: 910
restore_value: true
id: "ph_10"
- platform: template
entity_category: "diagnostic"
name: "ppm Factor"
min_value: 1
max_value: 3
step: 0.01
optimistic: true
initial_value: 1
restore_value: true
id: "ppm_factor"
sensor:
- platform: adc
pin: 1
name: "ORP"
force_update: true
update_interval: 0.1s
entity_category: "diagnostic"
device_class: "voltage"
attenuation: 11db
unit_of_measurement: "mV"
id: "orp"
accuracy_decimals: 0
filters:
- median:
window_size: 19
send_every: 19
send_first_at: 19
- lambda: |
return (x * 1000 - 1500) + id(orp_offset).state;
- platform: adc
pin: 3
name: "pH Raw"
force_update: true
update_interval: 0.1s
entity_category: "diagnostic"
device_class: "voltage"
attenuation: 11db
unit_of_measurement: "mV"
id: "ph_raw"
accuracy_decimals: 0
filters:
- median:
window_size: 19
send_every: 19
send_first_at: 19
- lambda: return x * 1000;
- platform: adc
pin: 7
name: "Battery"
device_class: "battery"
entity_category: "diagnostic"
force_update: true
update_interval: 0.1s
unit_of_measurement: "%"
accuracy_decimals: 0
attenuation: 11db
filters:
- median:
window_size: 19
send_every: 19
send_first_at: 19
- calibrate_linear:
- 1.5 -> 0
- 2.1 -> 100
- lambda: |
if (x < 0) return 0;
else if (x > 100) return 100;
else return (x);
- platform: template
name: pH
force_update: true
lambda: |
auto PH_MID_CAL = id(ph_7).state;
auto PH_LOW_CAL = id(ph_4).state;
auto PH_HIGH_CAL = id(ph_10).state;
if (id(ph_raw).state > PH_MID_CAL) return 7.0 - 3.0 / (PH_LOW_CAL - PH_MID_CAL) * (id(ph_raw).state - PH_MID_CAL);
else return 7.0 - 3.0 / (PH_MID_CAL - PH_HIGH_CAL) * (id(ph_raw).state - PH_MID_CAL);
icon: "mdi:ph"
unit_of_measurement: pH
id: "ph"
update_interval: 2s
accuracy_decimals: 2
- platform: template
name: Sanitizer
id: "ppm"
force_update: true
lambda: |
auto ppm = static_cast <LightSleep *> (id(custom_id))->predict_ppm(id(orp).state, id(ph).state);
return ppm * id(ppm_factor).state;
unit_of_measurement: ppm
icon: "mdi:test-tube"
update_interval: 2s
accuracy_decimals: 2
on_value:
- if:
condition:
- lambda: "return id(sleep_blocked) == false;"
then:
- deep_sleep.enter: deep_sleep_1