LoRaWan – Probador con OLED en Chirpstack y HomeAssistant

ChirpStack

DECODER

function Decode(fPort, bytes, variables) {
  var Down_rssi = -1*parseInt(bytes[0]);
  var Down_snr = bytes[1];
  var Down_datarate = bytes[2];
  // usando entero
  var unalectura = (bytes[4] << 8) |(bytes[3]);
  unalectura = (unalectura/1000);
  unalectura = +unalectura.toFixed(2);
  var appData = {'Down_rssi':Down_rssi,'Down_snr':Down_snr,
                 'Down_datarate':Down_datarate,
                 'bateria_V': unalectura}
  return appData;
}

ENCODER

function Encode(fPort, obj, variables) {
  var UP_rssi = obj["UP_rssi"];
  // var Up_snr = obj["UP_snr"];
  var mensaje = [UP_rssi];
  return mensaje;
}

Home Assistant

configuration.yaml

mqtt:
  sensor:
    - name: "rssi_up_cc50"
      unique_id: cc27rssiup
      state_topic: "application/1/device/a53ec615aede3f50/event/up"
      unit_of_measurement: "dBm"
      value_template: "{{ value_json.rxInfo[0].rssi}}"
      #availability:
      #  - topic: "home/sensor1/status"
      payload_available: "online"
      payload_not_available: "offline"
      json_attributes_topic: "application/1/device/a53ec615aede3f50/event/up"

Automation

Desencadenante

platform: mqtt
topic: application/1/device/a53ec615aede3f50/event/up

Accion

service: mqtt.publish
data:
  qos: 0
  retain: false
  topic: application/1/device/a53ec615aede3f50/command/down
  payload: '{"confirmed":false,"fPort":4,"object":{"UP_rssi":{{(states("sensor.rssi_up_cc50") | int)*(-1)}}}}'