-
Notifications
You must be signed in to change notification settings - Fork 6
/
weather_station.yaml
350 lines (322 loc) · 10.6 KB
/
weather_station.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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
######################################################################################################################
# Project author: Debasish Dutta #
# Kit supplied by PCBWay: # https://www.pcbway.com/project/shareproject/Solar_Powered_WiFi_Weather_Station_V3_0.html #
# Code adapted and expanded by Bearded Tinker ;) #
# GitHub: https://github.com/BeardedTinker/SolarWS #
######################################################################################################################
# Additional modules that can be use (and code takes them into account) #
# BME280 temperature, humidity and pressure OR BMP280 for temperature and pressure #
# DS18B20 additional temperature measurments #
# BH1750 lux sensor #
# #
# TX20 Wind speed and direction #
# #
# NOT USED: #
# #
# SI1145 UV index #
# #
######################################################################################################################
###########################
# Configuration variables #
###########################
substitutions:
display_name: solarws
awake_duration: 30s
update_fq: 25s
sleep_duration: 5min
battery_full: '3.16'
battery_empty: '2.492'
battery_diff: '0.668' # '${battery_full}-${battery_empty}'
esphome:
name: solarweather
####################################################
##### No need to edit anything below this line #####
####################################################
# On boot run script to see if Deep Sleep is prevented or not
on_boot:
then:
- script.execute: consider_deep_sleep
esp32:
board: esp-wrover-kit
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_key
api:
# Enable logging
logger:
ota:
# On OTA end toggle off HA boolean
on_end:
then:
- logger.log: 'OTA successful - flipping switch'
- homeassistant.service:
service: input_boolean.turn_off
data:
entity_id: input_boolean.solarws_prevent_deep_sleep
# Enable i2c
i2c:
sda: 21
scl: 22
scan: true
id: bus_a
# Detect Dallas sensor address
dallas:
- pin: GPIO4
# Check status of Home Assistant input boolean to prevent Deep Sleep
# Used for OTA - has BIG impact on battery life
binary_sensor:
- platform: homeassistant
id: solarws_prevent_deep_sleep
name: 'Prevent Solar WS Deep Sleep'
entity_id: input_boolean.solarws_prevent_deep_sleep
sensor:
# BME280 is used to get temperature, pressure and humidity
# BMP280 only provides temperature and pressure so please comment out hummidity section
# - platform: bmp280
- platform: bme280
address: 0x76
temperature:
name: '${display_name} WS Temperature'
oversampling: 4x
unit_of_measurement: "°C"
icon: "mdi:thermometer"
device_class: "temperature"
state_class: "measurement"
accuracy_decimals: 1
pressure:
name: '${display_name} Pressure'
oversampling: 4x
unit_of_measurement: "hPa"
device_class: "pressure"
state_class: "measurement"
humidity:
name: '${display_name} Humidity'
oversampling: 4x
unit_of_measurement: "%"
icon: "mdi:thermometer"
device_class: "humidity"
state_class: "measurement"
# DS18B20 Dallas temperature sensor
- platform: dallas
address: 0xc43c01f096e8b728
name: '${display_name} Air Temperature'
unit_of_measurement: "°C"
icon: "mdi:thermometer"
device_class: "temperature"
state_class: "measurement"
accuracy_decimals: 1
# BH1750 sensor provides lux vaules
- platform: bh1750
name: '${display_name} Lux'
address: 0x23
unit_of_measurement: "lx"
icon: "mdi:white-balance-sunny"
device_class: "illuminance"
state_class: "measurement"
update_interval: ${update_fq}
# ADC platform helps track status of battery
- platform: adc
pin: GPIO33
name: '${display_name} Battery'
unit_of_measurement: "V"
icon: "mdi:battery-high"
device_class: "voltage"
state_class: "measurement"
accuracy_decimals: 3
attenuation: 11db
id: voltage
# update_interval: 25s
# Another ADC platform to track battery %
- platform: adc
pin: GPIO33
name: '${display_name} Battery %'
attenuation: 11db
unit_of_measurement: '%'
filters:
- lambda: |-
return ((id(voltage).state - 2.492) / 0.668 * 100.00);
# return ((id(voltage).state - ${battery_empty}) / ${battery_diff} * 100.00);
update_interval: ${update_fq}
# Rain gauge with pulse counter
- platform: pulse_counter
pin:
number: GPIO25
inverted: True
mode: INPUT_PULLUP
name: 'Rainfall'
unit_of_measurement: 'mm'
count_mode:
rising_edge: DISABLE
falling_edge: INCREMENT
# internal_filter: 14ms
filters:
- multiply: 0.367
update_interval: ${update_fq}
# Wind speed sensor with pulse counter
- platform: pulse_counter
pin:
number: GPIO14
mode: INPUT_PULLUP
name: '${display_name} Windspeed Meter'
icon: 'mdi:weather-windy'
id: wind_meter
unit_of_measurement: 'km/h'
accuracy_decimals: 1
update_interval: ${update_fq}
# timeout: 5s
filters:
- multiply: 0.048 #1.492mph per rotation so 1 / 25 (update_fq) / 2 * 2.4
### Wind direction support
# Another ADC platform to track wind direction
- platform: adc
id: wind_direction
pin: GPIO35
name: ADC wind
attenuation: 11db
internal: true
update_interval: ${update_fq}
- platform: resistance
sensor: wind_direction
id: resistance_sensor
configuration: DOWNSTREAM
resistor: 10kOhm
internal: true
name: Resistance Sensor
reference_voltage: 3.3V
accuracy_decimals: 1
on_value:
- if:
condition:
sensor.in_range:
id: resistance_sensor
above: 30500
below: 33900
then:
- text_sensor.template.publish:
id: wind_dir_card
state: "N"
- sensor.template.publish:
id: wind_heading
state: 0.0
- if:
condition:
sensor.in_range:
id: resistance_sensor
above: 7500
below: 8400
then:
- text_sensor.template.publish:
id: wind_dir_card
state: "NE"
- sensor.template.publish:
id: wind_heading
state: 45.0
- if:
condition:
sensor.in_range:
id: resistance_sensor
above: 88000
below: 115000
then:
- text_sensor.template.publish:
id: wind_dir_card
state: "E"
- sensor.template.publish:
id: wind_heading
state: 90.0
- if:
condition:
sensor.in_range:
id: resistance_sensor
above: 1800
below: 2500
then:
- text_sensor.template.publish:
id: wind_dir_card
state: "SE"
- sensor.template.publish:
id: wind_heading
state: 135.0
- if:
condition:
sensor.in_range:
id: resistance_sensor
above: 3500
below: 4000
then:
- text_sensor.template.publish:
id: wind_dir_card
state: "S"
- sensor.template.publish:
id: wind_heading
state: 180.0
- if:
condition:
sensor.in_range:
id: resistance_sensor
above: 14500
below: 16600
then:
- text_sensor.template.publish:
id: wind_dir_card
state: "SW"
- sensor.template.publish:
id: wind_heading
state: 225.0
- if:
condition:
sensor.in_range:
id: resistance_sensor
above: 850
below: 1200
then:
- text_sensor.template.publish:
id: wind_dir_card
state: "W"
- sensor.template.publish:
id: wind_heading
state: 270.0
- if:
condition:
sensor.in_range:
id: resistance_sensor
above: 55000
below: 63000
then:
- text_sensor.template.publish:
id: wind_dir_card
state: "NW"
- sensor.template.publish:
id: wind_heading
state: 315.0
- platform: template
name: "${display_name} wind heading"
id: wind_heading
unit_of_measurement: "°"
text_sensor:
- platform: template
name: "Wind Cardinal Direction"
id: wind_dir_card
# Define length of Deep sleep
deep_sleep:
id: deep_sleep_control
sleep_duration: ${sleep_duration}
run_duration:
default: ${awake_duration}
gpio_wakeup_reason: 2s
wakeup_pin: GPIO25
wakeup_pin_mode: INVERT_WAKEUP
# Deep sleep script if/then/else
script:
- id: consider_deep_sleep
mode: queued
then:
- delay: ${awake_duration}
- if:
condition:
binary_sensor.is_on: solarws_prevent_deep_sleep
then:
- logger.log: 'Skipping sleep, per prevent_deep_sleep'
else:
- deep_sleep.enter: deep_sleep_control
- script.execute: consider_deep_sleep