angelnu / home_assistant_thethingsnetwork

TheThingsNetwork v3 integration for Home Assistant
33 stars 8 forks source link

Iotracker GPS #12

Open rploeg opened 1 year ago

rploeg commented 1 year ago

Hi,

I have connected a iotracker to the TTN. I see the device within HomeAssistant, but I am missing the location data in HomeAssistant. I can see the GPS location in the decoder message at the TTN console:

here some parts of the JSON message:

"received_at": "2022-10-28T08:28:45.543719773Z",
"uplink_message": {
  "session_key_id": "AYQdrnkq37ZIzcWWLHmvLQ==",
  "f_port": 1,
  "f_cnt": 6,
  "frm_payload": "GAD7iQgIzwAAA5AzAx8NDkMDJVUaAagVYAACArkPCA==",
  "decoded_payload": {
    "batteryLevel": 251,
    "containsGps": true,
    "containsOnboardSensors": true,
    "containsSpecial": false,
    "crc": 0,
    "gps": {
      "altRef": 42.4,
      "cog": 69.7,
      "hAcc": 21,
      "hdop": 1.5,
      "latitude": 52.0949315,
      "longitude": 5.2778266,
      "navStat": 3,
      "numSvs": 8,
      "sog": 0.2,
      "vAcc": 96
    },

Any idea how I can use the location or GPS data also in HA?

angelnu commented 1 year ago

Hi @rploeg ,

it would be useful if you could add a log from home-assitant, with the TTN adaptor loglevel set to debug. My theory is that the the issue is the missing altitude which will break: https://github.com/angelnu/home_assistant_thethingsnetwork/blob/d97db41d93a4925cee3618f0a370d47b1bfe4df8/custom_components/thethingsnetwork/TTN_client.py#L650

The code can be made mode robust to return 0 or unknown if no altitudevalue is available. We could also try some alternative values such as altRef(if this is the right value for your device)