09-23-2024, 02:08 AM
Code:
esphome:
name: a2
esp32:
board: esp32dev
framework:
type: arduino
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: "YnmQggQsfd7jvFefoMqNCpBtb63RXtotS+mSBQVIhY8="
# Example configuration entry
ethernet:
type: LAN8720
mdc_pin: GPIO23
mdio_pin: GPIO18
clk_mode: GPIO17_OUT
phy_addr: 0
switch:
- platform: gpio
name: "a2-light1"
pin: 15
inverted: False
id: relay_1 # Assign ID to relay 1
- platform: gpio
name: "a2-light2"
pin: 2
inverted: False
binary_sensor:
- platform: gpio
name: "a2-input1"
pin:
number: 36
inverted: true
- platform: gpio
name: "a2-input2"
pin:
number: 39
inverted: true
web_server:
port: 80
# UART configuration for SIM7600E
uart:
id: uart_2
tx_pin: GPIO5
rx_pin: GPIO13
baud_rate: 115200
interval:
- interval: 200ms # Shorten the interval to reduce blocking time
then:
- lambda: |-
static std::string uart_buffer;
uint8_t c;
int count = 0;
const int max_reads = 10; // Limit the number of bytes read per interval
while (id(uart_2).available() && count < max_reads) {
if (id(uart_2).read_byte(&c)) {
uart_buffer += (char)c;
count++;
// Log each received character (optional for debugging)
ESP_LOGD("UART", "Received: %c", (char)c);
// Check if we have received the "RING" signal
if (uart_buffer.find("RING") != std::string::npos) {
ESP_LOGI("SIM7600", "Incoming call detected, turning on relay 1.");
id(relay_1).turn_on(); // Turn on relay 1
uart_buffer.clear(); // Clear the buffer after processing
}
// Clear the buffer if it gets too large
if (uart_buffer.length() > 100) {
uart_buffer.clear();
}
}
}
A2-yaml-sim7600-call-relay.txt (Size: 2.02 KB / Downloads: 39)