TTN (The Things Network) Integration

I’ve followed the guide here https://www.home-assistant.io/integrations/thethingsnetwork/ but am stuck at getting the actual sensor information back.

This is what the API (via the TTN Swagger implementation) returns for my elsys-mini device

[
  {
    "accMotion": 0,
    "device_id": "elsys-mini",
    "digital": 1,
    "humidity": 39,
    "pulseAbs": 62,
    "raw": "AQDjAicDAP0/Bw4pCwAAAD4NAQ8AEgA=",
    "temperature": 22.7,
    "time": "2019-12-31T16:59:20.912275196Z",
    "vdd": 3625,
    "waterleak": 0,
    "x": 0,
    "y": -3,
    "z": 63
  }
]

and this is what I have in my configuration.yaml file …


thethingsnetwork:
  app_id: elsys-mini
  access_key: ttn-account-v2.5zdrCnTZtkfyN3lcuCm0u6UXm4z1v[REDACTED!!]
  
sensor:
  - platform: thethingsnetwork
    device_id: elsys-mini
    values:
      sensor_value: digital

I see this in Overview … but never any values … I guess I don’t really follow what needs to be set under sensor: above, and perhaps in values: in particular …

Any pointers much appreciated!

image

1 Like

Ok, this is the answer

sensor:
  - platform: thethingsnetwork
    device_id: elsys-mini
    values:
      humidity: '%'
      temperature: °C
      vdd: mV
      digital: boolean

and you see …

image

1 Like

Great - thank you for sharing this!
But how did you manage to authorize your request to the TTN? I could not get any data. The only evidence there is something wrong is in the home-assistant.log is:
ERROR (MainThread) [homeassistant.components.thethingsnetwork.sensor] Error while accessing: https://my_app_id.data.thethingsnetwork.org/api/v2/query/my_device_id

I have the same issue. Difficult to understand what is wrong, the same URL that is in the error message and the authentication token I use in my configuration works fine if I try it manually with wget.
Is there a bug in recent versions or something?

Ok, figured out it is a certificate issue by adding a printout of the aoihttp error code:

Cannot connect to host <app_id>.data.thethingsnetwork.org:443 ssl:True [SSLCertVerificationError: (1, "[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: Hostname mismatch, certificate is not valid for '<app_id>.data.thethingsnetwork.org'. (_ssl.c:1108)")]

I can make it work by turning off the SSL certificate verification, but it may be a problem on the server rather than with the HA implementation.
So not sure where to report the bug…

1 Like

I think this is the right place. Please check this thread: https://www.thethingsnetwork.org/forum/t/ssl-certificate-for-data-storage-integration-expired/23094/2

Indeed - a new application in the TTN console without an underscore in the name is the solution!

Hello,
I have the same problem, I’m not receiving the sensor values from the TTN to Home Assistant.
sensors
This is my configuration.yaml file:

thethingsnetwork:
  app_id: enviromentalsensing124
  access_key: *accessKey of my application*

sensor:
  - platform: thethingsnetwork
    device_id: placa
    values:
      temperature: ºC
      light: lux 
      pressure: hPa
      humidity: '%' 
      loudness: dB
      airQuality: Analog

And this is what I have in the swagger integration:

{
    "air": null,
    "airQuality": "53.00",
    "air_quality": null,
    "device_id": "placa",
    "humidity": "41.16",
    "light": "96.35",
    "loudness": "184.00",
    "pressure": "951.00",
    "raw": "pmIxMvpDOAAAYTb6QsC1Y2E1+kGvhR9iMTH6QiSlAGIxMPpEbb/NYjEz+kJUAAA=",
    "soundLevel": null,
    "temperature": "21.94",
    "time": "2020-04-23T11:46:53.815340493Z"
  }

At first I had some names with underscore in the TTN that I’m not using anymore after reading this thread but I’m still not receiving values. ¿Any idea what might be happening?

Well, more or less i have the same configuration:

values:

sensor_value: digital

    humidity: '%' 
    pressure: hPa
    temperature: "°C"
    voltage: v

I hope you delete the TTN device from console and create it in new application.
This way of integration is not usable anymore due to limitation to single device.

Thanks for your answer, the problem was that I was using a function that converted my values in String and Home Assistant dind’t understand those values. The solution was to send float values so I have in swagger {“airQuality”: 53.00 } instead of { “airQuality”: “53.00”}

Just to say that I’ve just solved this issue by using the underscore replace trick both in TTN application id AND device id

So thanks for having shared the trick

Hello,

I would like to ask you for your help. I also have a problem adding a sensor from TTN.
The sensor will not appear to me in new entities at all.
I enclose my code below. I already have more other sensors there, so I prefer to put everything here to see if I have a writing error somewhere.

# Integrace TTN sítě
thethingsnetwork:
  app_id: gpstrackermoko
  access_key: mykey
 
 
