LoRaWan Decoders~
- Introduction
- Adding Payload Data Decoding
- Example LwDecoded MQTT message
- Files
- How to use the Device Decoder feature
- Write your own Device Decoder file
- Home Assistant Discovery
Introduction~
LoRaWan end devices transmit packets containing raw Payload Data. The Tasmota LoRaWan Bridge feature normally passes the raw Payload Data onto an MQTT server.
{
"LwReceived": {
"0xAE3D": {
"Node": 1,
"Device": "0xAE3D",
"RSSI": -14,
"SNR": 8.8,
"Decoder": "LHT52",
"DevEUIh": "A840414E",
"DevEUIl": "4F5CAE3D",
"FPort": 2,
"Payload": [9,230,2,48,127,255,1,104,33,178,172]
}
}
}
Adding Payload Data Decoding~
There are no industry standards on the format or content of the raw data send by each sensor; every manufacturer/device is different. There are public databases of decoder scripts for many devices; e.g. TTN decoder script database
The Tasmota LoRaWAN Decoder feature: - is optional
- is implemented in Berry - does not require any custom builds - the elements are: - a Berry script LwDecode.be that: - subscribes to the tele/xxxx/SENSOR MQTT messages, looking for the LwReceived packets sent by the Tasmota LoRaWAN Bridge. - dynamically loads (once only) Device Decoder Files from the Tasmota file system, if they exist. - asks a Device Decoder File to decode the raw Data Payload - reports the result via MQTT - Device Decoder Files: - are written in Berry - closely modelled on the TTN decoder script database.
Example LwDecoded MQTT message~
{
"LwDecoded": {
"0xAE3D": {
"TempC_Internal": 25.34,
"Ext_SensorType": 1,
"Systimestamp": 1747038892,
"Device": "Dragino LHT52",
"Ext_SensorConnected": false,
"Hum_Internal": 56
}
}
}
Files~
These files are available from the Tasmota Github Repository
- LwDecoder.be
- Device Decoder Files (indexed by Vendor/Model)
How to use the Device Decoder feature~
- Download to your local PC, then upload to the Tasmota File System
- LwDecode.be
- the Device Decoder File(s) for your End Device(s), or write your own (see below)
- Add this line to
autoexec.bein the Tasmota File System (create if necessary)
load("LwDecode.be") - Execute these Tasmota Console commands:
LoRaWanAppKey<x> yyyyyyyy
where<x>is the Tasmota LoRaWAN node number. Joins an End Device to the LoRaWan Bridge. See LoRaWan Commands.LoRaWanDecoder<x> <decoderfile>where<x>is the Tasmota LoRaWan node number. Sets the name of the Decoder File for each end device.
e.g.LoRaWanDecoder1 LHT52associates node 1 with theLHT52.bedecoder fileBrRestartto restart Berry
Write your own Device Decoder file~
- Find the JavaScript (*.js) decoder file for your device from TTN Device Decoder database
Alternatively, find the manufacturer's datasheet/User Guide/User Manual/etc. to learn the syntax of the Raw Data Payload - Edit LwDecoderSample.be to decode the Raw Data Payload
- Rename
LwDecoderSample.beto<DeviceName>.bewhere<DeviceName>matches your device name. - Copy
<DeviceName>.beto the Tasmota File System. -
Test
load("<DeviceName>.be")from the Berry Scripting Console, looking for any reported errors.- Execute this Tasmota console command:
LoRaWanDecoder<x> <DeviceName>
- Execute this Tasmota console command:
- Wait for your device to send raw Data Payloads to your Tasmota installation, and confirm
LwDecodedMQTT messages are received, and the values are correct:
-
Submit a PR to share your new decoder with the Tasmota community.
Home Assistant (HA) Discovery~
Tasmota has a built-in feature that reports device info to the HA Tasmota Integration at bootup.

Optionally, the LoRaWAN sensors can also be reported to HA using MQTT Discovery

To add HA LoRaWAN sensor discovery 1. Edit the Decoder file to add these two functions. Example 1. deviceInfo() 2. HAssSensors()
How it works~
If SetOption19 is 0 (default) then: 1. Device discovery to the HA Tasmota Integration is enabled 1. LoRaWAN sensor discovery to HA is enabled
When the first LoRaWAN data packet from a paired device is received and decoded after bootup, and if the associated decoder file has the optional functions (above), a series of HA discovery MQTT messages are sent. One for each sensor.
Example
{
"dev":{
"mdl":"LHT52",
"ids":"5390B0",
"name":"T3S3",
"mf":"Dragino"},
"o":{
"name":
"T3S3"},
"name":"Battery Voltage",
"ic":"mdi:current-dc",
"uniq_id":"tasmota_34B7DA5390B0_BattV",
"pl_not_avail":"Offline",
"val_tpl":"{{value_json['LwDecoded']['LHT52']['BattV']}}",
"unit_of_meas":"V",
"stat_t":"tele/LWG-T3S3_5390B0/SENSOR/A840414E4F5CAE3D",
"device_cla":"voltage",
"pl_avail":"Online",
"avty_t":"tele/LWG-T3S3_5390B0/LWT",
"state_cla":"measurement"
}