-
Notifications
You must be signed in to change notification settings - Fork 1
/
garage_temp_3.yaml
211 lines (182 loc) · 5.11 KB
/
garage_temp_3.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
substitutions:
device_name: garage_temp_3
upper_device_name: Garage Temp 3
ip_address: 192.168.37.211
esphome:
name: $device_name
platform: ESP8266
board: d1_mini
on_boot:
- priority: -300
then:
- script.execute: handle_sensors
wifi: !include include/wifi_iot_manual.yaml
captive_portal:
web_server:
port: 80
logger:
level: WARN
ota:
# web_server:
# port: 80
mqtt:
id: mqtt_cli
broker: !secret mqtt_broker
username: !secret mqtt_username
password: !secret mqtt_password
# Needed when using deep sleep mode
birth_message:
topic: $device_name/birthdisable
payload: disable
will_message:
topic: $device_name/willdisable
payload: disable
# Enable Home Assistant API
# api:
i2c:
sensor:
- platform: bme280
id: bme280_1
temperature:
name: $upper_device_name Temperature
id: bme280_temperature
oversampling: 16x
expire_after: 30min
accuracy_decimals: 2
device_class: "temperature"
state_topic: $device_name/temperature/state
on_value:
lambda: |-
id(updates)++;
ESP_LOGD("Read","BME280 Temperature Value Returned");
pressure:
name: $upper_device_name Pressure
id: bme280_pressure
oversampling: 16x
expire_after: 30min
unit_of_measurement: "mbar"
device_class: pressure
accuracy_decimals: 2
state_topic: $device_name/pressure/state
on_value:
lambda: |-
id(updates)++;
ESP_LOGD("Read","BME280 Pressure Value Returned");
humidity:
name: $upper_device_name Humidity
id: bme280_humidity
oversampling: 16x
expire_after: 30min
accuracy_decimals: 2
device_class: "humidity"
state_topic: $device_name/humidity/state
on_value:
lambda: |-
id(updates)++;
ESP_LOGD("Read","BME280 Humidity Value Returned");
address: 0x76
update_interval: never
- platform: template
name: $upper_device_name Sea Level Pressure
id: bme280_sea_level
update_interval: never
unit_of_measurement: 'hPa'
device_class: pressure
- platform: adc
pin: A0
filters:
- multiply: 100
- lambda: return x * 100 / 75;
unit_of_measurement: "%"
name: $upper_device_name Battery
id: battery
device_class: battery
update_interval: never
expire_after: 60min
state_topic: $device_name/battery/state
on_value:
lambda: |-
id(updates)++;
ESP_LOGD("Read","Battery Value Returned");
- platform: wifi_signal
id: wifi_signal_1
name: $upper_device_name WiFi Signal
update_interval: never
on_value:
lambda: |-
id(updates)++;
ESP_LOGD("Read","WiFi Value Returned");
deep_sleep:
id: deep_sleep_1
run_duration: 20s
button:
- platform: restart
name: $upper_device_name
id: restart_button
globals:
- id: updates
type: int
restore_value: no
initial_value: '0'
- id: errors
type: int
restore_value: no
initial_value: '0'
- id: defeat_sleep
type: int
restore_value: no
initial_value: '0'
script:
- id: handle_sensors
then:
- lambda: |-
ESP_LOGD("Script","Subscribe to defeat_sleep");
id(mqtt_cli).subscribe("hass/defeat_sleep/state", [=](const std::string &topic, const std::string &payload) {
id(defeat_sleep) = (payload.compare("on") == 0);
});
- lambda: |-
ESP_LOGD("Script","Get Sensor Updates");
id(updates) = 0;
id(errors) = 0;
id(bme280_1).update();
if(id(bme280_1)->status_has_error()){
id(errors) += 3;
ESP_LOGD("Update","BME280 Update Error");
}
id(battery).update();
if(id(battery)->status_has_error()){
id(errors) += 1;
ESP_LOGD("Update","Battery Update Error");
}
id(wifi_signal_1).update();
if(id(wifi_signal_1)->status_has_error()){
id(errors) += 1;
ESP_LOGD("Update","Wifi Signal Update Error");
}
- lambda: |-
ESP_LOGD("Script","Wait for updates");
- wait_until:
lambda: |-
return (id(updates) + id(errors) >= 5);
- lambda: |-
ESP_LOGD("Script","Publish Readings");
const float STANDARD_ALTITUDE = 204; // in meters
float press = id(bme280_pressure).state;
float temp = id(bme280_temperature).state;
float sea_level = (press / powf(1 - ((0.0065 * STANDARD_ALTITUDE) /
(temp + (0.0065 * STANDARD_ALTITUDE) + 273.15)), 5.257)) + 2.8; // in hPa
id(bme280_sea_level).publish_state(sea_level);
- lambda: ESP_LOGD("Script","defeat_sleep = %d", id(defeat_sleep));
# - while:
# condition:
# lambda: 'return id(defeat_sleep) == 1;'
# then:
# # How to I check the button?
- wait_until:
lambda: 'return id(defeat_sleep) == 0;'
- lambda: |-
ESP_LOGD("Script","defeat_sleep = %d", id(defeat_sleep));
ESP_LOGD("Script","Entering deep sleep");
- deep_sleep.enter:
id: deep_sleep_1
sleep_duration: 15min