Door sensor with esphome by lora

Hi
I’m trying to install a door sensor in my storage room. The coverage is fine.
I have a temperature and humidity sensor installed and I receive the data without any problems. All the program ara make with esphome. However, I don’t receive changes in the magnetic sensor’s state on the door.
The remote device is a Heltec 32 v2 and the one I have at home is a TTGO
I don’t see any errors in the logs. In the transmitter log, I see it being transmitted, but in the receiver log, I don’t see it being received.

This is the trasmiter code:

esphome:
  name: lora-heltec
  friendly_name: Lora HELTEC

esp32:
  board: esp32dev
  framework:
    type: arduino

external_components:
  - source: github://dala318/esphome@sx127x-transport
    components:
      - sx127x
      - packet_transport
    refresh: 5min

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "XXXXXXXXXXXXXXXXXXXX"

ota:
  - platform: esphome
    password: "XXXXXXXXXXXXXXXXXXXX"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Lora-Heltec Fallback Hotspot"
    password: "XXXXXXXXXXXX"

#bluetooth_proxy:
#  active: True

captive_portal:

# Example configuration entry
spi:
  clk_pin: GPIO5
  mosi_pin: GPIO27
  miso_pin: GPIO19

sx127x:
  dio0_pin: GPIO26
  cs_pin: GPIO18
  rst_pin: GPIO23
  pa_pin: BOOST
  pa_power: 17
  bandwidth: 125_0kHz
  crc_enable: true
  frequency: 868920000
  modulation: LORA
  rx_start: true
  sync_value: 0x12
  spreading_factor: 7
  coding_rate: CR_4_5
  on_packet:
    then:
      - lambda: |-
          ESP_LOGD("lambda", "packet %s", format_hex(x).c_str());
          ESP_LOGD("lambda", "rssi %.2f", rssi);
          ESP_LOGD("lambda", "snr %.2f", snr);
sensor:
  - platform: dht
    pin: GPIO13    
    temperature:
      name: Temperatura
      id: temperatura
    humidity:
      name: Humedad
      id: humedad

packet_transport:
  platform: sx127x
  update_interval: 10s
  encryption: ""
  rolling_code_enable: true
  sensors:
    - humedad
    - temperatura
  binary_sensors:
    - rele_heltec
    - puerta_trastero
  providers:
    name: lora-ttgo
    encryption: ""

switch:
  - platform: gpio
    pin: GPIO25
    name: Relé
    id: rele

binary_sensor:
  - platform: packet_transport
    provider: lora-ttgo
    id: rele_ttgo
    on_press:
      switch.turn_on: rele
    on_release:
      switch.turn_off: rele

  - platform: template
    id: rele_heltec
    lambda: return id(rele).state;

  - platform: gpio
    id: puerta_tras
    pin: 
      number: 12
      mode: input_pullup

  - platform: template
    id: puerta_trastero
    lambda: return id(puerta_tras).state;

And this the receiver code:

esphome:
  name: lora-ttgo
  friendly_name: Lora TTGO

esp32:
  board: esp32dev
  framework:
    type: arduino

external_components:
  - source: github://dala318/esphome@sx127x-transport
    components:
      - sx127x
      - packet_transport
    refresh: 5min

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "XXXXXXXXXXXXXXXXXX"

ota:
  - platform: esphome
    password: "XXXXXXXXXXXXXXXXX"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Lora-Ttgo Fallback Hotspot"
    password: "XXXXXXXXXXXXXX"

#bluetooth_proxy:
#  active: True

captive_portal:

#Hora
time:
  - platform: homeassistant
    id: hora
    
# Example configuration entry
spi:
  clk_pin: GPIO05
  mosi_pin: GPIO27
  miso_pin: GPIO19

sx127x:
  dio0_pin: GPIO26
  cs_pin: GPIO18
  rst_pin: GPIO23
  pa_pin: BOOST
  pa_power: 17
  bandwidth: 125_0kHz
  crc_enable: true
  frequency: 868920000
  modulation: LORA
  rx_start: true
  sync_value: 0x12
  spreading_factor: 7
  coding_rate: CR_4_5
  on_packet:
    then:
      - lambda: |-
          ESP_LOGD("lambda", "packet %s", format_hex(x).c_str());
          ESP_LOGD("lambda", "rssi %.2f", rssi);
          ESP_LOGD("lambda", "snr %.2f", snr);

packet_transport:
  platform: sx127x
  update_interval: 10s
  encryption: ""
  binary_sensors:
    - rele_ttgo
  providers:
    name: lora-heltec
    encryption: ""

sensor:
  - platform: packet_transport
    id: humedad
    provider: lora-heltec

  - platform: packet_transport
    id: temperatura
    provider: lora-heltec
  
  - platform: template
    name: Temperatura
    device_class: temperature
    unit_of_measurement: º
    update_interval: 10s
    lambda: return id(temperatura).state;

  - platform: template
    name: Humedad
    device_class: humidity
    unit_of_measurement: '%'
    update_interval: 10s
    lambda: return id(humedad).state;


switch:
  - platform: template
    name: Relé
    id: rele
    optimistic: True


binary_sensor:
  - platform: template
    id: rele_ttgo
    lambda: return id(rele).state;

  - platform: packet_transport
    id: rele_heltec
    provider: lora-heltec
    on_press:
      switch.turn_on: rele
    on_release:
      switch.turn_off: rele

  - platform: packet_transport
    id: puerta_trastero
    provider: lora_heltec


  - platform: template
    name: Puerta Trastero
    lambda: return id(puerta_trastero).state;

Somebody can help me? Thanks a lot Preformatted text

Please read the pinned post on how to help us help you and format your code properly.

No one can tell if you have indentation errors with the way you posted the code.

1 Like

Hello Mikel,

This might help…
Thanks for coming here and asking a question and welcome to the Home Assistant Forum.
Would you be so kind as to adjusting the format of your code so that we can read it properly & check the YAML spacing, etc. Editing your original is the preferred way. It is very hard for us to tell what is what when the text formatter jumbles everything like that.
You can use the </> button like this… How to format your code in forum posts
OR… Here is an example of how to fix it from the site FAQ Page.
How to help us help you - or How to ask a good question.

now is correct?

1 Like

thanks for all
Now the problem is solve

It would be helpful if you could post the config that works, so other people can benefit.

1 Like