fabrizio97726

Lora receiver 433

Jul 27th, 2025 (edited)
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 3.63 KB | None | 0 0
  1. esphome:
  2.   name: lora-2
  3.   friendly_name: lora-2
  4.  
  5. esp32:
  6.   board: esp32dev
  7.   framework:
  8.     type: arduino
  9.  
  10.  
  11. # Enable logging
  12. logger:
  13. # Enable Home Assistant API
  14. api:
  15.   encryption:
  16.     key: ""
  17.  
  18. ota:
  19.   - platform: esphome
  20.     password: ""
  21.  
  22. wifi:
  23.   ssid: !secret wifi_ssid
  24.   password: !secret wifi_password
  25.   use_address: 192.168.68.91
  26.  
  27.   # Enable fallback hotspot (captive portal) in case wifi connection fails
  28.   ap:
  29.     ssid: ""
  30.     password: ""
  31.  
  32. captive_portal:
  33. web_server:
  34.   port: 80
  35.   version: 3
  36.   include_internal: true
  37.   local: true  
  38.  
  39. spi:
  40.   clk_pin: GPIO5
  41.   mosi_pin: GPIO27
  42.   miso_pin: GPIO19  
  43.  
  44. # CONFIGURAZIONE LORA COMPONENTE SX 1276
  45. sx127x:
  46.   dio0_pin: GPIO26
  47.   cs_pin: GPIO18
  48.   rst_pin: GPIO23 # verificare versione scheda
  49.   pa_pin: BOOST
  50.   pa_power: 15
  51.   bandwidth: 125_0kHz
  52.   crc_enable: true
  53.   frequency: 433920000
  54.   modulation: LORA
  55.   rx_start: true
  56.   sync_value: 0x12
  57.   spreading_factor: 7
  58.   coding_rate: CR_4_5
  59.   preamble_size: 6  
  60.   on_packet:
  61.     then:
  62.       - lambda: |-
  63.           ESP_LOGD("lambda", "packet %s", format_hex(x).c_str());
  64.           ESP_LOGD("lambda", "rssi %.2f", rssi);
  65.           ESP_LOGD("lambda", "snr %.2f", snr);    
  66.           id(last_rssi) = rssi;
  67.           id(lora_packet_count) += 1;
  68.           ESP_LOGI("lora", "Pacchetto ricevuto. Totale: %d", id(lora_packet_count));
  69.           id(lora_sent_count) += 1;
  70.           ESP_LOGI("lora", "Pacchetto inviato. Totale: %d", id(lora_sent_count));
  71.  
  72. globals:
  73.   - id: last_rssi
  74.     type: float
  75.     restore_value: no
  76.     initial_value: '0.0'
  77.  
  78.   - id: lora_packet_count
  79.     type: int
  80.     restore_value: no  # se vuoi mantenere il conteggio dopo il riavvio
  81.     initial_value: '0'
  82.  
  83.   - id: lora_sent_count
  84.     type: int
  85.     restore_value: no  # mantiene il conteggio al riavvio
  86.     initial_value: '0'    
  87. sensor:
  88. #WIFI
  89.   - platform: wifi_signal
  90.     name: "WiFi Signal lora 1"
  91.     update_interval: 15s
  92.     filters:
  93.       - sliding_window_moving_average:
  94.           window_size: 15
  95.           send_every: 15
  96.           send_first_at: 15
  97.     icon: mdi:wifi    
  98.  
  99.   - platform: template
  100.     name: "LoRa RSSI"
  101.     unit_of_measurement: "dBm"
  102.     accuracy_decimals: 1
  103.     update_interval: 5s
  104.     lambda: |-
  105.       return id(last_rssi);    
  106.  
  107.   - platform: template
  108.     name: "LoRa Pacchetti Ricevuti"
  109.     lambda: |-
  110.       return id(lora_packet_count);
  111.     update_interval: 5s
  112.     unit_of_measurement: "pkt"
  113.     accuracy_decimals: 0      
  114.  
  115.   - platform: template
  116.     name: "LoRa Pacchetti Inviati"
  117.     lambda: |-
  118.       return id(lora_sent_count);
  119.     update_interval: 10s
  120.     unit_of_measurement: "pkt"
  121.     accuracy_decimals: 0                
  122.    
  123. # Example configuration entry
  124.  
  125.  
  126. packet_transport:
  127.   platform: sx127x
  128.   update_interval: 1s
  129.   encryption: "fabrizio"
  130.   rolling_code_enable: true
  131.  
  132.   binary_sensors:
  133.    - rele_lora2
  134.  
  135.   providers:
  136.     name: lora-1
  137.     encryption: "fabrizio"  
  138.  
  139. button:
  140.   - platform: restart
  141.     name: "Restart"
  142.  
  143.   - platform: template
  144.     name: "Apri cancello box lora 2"
  145.     id: apri_cancello_box_lora_2
  146.     icon: "mdi:gate"
  147.     on_press:                      
  148.       - switch.turn_on: rele
  149.       - delay: 3s                
  150.       - switch.turn_off: rele          
  151.  
  152. switch:
  153.   - platform: gpio
  154.     pin: GPIO12
  155.     name: Relè
  156.     id: rele
  157.  
  158. binary_sensor:
  159.   - platform: packet_transport
  160.     provider: lora-1
  161.     id: rele_lora1
  162.     on_press:
  163.       switch.turn_on: rele
  164.     on_release:
  165.       - delay: 2s                  
  166.       - switch.turn_off: rele  
  167.    
  168.  
  169.   - platform: template
  170.     id: rele_lora2
  171.     lambda: return id(rele).state;
  172.  
  173.  
Advertisement
Add Comment
Please, Sign In to add comment