-
Notifications
You must be signed in to change notification settings - Fork 1
/
th10.yaml
301 lines (264 loc) · 7.21 KB
/
th10.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
#------------------------------
#-- th10.yaml
#-- Petit code pour monitorer la température et l'humidité dans une pièce
#-- location: salle de douche
#-- Si la pin D7 est à GND, alors part en dsleep pour une certaine durée autrement on tourne en mode normal
#-- ATTENTION, il faut relier la pin D0 à RST pour qu'il puisse sortir du dsleep mode !
#-- calibration VCC diode: 239 lambda: return id(th10_vcc_voltage).state + 1.339 ;
#-- calibration température: 213 - offset: -0.3
#-- Il faut publier sur mqtt 'th10/switch/th10_led/command' = ON/OFF pour allumer/éteindre la LED
#-- Il faut publier sur mqtt 'th10/switch/th10_firmware_update/command' = ON pour lancer l'OTA
#-- zf230721.1310, zf230830.0911
#--
#-- Procédure à faire sur mon iMAC pour le flash OTA HTTP
#-- cd ~/ota_www/
#-- python -m SimpleHTTPServer 8080
#--
# sources:
# https://esphome.io/components/sensor/htu21d.html
# https://github.com/oarcher/piotech/tree/main/components/ota_http
# Calcul de la durée sur une batterie: https://docs.google.com/spreadsheets/d/1I6s_R04LjGxCB0hrcvogGHNeITDwfXjM05hJhuqGkoU/edit#gid=1470557238
esphome:
name: th10
on_boot:
# - switch.turn_off: led
- switch.turn_on: led
esp8266:
board: d1_mini
# Configuration WIFI
wifi:
fast_connect: true
reboot_timeout: 15s
ssid: !secret wifi_ssid_apzuzu7
password: !secret wifi_pass_apzuzu7
# manual_ip:
# static_ip: 192.168.0.201
# gateway: 192.168.0.51
# dns1: 192.168.0.51
# dns2: 8.8.8.8
# subnet: 255.255.255.0
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "th10 Fallback"
password: !secret ap_wifi_password
captive_portal:
# Enable logging
logger:
level: DEBUG
# level: INFO
logs:
logger: INFO
adc: INFO
captive_portal: INFO
deep_sleep: INFO
htu21d: INFO
i2c: INFO
ota: INFO
restart: INFO
sensor: INFO
switch: INFO
switch.gpio: INFO
uptime.sensor: INFO
web_server: INFO
wifi_signal.sensor: INFO
mqtt: INFO
mqtt.component: INFO
mqtt.client: INFO
mqtt.switch: INFO
mqtt.sensor: INFO
# # Enable Home Assistant API
# api:
# password: !secret api_password
ota:
password: !secret ota_password
external_components:
- source: github://oarcher/piotech/
ota_http:
# WEB Server
web_server:
port: 80
# MQTT server
mqtt:
broker: !secret mqtt_server_dev
port: !secret mqtt_port_dev
username: !secret mqtt_user_dev
password: !secret mqtt_password_dev
birth_message:
will_message:
reboot_timeout: 15s
# I2C conf
i2c:
sda: D2
scl: D1
# frequency: 10khz
# Définition des Switch's
switch:
- platform: gpio
name: "th10 LED"
inverted: True
id: led
pin: D4
- platform: restart
name: "th10 Restart"
- platform: shutdown
name: "th10 Shutdown"
id: th10_shutdown
internal: true
- platform: template
name: "th10 Firmware update"
id: th10_firmware_update
turn_on_action:
then:
- binary_sensor.template.publish:
id: th10_ota_mode
state: ON
- logger.log: "On me demande un firmware update"
turn_off_action:
then:
- binary_sensor.template.publish:
id: th10_ota_mode
state: OFF
- logger.log: "On ne me demande plus un firmware update"
# Définition des Scripts
script:
# fonction BMS, shutdown si < 3.3 Volts !
- id: my_bms
then:
- logger.log:
format: "La batterie est à %.1f"
args: [ 'id(th10_bat_voltage).state' ]
- if:
condition:
lambda: 'return id(th10_bat_voltage).state < 3.2 ;'
then:
- logger.log: "La batterie est en dessous de 3.2 Volts !"
- delay: 0.5s
- switch.turn_on: th10_shutdown
else:
- logger.log: "La batterie est encore bonne !"
# Définition des Sensors
sensor:
- platform: wifi_signal
name: "th10 Signal Wi-Fi"
update_interval: 10s
on_value:
if:
condition:
mqtt.connected:
then:
- logger.log: Je suis connecté sur le mqtt et j'envoie la sauce !
- switch.turn_off: led
- delay: 0.5s
- switch.turn_on: led
- if:
condition:
lambda: 'return id(th10_ota_mode).state == 0;'
then:
- if:
condition:
lambda: 'return id(th10_sleep_mode).state == 1;'
then:
- logger.log: On me demande de dormir !
- deep_sleep.enter: deep_sleep_1
else:
- mqtt.publish:
topic: th10/switch/th10_firmware_update/command
payload: "OFF"
retain: True
- delay: 2s
- ota_http.flash:
url: http://192.168.0.138:8080/th10.bin
- logger.log: "This message should be not displayed(reboot)"
else:
- logger.log: Erreur 007 *********************************************************
- if:
condition:
lambda: 'return id(th10_sleep_mode).state == 1;'
then:
- logger.log: On me demande de dormir !
- deep_sleep.enter: deep_sleep_1
- platform: uptime
name: "th10 uptime"
update_interval: 1s
# température et humidité
- platform: htu21d
temperature:
name: "th10 Température"
filters:
- offset: -0.3
humidity:
name: "th10 Humidité"
# accuracy_decimals: 0
update_interval: 1s
# tension VCC à l'intérieur de l'ESP
- platform: adc
pin: VCC
name: "th10 VCC Voltage"
id: th10_vcc_voltage
update_interval: 1s
unit_of_measurement: "V"
accuracy_decimals: 3
internal: true
# tension de la batterie
- platform: template
name: "th10 BAT Voltage"
id: th10_bat_voltage
update_interval: 1s
unit_of_measurement: "V"
accuracy_decimals: 3
on_value:
then:
- script.execute: my_bms
lambda: return id(th10_vcc_voltage).state + 1.339 ;
# capacité de la batterie
- platform: template
name: "th10 BAT capacity"
update_interval: 1s
unit_of_measurement: "%"
accuracy_decimals: 0
lambda: return id(th10_bat_voltage).state ;
filters:
- calibrate_linear:
- 3.4 -> 0.0
- 4.1 -> 100.0
# filtre la valeur minimale
- lambda: |-
if (x >= 0)
return x;
else
return 0;
# filtre la valeur maximale
- lambda: |-
if (x <= 100)
return x;
else
return 100;
# Définition des binary sensor
binary_sensor:
- platform: gpio
pin:
number: D7
mode: INPUT_PULLUP
inverted: True
name: "th10 sleep mode"
id: th10_sleep_mode
- platform: template
name: "th10 ota mode"
id: th10_ota_mode
# Définition des Sensors text
text_sensor:
- platform: version
name: "th10 Version 164434"
- platform: wifi_info
ip_address:
name: th10 IP Address
id: wifi_ip
ssid:
name: th10 Connected SSID
id: wifi_ssid
# Deep Sleep
deep_sleep:
run_duration: 15s
# sleep_duration: 600s
sleep_duration: 60s
id: deep_sleep_1