-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnow55.yaml
238 lines (216 loc) · 7 KB
/
now55.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
### waveshare esp32-s3 zero
### Bus 001 Device 029: ID 303a:1001 Espressif USB JTAG/serial debug unit
### mosquitto_sub -h 192.168.1.1 -F "%I %t %p" -v -t "now55/#" ( coming from gateway, not here )
### esphome run now55.yaml --device=/dev/ttyACM0 | tee /tmp/now55_$(date +"%Y%m%dT%H%M%S").log
### listen to serial port on battery : socat stdio /dev/ttyUSB1
# from dmesg:
# usb 1-3.2: New USB device found, idVendor=303a, idProduct=1001, bcdDevice= 1.01
# usb 1-3.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
# usb 1-3.2: Product: USB JTAG/serial debug unit
# usb 1-3.2: Manufacturer: Espressif
# usb 1-3.2: SerialNumber: 24:EC:4A:26:91:04
### strapping pins: gpio 0,3,45,46
### USB-JTAG pins 19,20 ( usb -c )
### UART0 pins 43,44
### rtc pins: gpio 1-21
substitutions:
device: now55
esphome:
name: ${device}
### ######### UART REQD FOR BATTERY POWERED TESTING
### since no mqtt for logging, and USB_CDC unavailable on battery
### i needed a logging method while on battery
### esp32s3 has uart0 at 43,44 and pins are available on waveshare esp32-s3 zero
uart:
- id: my_uart
baud_rate: 115200
tx_pin:
number: GPIO43
rx_pin:
number: GPIO44
esp32:
board: esp32-s3-devkitc-1
flash_size: 4MB
variant: esp32s3
framework:
type: arduino
version: latest
external_components:
- source:
type: git
url: https://github.com/u-fire/ESPHomeComponents/
deep_sleep:
id: ${device}_deep_sleep
run_duration: 30s
sleep_duration: 15min
wakeup_pin:
number: GPIO7
allow_other_uses: true
mode:
input: true
pulldown: true ### not strong enough, required external pulldown
now_mqtt:
on_sent:
then:
- lambda: id(sent)++;
- if:
condition:
lambda: 'return id(sent) == 5;' # only my sensors , not rssi/motion
then:
- uart.write: !lambda
char buf[128];
sprintf(buf, " reset sent = id %d (sleep)\n", id(sent) );
std::string s = buf;
return std::vector<unsigned char>( s.begin(), s.end() );
- globals.set:
id: sent
value: '0'
- deep_sleep.enter:
id: ${device}_deep_sleep
sleep_duration: 15min
globals:
- id: sent
type: int
restore_value: no
initial_value: '0'
# Enable logging
logger:
level: VERY_VERBOSE
i2c:
sda: GPIO5
scl: GPIO6
binary_sensor:
- platform: gpio
pin:
number: GPIO7
mode:
input: true
pulldown: true
allow_other_uses: true
name: "${device} motion 07"
id: ${device}_motion_07
device_class: motion
filters:
- delayed_off: 1s
on_state:
then:
- logger.log: "${device} GPIO07 acted"
- uart.write: !lambda
char buf[128];
sprintf(buf, " >>>>> [%d] motion07 %2d \n", id(sent) , id(${device}_motion_07).state );
std::string s = buf;
return std::vector<unsigned char>( s.begin(), s.end() );
sensor:
- platform: template
name: "${device} Wakeup Cause"
id: ${device}_Wakeup_Cause
icon: mdi:text
accuracy_decimals: 0
lambda: return esp_sleep_get_wakeup_cause();
on_value:
then:
- uart.write: !lambda
char buf[128];
sprintf(buf, " >>>>> [%d] wake cause = %2d \n", id(sent) , x );
std::string s = buf;
return std::vector<unsigned char>( s.begin(), s.end() );
- platform: shtcx
address: 0x70
update_interval: 5s
temperature:
filters:
- lambda: return x * (9.0/5.0) + 32.0;
unit_of_measurement: "°F"
name: "${device} Temperature"
id: ${device}_temp
on_value:
then:
- uart.write: !lambda
char buf[128];
sprintf(buf, " >>>>> [%d] temp = %5.2f\n", id(sent), x );
std::string s = buf;
return std::vector<unsigned char>( s.begin(), s.end() );
humidity:
name: "${device} Humidity"
id: ${device}_humi
filters:
- filter_out: nan
on_value:
then:
- uart.write: !lambda
char buf[128];
sprintf(buf, " >>>>> [%d] humi = %5.2f \n", id(sent), x );
std::string s = buf;
return std::vector<unsigned char>( s.begin(), s.end() );
- platform: adc
pin: GPIO4
name: "${device} Vdd"
id: "${device}_Vdd"
attenuation: auto
update_interval: 5s
filters:
- lambda: return x * 3.5893;
on_value:
then:
- component.update: "${device}_bat_pct"
- uart.write: !lambda
char buf[128];
sprintf(buf, " >>>>> [%d] adc = %5.2f \n", id(sent), x );
std::string s = buf;
return std::vector<unsigned char>( s.begin(), s.end() );
### divider = 56.1k over 21.77K ( multiplier = [ 21.7 / ( 56.1 + 21.77)) = 0.2786 ]
### results 5v -> 1.393 v, 4.2v = 1.17v , 3.7v = 1.03c, 3.3v = 0.9194
# https://community.home-assistant.io/t/esphome-battery-level-sensor/245196/19
- platform: template
name: "${device} Battery Percentage"
id: ${device}_bat_pct
lambda: return id(${device}_Vdd).state;
accuracy_decimals: 0
unit_of_measurement: "%"
icon: mdi:battery-medium
update_interval: never
filters:
- calibrate_linear:
method: exact
datapoints:
- 0.00 -> 0.0
- 3.30 -> 1.0
- 3.39 -> 10.0
- 3.75 -> 50.0
- 4.11 -> 90.0
- 4.20 -> 100.0
- lambda: |-
if (x <= 100) {
return x;
} else {
return 100;
}
if (x <0) {
return 0;
}
on_value:
then:
- uart.write: !lambda
char buf[128];
sprintf(buf, " >>>>> [%d] bat pct = %5.2f \n", id(sent), x );
std::string s = buf;
return std::vector<unsigned char>( s.begin(), s.end() );
#### #################################### sqample UART0 output per wakeup #########################
#### ESP-ROM:esp32s3-20210327
#### Build:Mar 27 2021
#### rst:0x5 (DSLEEP),boot:0x8 (SPI_FAST_FLASH_BOOT)
#### SPIWP:0xee
#### mode:DIO, clock div:1
#### load:0x3fce3808,len:0x44c
#### load:0x403c9700,len:0xbe4
#### load:0x403cc700,len:0x2a38
#### entry 0x403c98d4
#### E (38) esp_core_dump_flash: No core dump partition found!
#### E (38) esp_core_dump_flash: No core dump partition found!
#### [ 52][I][esp32-hal-i2c.c:75] i2cInit(): Initialising I2C Master: sda=5 scl=6 freq=100000
#### >>>>> [0] wake cause = 0
#### >>>>> [1] bat pct = 82.28
#### >>>>> [2] adc = 4.04
#### >>>>> [3] temp = 68.09
#### >>>>> [4] humi = 64.08
#### reset sent = id 5 (sleep)