# Všechny ručně přidaný senzory
sensor:
  - platform: mqtt
    state_topic: "rtl_433/9b13b3f4-rtl433/devices/TS-FT002/156/depth_cm"
    unit_of_measurement: "cm"
    name: "hladinomer_studna"
    icon: "hass:water"
  - platform: template
    sensors:
      vyska_hladiny_studna:
        value_template: "{{ 1050 - states('sensor.hladinomer_studna') | int }}"
        friendly_name: "Výška hladiny"
        unit_of_measurement: "cm"
  - platform: template
    sensors:
      objem_vody_studna:
        value_template: "{{ (states('sensor.vyska_hladiny_studna') | float * 7.853) | round(0) }}"
        friendly_name: "Objem vody"
        unit_of_measurement: "l"
  - platform: template
    sensors:
      zustatek_vody_studna:
        value_template: "{{ (states('sensor.vyska_hladiny_studna') | float * 100) / 400 | round(0) }}"
        friendly_name: "Zůstatek vody"
        unit_of_measurement: "%"
  - platform: thethingsnetwork
    device_id: gpstrackermoko
    values:
      latitude: "°"
      longitude: "°"
        
        

and I see this in Swagger

[
  {
    "battery": null,
    "current_pkt": 1,
    "device_id": "gpstrackermoko",
    "latitude": 49.24961751302083,
    "longitude": 16.674969482421876,
    "raw": "AgHRl5lF8Q/NRA==",
    "sensor": "MOKO LW001-BG",
    "speed": null,
    "time": "2021-04-23T13:36:28.402917556Z",
    "xdir": null,
    "ydir": null
  },
  {
    "battery": "ok",
    "current_pkt": 2,
    "device_id": "gpstrackermoko",
    "latitude": null,
    "longitude": null,
    "raw": "AgIA7FG4PeW5Qv8=",
    "sensor": "MOKO LW001-BG",
    "speed": 0.16668000662326812,
    "time": "2021-04-23T13:36:31.36482964Z",
    "xdir": 475.89,
    "ydir": 653.46
  },
  {
    "battery": null,
    "current_pkt": 1,
    "device_id": "gpstrackermoko",
    "latitude": 49.2495849609375,
    "longitude": 16.6749755859375,
    "raw": "AgHNl5lF9A/NRA==",
    "sensor": "MOKO LW001-BG",
    "speed": null,
    "time": "2021-04-23T13:41:27.215384511Z",
    "xdir": null,
    "ydir": null
  },
  {
    "battery": "ok",
    "current_pkt": 2,
    "device_id": "gpstrackermoko",
    "latitude": null,
    "longitude": null,
    "raw": "AgIAzczMPee5Ov8=",
    "sensor": "MOKO LW001-BG",
    "speed": 0.18520000275969506,
    "time": "2021-04-23T13:41:30.66551637Z",
    "xdir": 475.91,
    "ydir": 653.38
  },
  {
    "battery": "ok",
    "current_pkt": 2,
    "device_id": "gpstrackermoko",
    "latitude": null,
    "longitude": null,
    "raw": "AgIAmpkZPoTe7vA=",
    "sensor": "MOKO LW001-BG",
    "speed": 0.2778000110387802,
    "time": "2021-04-23T13:46:30.610062735Z",
    "xdir": 569.64,
    "ydir": 616.78
  },
  {
    "battery": null,
    "current_pkt": 1,
    "device_id": "gpstrackermoko",
    "latitude": 49.25804850260417,
    "longitude": 16.681817626953126,
    "raw": "AgHdm5lFFx3NRA==",
    "sensor": "MOKO LW001-BG",
    "speed": null,
    "time": "2021-04-23T14:01:26.922208561Z",
    "xdir": null,
    "ydir": null
  },
  {
    "battery": "ok",
    "current_pkt": 2,
    "device_id": "gpstrackermoko",
    "latitude": null,
    "longitude": null,
    "raw": "AgIAZmYmP9Agaf4=",
    "sensor": "MOKO LW001-BG",
    "speed": 1.2037999558448793,
    "time": "2021-04-23T14:01:30.373975185Z",
    "xdir": 84,
    "ydir": 651.29
  }
]

Does someone knows how to deal with integration in The Things stack v3?

Hello, I’m moving from TTN v2 to TTS v3 and I have no v2 devices any more. Maybe it is better to continue in this direction.

Hi Roberto, I have not been able to link my application with homeassistant. I have the following error: "Application ID is not available: ". Could you tell me how you got it with the TTS v3 version? Could it be because of the access_key?

Thank you very much!"

Huh, I’m afraid your issue is not quite clear to me. Anyway, I’ll try to answer and maybe we’ll find out solution together :wink:

Will this help you? Integrating Node RED with The Things Stack - YouTube

But how to integrate TTN v3 node in HA still remains open question to me.

PLEASE update integration to The Things stack v3 !!!
Those who dont know how to move to V3 check out this beautiful blonde’s explanation https://www.youtube.com/watch?v=DL87O5zNE_4![Selection_999(453)|376x344](upload://mLFQ7UG2FpcpBcNSGKKbaKOZFdM.png)

2 Likes

Yes please +1 for Things Stack v3 support. Hopefully that will also resolve the problems for regional servers,

e.g. for Australian users The Things Network Integration Config (Australia Meshed Node)

1 Like

I’m also trying to use the TTN integration with my Home Assistant and am getting “ApplicationID is not available.”. Support for TTN API v3 would be amazing :slight_smile:

3 Likes

got an info from TTN that Home Assistant support/integration is on their task list, they know how important it is, so lets just give them some time

1 Like