Capturing data from on_packet event to a sensor?

Hey everyone! First time posting here.

I’ve got two LoRa sensors talking with each other, sending data. Love it, and it works! YAY!

I’m curious if there is a way to save RSSI as a sensor entity? The only way I know to capture RSSI is via example code using logs during “on_packet” event. Hoping to somehow capture this data to a sensor so I can track the signal strength and noise over time.

# LoRa Radio Configuration (SX1262)
sx126x:
  .........
  on_packet:
    - lambda: |-
        ESP_LOGD("lora", "Received packet RSSI: %.2f dBm, SNR: %.2f dB, Data: %s",
                 rssi, snr, format_hex(x).c_str());

Anyone have thoughts how to capture the variable data (‘rssi’ and ‘snr’) from “on_packet” event to a sensor template?

It should be noted, that I did try to SET the state of a sensor, rather than reading a state. Doesn’t look like I can?

# LoRa Radio Configuration (SX1262)
sx126x:
  .........
  on_packet:
    - lambda: |-
        ESP_LOGD("lora", "Received packet RSSI: %.2f dBm, SNR: %.2f dB, Data: %s",
                 rssi, snr, format_hex(x).c_str());
        id(rssi).state = rssi;

sensor:
...
  - platform: template
    name: "LoRa RSSI"
    id: rssi
    unit_of_measurement: dB

I’m not familiar with this component but give it a try like this:

sensor:
  - platform: template
    name: "LoRa RSSI"
    id: lora_rssi
    unit_of_measurement: "dBm"
    update_interval: never   

 
on_packet:
  - lambda: |-
      id(lora_rssi).publish_state(rssi);
      
1 Like

This is exactly what I needed! Thank you!

You’re welcome!