The Things Network (TTN) - new adapter for v3

The issue is - HA sees the sensor data as a message - and is not parsing out the relevant values. In TTN, im using the device specific payload formatted.

So as u can see above - HA sees “messages” as a sensor. It would seems like HA should see the 3 or 4 values within the messages as the sensors.

It’s not HA but the integration and you can’t do anything about it that’s why I suggest you since few messages to use the MQTT way as you can then easily extract any data you need :wink:

Im trying MQTT - but im having a problem.

I configure the MQTT broker in HA with the host, and username/password - but nothing populates in devices, MQTT.
And i know the Ttn MQTT is working bc if i go to any program that receives MQTT feeds, it will work.

Nothing here is showing up as a device -
image

This is the set up w the proper credentials that receives data if i try to listen for it on other devices.

It’s absolutely not the way to do it ! Please look at link in my previous posts where I explain how to configure HA MQTT add-on to get it to communicate it with TTN :wink: You have to create a bridge configuration !

1 Like

I am not seeing your instructions on creating a bridge. where should I look? I looked at post #41 - but im not seeing instructions there

have a loot at my post there: The Things Stack integration ? (on TTN V3)? - #5 by vincen

so if I understand the sequence correctly

  1. go to add on’s - go to the mqtt broker app configuration -
    change the text to
logins: []
customize:
  active: true
  folder: mosquitto
certfile: fullchain.pem
keyfile: privkey.pem
require_certificate: false
anonymous: false

from

then - add

connection nameitasyouwant
address eu1.cloud.thethings.network
bridge_protocol_version mqttv311
remote_username xxxxx@ttn (to get on device profile page in TTS console)
start_type automatic
notifications false
try_private false
remote_password NNSXS.XXXXXXX (named API keys in TTS console)
bridge_insecure true
topic # in 0
cleansession true

if this is correct - where do I put the above code? I dont see a folder named mosquito? where would I look - or does this get entered in an integration?

absolutely not needed, never indicated that in post linked above :wink:

it has to be put in a bridge.conf file that you’ll save in /share/mosquitto folder in HA :wink: If it’s properly done, when you restart the mqtt addon you’ll see in logs that it connects the bridge ! something similar to that:

[10:56:31] INFO: Starting mosquitto MQTT broker...
1684400191: Loading config file /share/mosquitto/bridge.conf
1684400191: Warning: Bridge dragino-ttn-bridge using insecure mode.
1684400191: Warning: Bridge boutons-inputs using insecure mode.
1684400191: Warning: Bridge tracker-tbeam-ttn-bridge using insecure mode.
1684400191: Warning: Bridge trackit-ttn-bridge using insecure mode.
2023-05-18 10:56:31: Warning: Mosquitto should not be run as root/administrator.
[10:56:32] INFO: Successfully send discovery information to Home Assistant.
[10:56:32] INFO: Successfully send service information to the Supervisor.

ahh, ok. starting to understand

in terms of the file location that im going to add - i can find 2 share directories. one is /share and is currently empty, and the other share directory is - usr/share/

do I put the /mosquitto/bridge.conf file in the first directory that is currently empty?

many thx for the help

I created bridge.conf in /share/mosquito

the bridge file is -

connection XXXXXlora
address nam1.cloud.thethings.network
bridge_protocol_version mqttv311
remote_username my-XXX-XXX@ttn (to get on device profile page in TTS console)
start_type automatic
notifications false
try_private false
remote_password NNSXS.00000000000000000000000UI.ABCDEFGHM53ZRLKTKEL5DAXPSVZ27IDIEM7YWJUAG3PHQ (named API keys in TTS console)
bridge_insecure true
topic # in 0
cleansession true

and now im seeing in the ttn log -

invalid authorization -

