How to create my own lora sensor for HA

Hello, I wanted to create my own Lora sensor with Heltec Wireless Stick Lite. Gateway and Node works fine. The communication is well established but how do I have to create my message to let HA detects this as a sensor? Is there a code example?


You can create an mqtt sensor into your configuration.yaml file, here are more information below:

You can adapt this configuration depending on your msg structure.
Your msg should contains at least an “id” and a “key”, Example:

Moreover I think we need to propose something structured so that it is easier for people using this gateway.

Ok thx for help. I prepared e.g. this msg:


With HA I can extract this msg:

- name: "msg"
      state_topic: "home/MQTTGateway/LORAtoMQTT"
      value_template: "{{ value_json.msg }}"

but how can I extract the json values id, temp, hum, pre from that msg?

Here is an example

        - unique_id: temp_lora
          name: temperature
          state_topic: "home/MQTTGateway/LORAtoMQTT"
          value_template: "{{ value_json.temperature}}"
          state_class: measurement

I created the MQTT sensors in my yaml file as you mentioned. HA show this gatewayLORA msg: {"id":4119,"temperature":23.17,"humidity":50.30,"pressure":1000.23} and HA shows each entity. But there are no values and no updates of my entities.

Could you share your exact configuration.yaml and a copy of your mqtt message with their topic ?

Sure. This is the code of my sensor:

msg = "{\"id\":" + String(id) + ",\"temperature\":" + String(bme.readTemperature()) + ",\"humidity\":" + String(50.3) + ",\"pressure\":" + String(bme.readPressure() / 100.0) + "}";

This is the mqtt yaml section:

     - unique_id: temp_lora
       name: temperature
       state_topic: "home/MQTTGateway/LORAtoMQTT"
       value_template: "{{ value_json.temperature }}"
       state_class: measurement
     - unique_id: hum_lora
       name: humidity
       state_topic: "home/MQTTGateway/LORAtoMQTT"
       value_template: "{{ value_json.humidity }}"
       state_class: measurement
     - unique_id: press_lora
       name: pressure
       state_topic: "home/MQTTGateway/LORAtoMQTT"
       value_template: "{{ value_json.pressure }}"
       state_class: measurement

This is what HA receives:


And this how it looks like after reboot:

@1technophile, I have no glue how to proceed. Can you give me a hint how to get the values?

If you connect MQTT explorer to your server, do you see the json into this topic ?


yes, I do:

> {"rssi":-71,"snr":9.5,"pferror":-92,"packetSize":67,"message":"
> {\"id\":4119,\"temperature\":24.20,\"humidity\":50.30,\"pressure\":1001.95}"}

This should help you:

I don’t know if it can help. To read a value from a device connected to the gateway I do the following :

Then, Listen to a topic : you need to add the name of the device which is connected to the gateway

If you don’t know the device name, you can try to listen to all message : home/#
It will work :

Otherwhise, check with :

Then in YAML file add :

    - name: "TempBureauMQTT"
      state_topic: "home/omg01/BTtoMQTT/D8C0522C7FD5"
      suggested_display_precision: 2
      unit_of_measurement: "°C"
      value_template: "{{ value_json.tempc }}"

In HA, I’m able to see the tempc value :

I have a similar question but for parameters about OMG.
I can’t see the value in the device shape as I set a overflow value of 600000 sec. The value displayed is not correct.
I want to display the value “interval” and “intervalacts” in a display through a sensor created like explained above.

    - name: "omginterval01"
      state_topic: "home/omg01/BTtoMQT"
      #availability_topic: home/omg01/LWT
      unit_of_measurement: s
      value_template: '{{ value_json.intervalacts/1000 }}'

I can see the same in OMG device and MQTT INFO :

But, the value I get into HA is ‘UNKNOWN’

Normally, I can receive the value as it is received in MQTT Listening :

I’m missing something…

Seems a typo in MQTT

1 Like