Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to turn on relay by SIM7600E 4G module voice call in ESPHome
#1
   
   
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();
              }
            }
          }
ESPHome yaml file for KC868-A2 board download: 
.txt   A2-yaml-sim7600-call-relay.txt (Size: 2.02 KB / Downloads: 39)
Reply
#2
Hello!
any way to select phone number id? like for gate opener

- registered number > relay 1
- unregistered > relay 2

thank you so much
Reply
#3
such as: telephone number A use for turn on relay1
telephone number B use for turn on relay2
?
Reply
#4
exactly, or number A,B...N relay 1, any other unknown number relay 2

thanks
Reply
#5
If you want to determine the incoming call number, you can only control the relay after hanging up the phone, is that okay?
Reply
#6
yes, I noticed the number appears in the "missed call log" actually I was trying to have the module hanging up the call after the first ring

thanks

also a binary sensor for the RING event would be very useful

Reply
#7
this is binary sensor make call: https://www.kincony.com/forum/showthread.php?tid=6502
Reply
#8
yes, but I need to detect the incoming one

I tried with id(ring).publish_state(true); in the lambda but didn't work
Reply
#9
(09-26-2024, 11:58 AM)attilhacks Wrote: yes, but I need to detect the incoming one

I tried with id(ring).publish_state(true); in the lambda but didn't work

i don't understand.
Reply
#10
I need to receive call, not make call, and binary sensor to detect ring, not placing call

thanks
Reply


Forum Jump:


Users browsing this thread:
1 Guest(s)