{
  "name": "as.mqtt.connect.fail",
  "time": "2023-05-18T12:12:09.714448981Z",
  "identifiers": [
    {
      "application_ids": {
        "application_id": "my-hamp-soil"
      }
    }
  ],
  "data": {
    "@type": "type.googleapis.com/ttn.lorawan.v3.ErrorDetails",
    "namespace": "pkg/identityserver",
    "name": "invalid_authorization",
    "message_format": "invalid authorization",
    "correlation_id": "370a70acd0e1435e9d5f2b2364b32f8b",
    "code": 16
  },
  "origin": "ip-10-101-14-141.us-west-1.compute.internal",
  "context": {
    "tenant-id": "CgN0dG4="
  },
  "visibility": {
    "rights": [
      "RIGHT_APPLICATION_TRAFFIC_READ"
    ]
  },
  "unique_id": "01H0QCCN3JGQCEGD6TWGCANFAJ"

and in the mqtt add on log -

2023-05-18 08:13:18: Received CONNACK on connection local.core-mosquitto.hampttnlora.
2023-05-18 08:13:18: Connection Refused: not authorised
time="2023-05-18T08:13:48-04:00" level=debug msg="found in cache: XXXXX"
2023-05-18 08:13:18: Client local.core-mosquitto.hampttnlora closed its connection.

and in TTN - under applications - im setting up integrations - mqtt - to get the key that im using that seems to be saying invalid

ok, seem to be making progress…

had to turn the false to true in the mqtt config.

and now see in the mqtt logs -


[06:44:02] INFO: Starting mosquitto MQTT broker...
1684493042: Loading config file /share/mosquitto/bridge.conf
1684493042: Warning: Bridge hampttnlora using insecure mode.
2023-05-19 06:44:02: Warning: Mosquitto should not be run as root/administrator.
[06:44:03] INFO: Successfully send discovery information to Home Assistant.
[06:44:03] INFO: Successfully send service information to the Supervisor.

now the question is - where should the ttn data be visible? in the ttn integration or in the mqtt integration? I was thinking in the mqtt integration - and just log into the local mqtt broadcast - as I thought this would be bridged to show everything? unless im mis understanding.

It’ll show up through the mqtt broker (forget the TTN integration and best to disable it :wink:
I strongly suggest to use an app such as MQTT Snooper on your phone (Android only here sorry) and you connect it at TTN with same credentials you used for the bridge and it’ll allow you to “see” messages sent by TTN and know how to decode it :wink:
You then use JSON logic to extract data you want ! Here are some few examples for a button, a VOC sensor and get battery level of sensor :slight_smile:

mqtt:
  sensor:
# Boutons
    - state_topic: "v3/buttons-xxxxxxx@ttn/devices/boutons-1/up"
      name: Bouton 1
      value_template: '{{ max(0,value_json.uplink_message.decoded_payload.button_pressed|int(0)) }}'
      state_class: measurement
# Mural
    - state_topic: "v3/sonde-xxxxxx@ttn/devices/rak3172-ambient/up"
      name: “Mural VOC 16”
      value_template: '{{ value_json.uplink_message.decoded_payload.data.voc_16 }}'
      state_class: measurement
    - state_topic: "v3/sonde-xxxxx@ttn/devices/rak3172-ambient/up"
      name: “Mural Batterie”
      value_template: '{{ value_json.uplink_message.decoded_payload.data.voltage_1 }}'
      state_class: measurement
      unit_of_measurement: V

ok, will try now

If this is what im getting from the MQTT snooper - how do i format that to the configuration.yaml
All of this is from a sensor


    "application_ids": {
      "application_id": "my-hamp-soil"
    },
    "dev_eui": "2CF7F1C044300918",
    "join_eui": "D85D8ED2E9FB2C50",
    "dev_addr": "260C42FF"
  },
  "correlation_ids": [
    "as:up:01H0T5S01Z0WGCH3CXQNP991RA",
    "gs:conn:01H0J9SVR5QHBA1CM8W15XW8HV",
    "gs:up:host:01H0J9SVWFHSY7BYG6PZXKA6TS",
    "gs:uplink:01H0T5RZVG0T1M7Z0G3VY1Y43S",
    "ns:uplink:01H0T5RZVHAB9SZZRV45DC8K7Y",
    "rpc:/ttn.lorawan.v3.GsNs/HandleUplink:01H0T5RZVHF3KVR5FK3WMBNFJT",
    "rpc:/ttn.lorawan.v3.NsAs/HandleUplink:01H0T5S01YFTVWHD1QSGA2TVCS"
  ],
  "received_at": "2023-05-19T14:14:17.406699928Z",
  "uplink_message": {
    "session_key_id": "AYgK9AksNKT8Ikp4C69CSw==",
    "f_port": 2,
    "f_cnt": 249,
    "frm_payload": "AQwQFAAAAAEGEBBAAAABBxDYcgAAnqA=",
    "decoded_payload": {
      "err": 0,
      "messages": [
        {
          "measurementId": 4108,
          "measurementValue": 0.02,
          "type": "report_telemetry"
        },
        {
          "measurementId": 4102,
          "measurementValue": 16.4,
          "type": "report_telemetry"
        },
        {
          "measurementId": 4103,
          "measurementValue": 29.4,
          "type": "report_telemetry"
        }
      ],
      "payload": "010C101400000001061010400000010710D87200009EA0",
      "valid": true

Where
4108 is Electrical Conductivity
4102 is soil temp
4103 is soil moisture

this is a snapshot of what I receive in mqtt_explorer :

 "received_at": "2023-05-20T10:14:02.345537991Z",
    "uplink_message": {
      "session_key_id": "AYgK9AksNKT8Ikp4C69CSw==",
      "f_port": 2,
      "f_cnt": 269,
      "frm_payload": "AQwQFAAAAAEGELA2AAABBxAQcgAAQMk=",
      "decoded_payload": {
        "err": 0,
        "messages": [
          {
            "measurementId": 4108,
            "measurementValue": 0.02,
            "type": "report_telemetry"
          },
          {
            "measurementId": 4102,
            "measurementValue": 14,
            "type": "report_telemetry"
          },
          {
            "measurementId": 4103,
            "measurementValue": 29.2,
            "type": "report_telemetry"

what json code do I enter for value_template to decode -

the id’s correspond to sensor fields - like 4103 would be moisture - how do I tell HA to display the measurementValue from a given measurementID?

Enter the full JSON output here:
https://jsonpathfinder.com/
You can then find the path to the values for the templates on the right-hand side.

Have you done the configuration of the sensor ? as you should be able also to setup it to use different names for different sensors which makes it easier to extract data ! What sensor are you using ?

Hi there, looks like an awesome add-on, thank you!

Can sometime tell me if this would work for an on-premise version of Things Stack Community version? It appears the add-on needs the Storage Integration component which isn’t available in the community version. I tried to re-compose my environment but throws an error:

user@stack:~/the-things-stack$ sudo docker-compose run --rm stack storage-db init
Creating the-things-stack_stack_run … done
The storage integration is not available in the open-source version of The Things Stack.
For more information, see Storage Integration | The Things Stack for LoRaWAN
error:cmd/ttn-lw-stack/commands:storage_integration_not_available (Storage Integration not available)

I guess the only alternative is through MQTT bridge or perhaps Node-Red to pull/push data?

Thanks for any insights…

Tom

Nope it’s not done for on-premise version and I would strongly suggest in all matters to interface it using MQTT and not integration as integration is not really great and works not really great too ! MQTT is a little more work but so much more reliable :wink:

For me, MQTT was very easy. I installed the MQTT client (not broker). I connected it to host eu1.cloud.thethings.network port 1883, with username and api-key.
Then in my configuration.yaml I defined the mqtt sensors like this:

mqtt:
- sensor:
    name: ttn_gpssensor
    state_topic: "v3/me-ttn-app1@ttn/devices/tbol100/location/solved"
    value_template: '{{ value_json["location_solved"]["location"] }}'
    unique_id: test123
    json_attributes_topic: "v3/my-ttn-app1@ttn/devices/tbol100/location/solved"
    json_attributes_template: '{{ {"received_at": value_json.received_at} | tojson }}'

For finding the right values I used the mqtt client “mosquitto_sub”:

mosquitto_sub -h eu1.cloud.thethings.network -p 8883 -t "#" -u "me-ttn-app1@ttn" -P "NNSXS.JSWH...................EFOPLN" -d