angelnu / home_assistant_thethingsnetwork

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

Allow to retrieve and use arrays in variables #22

Open kalon33 opened 9 months ago

kalon33 commented 9 months ago

I just bought a SenseCAP T1000A that I added to TTN, in order to use it through Home Assistant. It has a pretty complex payload (see https://github.com/Seeed-Solution/SenseCAP-Decoder/blob/main/T1000/TTN/SenseCAP_T1000_TTN_Decoder.js for the decoder), that send multiple measurements into the messages variable, and "state" values through their own variables.

Would it be possible to be able to retrieve informations in messages variable and split them into their own variables in HA? Currently I'm not able to retrieve anything in messages in HA, but other values (app_id, dev_id, err, errMessage, num, payload and valid) are properly set.

Here is an extract from what is generated on TTN side:

"decoded_payload": {
        "err": 0,
        "messages": [
          [
            {
              "measurementId": "4200",
              "measurementValue": [],
              "motionId": 0,
              "timestamp": 1703937567000,
              "type": "Event Status"
            },
            {
              "measurementId": "5002",
              "measurementValue": [
                {
                  "mac": "DE:25:4F:59:7E:02",
                  "rssi": "-87"
                },
                {
                  "mac": "12:3B:6A:1B:AB:B2",
                  "rssi": "-91"
                },
                {
                  "mac": "FD:9E:33:84:D2:C7",
                  "rssi": "-92"
                }
              ],
              "motionId": 0,
              "timestamp": 1703937567000,
              "type": "BLE Scan"
            },
            {
              "measurementId": "4097",
              "measurementValue": 17.4,
              "motionId": 0,
              "timestamp": 1703937567000,
              "type": "Air Temperature"
            },
            {
              "measurementId": "4199",
              "measurementValue": 6,
              "motionId": 0,
              "timestamp": 1703937567000,
              "type": "Light"
            },
            {
              "measurementId": "3000",
              "measurementValue": 96,
              "motionId": 0,
              "timestamp": 1703937567000,
              "type": "Battery"
            }
          ]
        ],
        "payload": "08000000006590061fde254f597e02a9123b6a1babb2a5fd9e3384d2c7a400ae000660",
        "valid": true
      }

Thanks for your help!