The Things Network (TTN) - new adapter for v3

As TTN v2 has been replaced with v3 I have rewritten the adapter to support the new protocol. I have been using for over a year (started in v2) with over 50 adapters.

Some highlights:

  • Supports setup from the UI
  • Devices and channels can be renamed using the adapter extra settings
  • Can be installed/updated with HACS - add as extra repository

How to install:

  1. Enable persistent storage in TTN: Storage Integration | The Things Stack for LoRaWAN I have tested with the EU endpoint
  2. Install the TTN adapter in HA
  3. Configure adapter in HA: Configuration ā†’ Device and Settings ā†’ Add Integration ā†’ Search for The Things Network

If there is interest in adding to the core I would prepare a PR.

UPDATE - 2024-03-16T23:00:00Z

The decision is to merge into HA core - WIP at Deprecated TheThingsNetwork - replace or remove? Ā· Issue #112491 Ā· home-assistant/core Ā· GitHub

9 Likes

Hi there,

Great that you made a new adapter for TTN V3 .
Installed it and it works .
I have one problem and maybe you can help me .
I have a Lora node (The things node) which provides 4 different values

1 Battery level
2 Event ( shows a value ''button" when the button on the node is pressed )
3. Light
4.Temperature

only the event works correct

Now with Temperature i get as a value in HA ā€œNaNā€
and for battery i get ā€œ1026ā€ (its has 4.5 volt power
and for light i get ā€œ465ā€

I saw that your integrations has ā€œ'fieldsā€ settings , how do i put these right?

Or is there something in my TTN Applications settings which is not correct ?

Hope you can help me

Good to hear it works for you!

The integration just displays the states as parsed by TTN - from the values you have it looks like those are raw values and not human readable. You can set parsers in TTN to convert what your Node sends to Volts or Ā°C.

The fields setting allow you to define the mapping from fields (the different values parsed by TTN) to Home Assistant states. I use the Cayenne format in my Nodes so the fields in TTN are called <measurement type such as digital, analog, temperature>_<channel> so in my integration I renamed those to what they represent in the sensor such as version or inside_temperature

You can also use the fields setting to assign info missing in TTN but useful in HA such as icon and unit name.

2 Likes

Thanks for the quick reply, how do i set parsers in TNN (im not a expert on TTN)

Check the payload formaters. If your device uses Cayene then you can select it and you are done. If you mix devices or your device has its own format for the payloads either the javascript (what I use) or the (new with TTN3) Repository formaters will be needed.

You need to ensure that when you receive an uplink the formarter adds a decoded_payload that has the different sensors and their human readable values into them. Example:

"decoded_payload": {
        "analog_in_3": 3.04,
        "digital_in_1": 8,
        "raw": [
          1,
          0,
          8,
          1,
          0,
          8,
          3,
          2,
          1,
          48,
          41,
          103,
          0,
          15,
          40,
          104,
          132
        ],
        "relative_humidity_40": 66,
        "temperature_41": 1.5
      },

The raw is what TTN received from the device and the other values are added by the payload formater. The TTN consode allows to test your formater until it looks good. In case you need help with this part they have a forum where if you post your device they might point you to existing/recomended formarters.

I mostly use my own built PCBs so I am not so familiar with commercial Lorawan devices and their payloads. And in my devices I ensure to use Cayene as format to keep it simple so I mostly do not have to touch anything in TTN when I add new devices. Kind of like esphome but for lorawan devices :slight_smile:

2 Likes

Great with your help it works now like i want.
I just needed to put a uplink payload formatter javascript.
and they had a thingsnode example file at their website :slight_smile:

And now all my sensors show the correct value.
and i can go further, and put my mailbox notifier in my letterbox to see when mail is dropped (8 floors down.
I connected a reedswith to the button on my node, so when the lid goes open i get notified.

Thanks again for all the help

1 Like

Good to hear it works for you! :slight_smile:

Hello all,
thanks for the plugin and the update to TTNv3. I have a Dragino LHT65 LoRaWAN Temperature & Humidity Sensor running.
However, I have problems with a Milesight MIL WS522-858M16 portable socket that I canā€™t reach with the plugin.
I have registered the part in TTN, there it also gives data from itself:

However, unlike the Dragino sensor, I can not configure the adapter in Homeassistant: It simply does not appear in the overview of the plugin => Devices. I only see the Dragino Sensor:
2022-02-28_10-17

Where do I have to start to solve the problem?

Thanks in advance for your help,
Thomas

I installed the Repository via the custom repository: GitHub - angelnu/home_assistant_thethingsnetwork

Cannot find it in the integrations as described though - can you please advice if the above repository is the correct one?
Thanks

Update: Now I have it: It did not show up as I used Home Assistant with the German user interface.
After I changed the language to English it showed up and all is fine.

Let me know if (and how) I can help with translation to German if you like.

Thanks

Albert

I have not tried to add translations but it should work by adding a new file with the translated strings to: home_assistant_thethingsnetwork/custom_components/thethingsnetwork/translations at master Ā· angelnu/home_assistant_thethingsnetwork Ā· GitHub I will add one for german initially with the english values - PR with the translations is welcome!

I should be able to register it HACS to make it easier to find if enough people want to use it. The other option would be replacing the default core integration as it will not longer work (TTN v2 only).

2 Likes

Hi @angelnu

Just a quick note to say thanks.
Installedā€¦ configured and just worked first go. (using the au1 TTN server)

I have successfully integrated a couple of my TTN sensors. No hassles and no fuss.

Great work!

Ben

1 Like

Glad to hear!

I assume you had to manually tweak the URL for the TTN backend - I still have to add the option to change it in the adapter endpoint. Maybe next weekend :slight_smile:

1 Like

Thanks angelnu for providing this integration! I noticed that your were just working on it these days. I have just entered the world of LoRaWAN & TTN and I thought adding the first sensor to my HA installation would be easy going. Not only is LoRa & TTN confusing enough (itā€™s CB radio of 70s combined with internet) but the installation of your adapter was a nightmare of user experience. I am not blaming you for this. It is what it is. Needed to upgrade HA docker image on my QNAP NAS. SSH dive into it and install HACS with shell script. Create GitHub account for verification. Enable persistance in TTN and create mile long IDsā€¦ But finally I got my first LoRa sensor result in HA. I am happy and thanks for it!

Yep, it would benefit from a good Getting Started tutorialā€¦ As you say configuring the devices, attaching them to TTN, configure the storage plugin and then finally deploy the adapter to HA is a lot to learn before you get the first data to play with.

But afterwards is a lot of fun and, with devices ready with low battery usage, a very low maintenance cost.

Iā€™m getting Invalid Add-0n repository when trying to add https://github.com/angelnu/home_assistant_thethingsnetwork Should it still be available?

It is still working for me on the latest HA and HACS - any error in the log?

Thanks for getting back to meā€¦

All up to date and running on a proxmox vm. Got other repositories installed. Going to try adding another repository to see if it is a generic issue with my new installation.

Home Assistant Core 2022.5.5

Home Assistant Supervisor 2022.05.3

Home Assistant OS 8.1

Logger: homeassistant.components.hassio
Source: components/hassio/websocket_api.py:120
Integration: Home Assistant Supervisor (documentation, issues)
First occurred: May 24, 2022, 9:29:37 PM (14 occurrences)
Last logged: 6:53:08 AM

  • Failed to to call /ingress/validate_session -
  • Failed to to call /supervisor/options - Invalid Add-on repository!
  • Failed to to call /supervisor/options - expected a URL @ data[ā€˜addons_repositoriesā€™][4]. Got ā€˜GitHub - angelnu/home_assistant_thethingsnetworkā€™
  • Failed to to call /supervisor/options - expected a URL @ data[ā€˜addons_repositoriesā€™][4]. Got ā€˜hacsā€™

The addon needs to be installed with hacs. It is not a surpervisor extension. Is this The problem perhaps?

Thanks for getting back to me. I was doing it the same way as the other add-ons. From the latest version, it is settings > add-ons > ADD-ON STORE > repositories then paste the github address into the Add field. I was surprised by the mention of supervisor in the logs but thought that was a legacy thing.

Ok, that explains it - it is not an addon repository.

You will need to install HACS