Smart Home Automation Forum
how to turn on relay by SIM7600E 4G module voice call in ESPHome - Printable Version

+- Smart Home Automation Forum (https://www.kincony.com/forum)
+-- Forum: Technical Support (https://www.kincony.com/forum/forumdisplay.php?fid=1)
+--- Forum: Getting Started with ESPHome and Home Assistant (https://www.kincony.com/forum/forumdisplay.php?fid=54)
+--- Thread: how to turn on relay by SIM7600E 4G module voice call in ESPHome (/showthread.php?tid=6763)

Pages: 1 2


how to turn on relay by SIM7600E 4G module voice call in ESPHome - admin - 09-23-2024

   
   
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: 295)


RE: how to turn on relay by SIM7600E 4G module voice call in ESPHome - attilhacks - 09-25-2024

Hello!
any way to select phone number id? like for gate opener

- registered number > relay 1
- unregistered > relay 2

thank you so much


RE: how to turn on relay by SIM7600E 4G module voice call in ESPHome - admin - 09-25-2024

such as: telephone number A use for turn on relay1
telephone number B use for turn on relay2
?


RE: how to turn on relay by SIM7600E 4G module voice call in ESPHome - attilhacks - 09-25-2024

exactly, or number A,B...N relay 1, any other unknown number relay 2

thanks


RE: how to turn on relay by SIM7600E 4G module voice call in ESPHome - admin - 09-25-2024

If you want to determine the incoming call number, you can only control the relay after hanging up the phone, is that okay?


RE: how to turn on relay by SIM7600E 4G module voice call in ESPHome - attilhacks - 09-26-2024

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




RE: how to turn on relay by SIM7600E 4G module voice call in ESPHome - admin - 09-26-2024

this is binary sensor make call: https://www.kincony.com/forum/showthread.php?tid=6502


RE: how to turn on relay by SIM7600E 4G module voice call in ESPHome - attilhacks - 09-26-2024

yes, but I need to detect the incoming one

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


RE: how to turn on relay by SIM7600E 4G module voice call in ESPHome - admin - 09-26-2024

(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.


RE: how to turn on relay by SIM7600E 4G module voice call in ESPHome - attilhacks - 09-27-2024

I need to receive call, not make call, and binary sensor to detect ring, not placing call

thanks