-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlora-receiver.yaml
More file actions
140 lines (126 loc) · 4.15 KB
/
Copy pathlora-receiver.yaml
File metadata and controls
140 lines (126 loc) · 4.15 KB
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
# LoRa Mailbox Receiver v8
#
# Hardware: Heltec WiFi LoRa 32 V3 (ESP32-S3 + SX1262)
# Power: USB or wall adapter (always on)
#
# Receives LoRa packets from sender and:
# - Fires Home Assistant event with payload and RSSI
# - Sends push notification to mobile app
#
# Message format received:
# 1|4.02 = Mail received
# 1|3.35|LOW_BAT = Mail received, low battery
# W|4.02|LID_OPEN = Lid open warning
esphome:
name: lora-receiver
friendly_name: LoRa Mailbox Receiver
esp32:
board: esp32-s3-devkitc-1
framework:
type: arduino
logger:
level: INFO
api:
encryption:
key: !secret api_encryption_key
ota:
- platform: esphome
password: !secret ota_password
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
spi:
clk_pin: GPIO9
mosi_pin: GPIO10
miso_pin: GPIO11
sx126x:
id: lora_radio
cs_pin: GPIO8
rst_pin: GPIO12
busy_pin: GPIO13
dio1_pin: GPIO14
hw_version: sx1262
tcxo_voltage: 1_8V
tcxo_delay: 30ms
rf_switch: true
modulation: LORA
sync_value: [0x14, 0x24]
frequency: 868000000 # Must match sender
bandwidth: 125_0kHz
spreading_factor: 12
coding_rate: CR_4_8
preamble_size: 10
crc_enable: true
pa_power: 14
rx_start: true
on_packet:
then:
- lambda: |-
std::string payload(x.begin(), x.end());
ESP_LOGI("LoRa RX", "Received: '%s' | RSSI: %.1f dBm", payload.c_str(), rssi);
// Parse battery voltage from payload
if (payload.find("|") != std::string::npos) {
size_t pos = payload.find("|");
std::string voltage_str = payload.substr(pos + 1);
size_t pos2 = voltage_str.find("|");
if (pos2 != std::string::npos) {
voltage_str = voltage_str.substr(0, pos2);
}
ESP_LOGI("LoRa RX", "Battery: %s V", voltage_str.c_str());
}
# Fire HA event with full payload
- homeassistant.event:
event: esphome.lora_mailbox_packet
data:
payload: !lambda 'return std::string(x.begin(), x.end());'
rssi: !lambda 'return std::to_string(rssi);'
# Mail notification (payload starts with "1|")
- if:
condition:
lambda: 'return std::string(x.begin(), x.end()).find("1|") == 0;'
then:
- logger.log: "Mail notification received"
- homeassistant.service:
service: notify.mobile_app_your_phone # Change to your device
data:
title: "Mailbox"
message: !lambda |-
std::string payload(x.begin(), x.end());
char msg[64];
snprintf(msg, sizeof(msg), "You've got mail! Battery: %.2f V Signal: %f dBm",
atof(payload.substr(2).c_str()), rssi);
return std::string(msg);
data:
channel: mailbox
# Lid open warning (payload starts with "W|")
- if:
condition:
lambda: 'return std::string(x.begin(), x.end()).find("W|") == 0;'
then:
- logger.log: "Lid open warning received"
- homeassistant.service:
service: notify.mobile_app_your_phone # Change to your device
data:
title: "Mailbox Warning"
message: "Mailbox lid has been open for 5 minutes!"
data:
channel: mailbox
# Low battery warning (payload contains "LOW_BAT")
- if:
condition:
lambda: 'return std::string(x.begin(), x.end()).find("LOW_BAT") != std::string::npos;'
then:
- logger.log: "Low battery warning received"
- homeassistant.service:
service: notify.mobile_app_your_phone # Change to your device
data:
title: "Mailbox Battery Low"
message: "Mailbox sensor battery is low - charge soon!"
data:
channel: mailbox
priority: high
# Keep receiver in RX mode
interval:
- interval: 60s
then:
- sx126x.set_mode_rx: lora_radio