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?
Hello,
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:
{"id":123,"tempc":21}
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:
{"rssi":-62,"snr":9.75,"pferror":528,"packetSize":66,"message":"{\"id\":4119,\"temperature\":23.21,\"humidity\":0.00,\"pressure\":1000.49}"}
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
mqtt:
sensor:
- 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:
mqtt:
sensor:
- 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:
{"id":4119,"temperature":22.69,"humidity":50.30,"pressure":996.22}
And this how it looks like after reboot:
If you connect MQTT explorer to your server, do you see the json into this topic ?
home/MQTTGateway/LORAtoMQTT
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:
Hi,
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
D8C0522C7FD5
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 :
mqtt:
sensor:
- 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.
mqtt:
sensor:
- 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