Following the obsolescence of TTN V2 (The Things Network( being replaced by The Things Stack V3 that has none integratiom so for in HA, I’m trying to find an alternate way to use my Lora sensors in HA. I was thinking to use the MQTT gateway of TTS but it doesn’t use the standard login/pass but an API key which is not supported by MQTT integration in HA.
Someone found out a way to integrate Lora sensors on TTS (TTN V3) in HA or is there no workaround till someone develops an integration for TTS ?
Mosquitto has the concept of a mqtt-bridge, e.g. one broker acting as a client to another mqtt broker.
So
HA → Mqtt using login and password to mosquitto → mosquitto using api-key to TTS mqtt server
yep right, forgot about these but in fact found out that API key is basically the MQTT password at TTS So I have setup an MQTT client in HA to connect at TTS one. Now I’m investigating how I can access these datas in HA and if HA connects well at TTS MQTT server
@vincen Could you show me your configuration? I have upgraded from V2 to V3, but I am not able to get a valid connection to the new mqtt service at TTS.
Edit: I see now that you probably are not using mosquitto in bridge mode as I do.
@stigvi I have managed to get it working (I’m preparing a blog post to explain whole process and will share link here) but basically I have added a bridge configuration at Mosquitto addon in hassio like that (to duplicate for each device on Lora that you want to get data from):
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
I have then configured a JSON filter on uplink in TTS console to decode payload and in HA configuration here is sample code from one of my sensor (Dragino LHT65 in that case):
Side note: I have used a mqtt client on my computer connected at TTS MQTT server to get proper state topic to use easily
Please post complete logs of mqtt once restarted the MQTT server and check in same time if you see MQTT connection showing up in console in TTN/TTS You should see An Application subscribed or something similar in TTN console of the device (in verbose mode) when your MQTT server reconnects at TTN/TTS !
I’m struggling a bit, my config is very similar to yours and I have clearly mqtt working as mqtt-explorer with the same API key/username works just fine (i can see it registering in the TTNv3 console etc) - so I think it must be my mosquitto config but I’m not sure what since it seems seems happy:
Dec 11 13:02:07 box1 mosquitto[9831]: 1639224127: mosquitto version 2.0.13 starting
Dec 11 13:02:07 box1 mosquitto[9831]: 1639224127: Config loaded from /etc/mosquitto/mosquitto.conf.
Dec 11 13:02:07 box1 mosquitto[9831]: 1639224127: Opening ipv4 listen socket on port 1883.
Dec 11 13:02:07 box1 mosquitto[9831]: 1639224127: Opening ipv6 listen socket on port 1883.
Dec 11 13:02:07 box1 mosquitto[9831]: 1639224127: Connecting bridge TTN3 (eu1.cloud.thethings.network:8883)
Dec 11 13:02:07 box1 mosquitto[9831]: 1639224127: mosquitto version 2.0.13 running
My problem turns out to be indeed the CA files not being loaded, it seems in some distros mosquitto will not go look in /etc/ssl and fails silently.
Adding this worked a treat bridge_capath /etc/ssl/certs
@rancho check that your mosquitto config file contains these directives:
customize:
active: true
folder: mosquitto
and put the extra config indicated previously in /mosquitto/bridge.conf file (I access it through samba share (hassio add-on) on my hassio machine and then restart mosquitto and you should be good (open the console of the device on TTS website before restart of mosquitto and you should see the mosquitto connection when you restart it and if everything is good
how to visualise the decoded payload in home assistant? i see this with mosquitto “decoded_payload”:{“airHum”:54.08,“airPres”:1023.35,“airTemp”:8.39,“bat”:91,“e25”:21.4,“ec”:0,“leak”:0,“lux”:0.91,“temp”:5.99,“valv”:0,“vwc”:36} somehow with template i guess
Please check previous posts (extract below) in thread where I explain how I did to check messages received through MQTT and be able to decode it properly in HA
@vincen next issue: how can i add the second application definition in the configuration.yaml?
thethingsnetwork:
app_id: app1
access_key key1
but how to add more, app2 and key2?
UPDATE: looks like this only needed for the old V2 version of TTN, now all traffic comes via the MQTT bridge, so the TTN integration is basically outdated and useless. Correct me if i am wrong
You mean for an other device you have in TTN ? You create as many mqtt bridges as devices with a different identifier each and then rest similar
Yep as we are orphan of an integration for TTS we have to use for now the mqtt bridge but it’s robust, I have it setup here for something like six months and never had any issue with it like typical lora stuffs, you setup them and they run alone for years
ok mate, all clear now, i removed the old TTNv2 configs so i used only which works, and thats your bridge solution. Thanks so much. TTN keeps making videos for IoT in angriculture but they dont even support the small farmers and home assistant users… Strange but thats how it is.
Good to hear it works all good Well they can’t support all platforms and as far as I know TTN integration was not done by them ! They are pushing too much to use cloud stuffs while we can do everything locally and independant of any external things !