-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmailbox-sensor.yaml
167 lines (146 loc) · 3.95 KB
/
mailbox-sensor.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
substitutions:
update_interval : "2s"
esphome:
name: mailbox-sensor
friendly_name: mailbox sensor
on_boot:
priority: 600
then:
- lambda: |-
Wire.begin();
delay(100);
- switch.turn_on: tof_enable1
- switch.turn_on: tof_enable2
on_shutdown:
priority: 200
then:
- switch.turn_off: tof_enable1
- switch.turn_off: tof_enable2
time:
- platform: homeassistant
id: ha_time
on_time_sync:
then:
- logger.log: "-->>Synchronized system clock from HA"
- if:
condition:
- lambda: return (id(ha_time).now().hour >= 19 ); #&& id(ha_time).now().hour <= 23);
then:
- delay: 60s # time enough to fix any problems
- logger.log: "-->>Its Night time. Time to sleep a LOOONG time..."
- deep_sleep.enter:
id: deep_sleep_1
sleep_duration: 50400s # 14 hours
else:
- logger.log: "-->>It's not night time yet. No long sleeping"
- logger.log: "Restarting i2c interface"
- lambda: |-
Wire.begin();
delay(100);
- lambda: id(mailbox_number_of_cycles) += 1; #keep track of how many auger turns happen and reset if stove lights
- lambda: id(mailbox_cycle_counter).publish_state(id(mailbox_number_of_cycles)); #publish it to the sensor
- delay: 15s #enough time for all sensors to report back
- logger.log: "-->>Beginning NORMAL daytime Sleeping for 15 min"
- deep_sleep.enter:
id: deep_sleep_1
sleep_duration: 900s # 30 min = 1800s, 15 min = 900s
globals:
- id: mailbox_number_of_cycles
type: int
restore_value: yes
deep_sleep:
id: deep_sleep_1
esp32:
board: esp32-c3-devkitm-1
framework:
type: arduino
# Enable Home Assistant API
api:
ota:
- platform: esphome
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
fast_connect: on
#power_save_mode: light
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Mailbox-Sensor Fallback Hotspot"
password: !secret wifi_password
captive_portal:
logger:
i2c:
sda: GPIO6 #D4
scl: GPIO7 #D5
scan: True
id: bus_a
switch:
- platform: gpio
id: tof_enable1
pin:
number: GPIO3 #D1
allow_other_uses: true
- platform: gpio
id: tof_enable2
pin:
number: GPIO4 #D2
allow_other_uses: true
binary_sensor:
- platform: gpio
name: "Mailbox Flag"
id: mail_flag
publish_initial_state: True
pin:
number: GPIO5 #D3
mode:
input: true
pullup: true
sensor:
- platform: uptime
id: mailbox_uptime
type: timestamp
name: Mailbox Uptime Sensor
- platform: template
name: Mailbox Cycle Counter
id: mailbox_cycle_counter
#2 sensors - big mailbox. one in front, one in back.
- platform: vl53l0x
name: "Mailbox Letter Distance"
id: distance1
address: 0x41
enable_pin:
number: GPIO3
allow_other_uses: true
update_interval: ${update_interval}
timeout: 200us
long_range: False
- platform: vl53l0x
name: "Mailbox Letter Distance2"
id: distance2
address: 0x42
enable_pin:
number: GPIO4
allow_other_uses: true
timeout: 200us
update_interval: ${update_interval}
- platform: adc
name: Mailbox_Batt_Level
id: mailbox_battery
pin: GPIO2
update_interval: ${update_interval}
accuracy_decimals: 2
attenuation: 12db
unit_of_measurement: "V"
icon: mdi:battery-medium
filters:
- calibrate_linear:
method: exact
datapoints:
- 1.92 -> 2.9
- 2.09 -> 3.1
- 2.23 -> 3.3
- 2.50 -> 3.6
- platform: wifi_signal
id: mailbox_wifi_signal
name: "Mailbox WiFi Signal"
update_interval: ${update_interval}