Selecting State from MQTT topic and Attributes from json, not working

value_json[0].id

Hmm, yes you would think so but have tried that already but good point it does look like they have put the json payload within an array when it comes into HA.


Here is my automation now, do you see any issues with it? When I watch the automation in the UI I can see the first part triggers but then the second condition part does not…

- id: '1706212772320'
  alias: 2cf7f1c0530003d4_SOS Count
  description: ''
  trigger:
  - platform: state
    entity_id:
    - sensor.2cf7f1c0530003d4_sos_event
  condition:
  - condition: template
    value_template: '{{ value_json[0].id == 8 }}'
  action:
  - service: mqtt.publish
    metadata: {}
    data:
      qos: 0
      topic: TrackerCount
      payload: one
  - service: counter.increment
    metadata: {}
    data: {}
    target:
      entity_id: counter.soscounterone
  mode: single

You have to level up your copy/paste skills :joy:

image

value_json[0].id

You don’t quite get it, yet

  condition:
  - condition: template
    value_template: '{{ (trigger.to_state.state | from_json)[0].id == 8 }}'

but for that to work, the state must be valid JSON. JSON mandates to use double-quotes rather than single ones.

So your payload should be similar to

[{"id": 8.0, "eventname": "blah" }]

I feel really stupid now, have been sat here looking at what I have missed or copy/pasted wrong… and I still cant see it. This is what happens when a mechanical and hardware engineer gets interested in coding…

Problem is, this is what the trackers send via the LoRaWAN gateway through the official Seeed integration and I cant change the format of this.
or am I missing the blindingly obvious?

Well, if that is what you show in the first post, that is correct.
It is the content of sensor.2cf7f1c0530003d4_sos_event which isn’t for whatever reason.

Sorry I dont understand what you mean here by ‘that is correct’, do you mean

this is correct?

So, last night my comment of I cant change the payload got me thinking, maybe I could. In the LoRaWAN gateway, they have codecs for each device which I assume controls the way the data is processed by the gateway. So I looked in the codec for the tracker I am trying to get going and found part of it has this code.

function getEventStatus (str) {
    // return getInt(str)
    let bitStr = getByteArray(str)
    let bitArr = []
    for (let i = 0; i < bitStr.length; i++) {
        bitArr[i] = bitStr.substring(i, i + 1)
    }
    bitArr = bitArr.reverse()
    let event = []
    for (let i = 0; i < bitArr.length; i++) {
        if (bitArr[i] !== '1') {
            continue
        }
        switch (i){
            case 0:
                event.push({id:1, eventName:"Start moving event."})
                break
            case 1:
                event.push({id:2, eventName:"End movement event."})
                break
            case 2:
                event.push({id:3, eventName:"Motionless event."})
                break
            case 3:
                event.push({id:4, eventName:"Shock event."})
                break
            case 4:
                event.push({id:5, eventName:"Temperature event."})
                break
            case 5:
                event.push({id:6, eventName:"Light event."})
                break
            case 6:
                event.push({id:7, eventName:"SOS event."})
                break
            case 7:
                event.push({id:8, eventName:"Press TESTonce event."})
                break
        }
    }
    return event
}

You will see I just inserted ‘TEST’ in what I assume is the payload for the message. When I pressed the button my new message came through. So it appears I can change the message… Most of this code is way above my pay scale but I assume it selects whichever switch case it needs depending on a variable passed to it. This is only one section of the whole codec which is quite large.
Do you think I need to change the payload to something else that conforms to the correct formating?

I mean the JSON in your very first post is proper JSON.

image

That is not proper JSON (wrong kind of quote).

There is still confusion between what lorawan send and that sensor, they seem to have no relation? I’m lost…
What is that sensor.2cf7f1c0530003d4_sos_event? What fills it?

I am glad its not just me that’s lost. ;-]
I think i have confused things by mixing using the seed integration with using mqtt messages and payloads (which it looks like how their integration gets its info).
I think tomorrow morning i will go back to just using mqtt because i cant work out how to use the event state through their integration.
Its a shame as there are 7 different events that can be triggered from the trackers.
I am thinking its not Json in the state, maybe its a string? But haven’t got a clue how to extract that either!

Right, I might be getting somewhere but getting unexpected results. So I went back to just using the MQTT messages which enable me to use the raw JSON.
This is the format of the raw JSON when I get a push once ID8 message

{
 "deduplicationId": "4f7a3af5-c630-4f73-8761-7b8235fdd8b3",
  "time": "2024-01-25T23:58:00.145856736+00:00",
  "deviceInfo": {
    "tenantId": "52f14cd4-c6f1-4fbd-8f87-4025e1d49242",
    "tenantName": "SenseCAP",
    "applicationId": "4dbc51c8-b854-4964-b499-678bf98b0086",
    "applicationName": "Home Assistant",
    "deviceProfileId": "d1dcbe7b-d2dd-4d41-bcc5-c5515a263dd5",
    "deviceProfileName": "MNL1 Tracker",
    "deviceName": "MNL1 Tracker",
    "devEui": "2cf7f1c053000409",
    "tags": {}
  },
  "devAddr": "5b49faab",
  "adr": true,
  "dr": 3,
  "fCnt": 1674,
  "fPort": 5,
  "confirmed": true,
  "data": "BgAAgABlsvWFCnu0AP2YnkgBDgBkXg==",
  "object": {
    "err": 0,
    "payload": "060000800065b2f5850a7bb400fd989e48010e00645e",
    "valid": true,
    "messages": [
      [
        {
          "measurementValue": [
            {
              "eventName": "Press once event.",
              "id": 8
            }
          ],
          "motionId": 0,
          "type": "Event Status",
          "measurementId": "4200",
          "timestamp": 1706227077000
        },
        {
          "measurementId": "4197",
          "type": "Longitude",
          "motionId": 0,
          "timestamp": 1706227077000,
          "measurementValue": 175.879168
        },
        {
          "measurementId": "4198",
          "timestamp": 1706227077000,
          "motionId": 0,
          "type": "Latitude",
          "measurementValue": -40.329656
        },
        {
          "timestamp": 1706227077000,
          "measurementId": "4097",
          "measurementValue": 27,
          "type": "Air Temperature",
          "motionId": 0
        },
        {
          "measurementId": "4199",
          "timestamp": 1706227077000,
          "motionId": 0,
          "type": "Light",
          "measurementValue": 100
        },
        {
          "timestamp": 1706227077000,
          "measurementValue": 94,
          "type": "Battery",
          "measurementId": "3000",
          "motionId": 0
        }
      ]
    ]
  },
  "rxInfo": [
    {
      "gatewayId": "2cf7f11153100032",
      "uplinkId": 902262466,
      "rssi": -29,
      "snr": 10.8,
      "channel": 2,
      "location": {
        "latitude": -40.32967305958506,
        "longitude": 175.87926864624023
      },
      "context": "z1vMIA==",
      "metadata": {
        "region_config_id": "US_902_928_FSB_2",
        "region_common_name": "US915"
      },
      "crcStatus": "CRC_OK"
    }
  ],
  "txInfo": {
    "frequency": 904300000,
    "modulation": {
      "lora": {
        "bandwidth": 125000,
        "spreadingFactor": 7,
        "codeRate": "CR_4_5"
      }
    }
  }
}

My sensor looks like this

- name: "Tracker 1 Message"
    state_topic: "application/4dbc51c8-b854-4964-b499-678bf98b0086/device/2cf7f1c053000409/event/up"
    
    value_template: '{{ value_json.object.messages[0][0].measurementValue[0].id }}' ##This sets the state message?
    
    json_attributes_topic: "application/4dbc51c8-b854-4964-b499-678bf98b0086/device/2cf7f1c053000409/event/up"
    json_attributes_template: '{{ value_json.messages[0][0] | tojson }}'            ##THIS CHANGEs WHATS SET AS AN ATTRIBUTE?

and this is what it gives me in the states page


I was thinking that I would only get attributes under messages not the whole lot? What am I missing?

Getting closer… changed the sensor to this

  - name: "Tracker 1 Message"
    state_topic: "application/4dbc51c8-b854-4964-b499-678bf98b0086/device/2cf7f1c053000409/event/up"
    
    value_template: '{{ value_json.object.messages[0][0] }}' ##This sets the state message?
    
    json_attributes_topic: "application/4dbc51c8-b854-4964-b499-678bf98b0086/device/2cf7f1c053000409/event/up"
    json_attributes_template: '{{ value_json.object.messages[0][0] | tojson }}'            ##THIS CHANGEs WHATS SENT AS AN ATTRIBUTE?

and now it only gives me (which is much better)


But I am now stuck on trying to break out the - eventName part so I can use it in an automation to increment a counter…

@koying So just a follow up on this. Thank you for all your help, it got me a long way to understanding so much more than what I needed.

Surprisingly, Seeed Studio support actually came to the party and gave me an updated/changed decoder.json to go in the tracker codecs on the chirpstack server.
Now I only get single number ID’s ech time a botton is pressed and I have put this through an automation with a counter.

Happy Days

Can you share your working mqtt sensor and decoder for the soil moisture sensor? I am curently connected throught TTN but I can’t get the sensors (S2101 and S2103) working. HA does see the state_topic but I keep getting “value_json” undefined.

Hi, Sorry for the late response, not been around for a while. Sure,
Decoder

/**
 * SenseCAP & TTN (new v3) Converter
 *
 * @since 3.0
 * @return Object
 *      @param  Boolean     valid       Indicates whether the payload is a valid payload.
 *      @param  String      err         The reason for the payload to be invalid. 0 means valid, minus means invalid.
 *      @param  String      payload     Hexadecimal string, to show the payload.
 *      @param  Array       messages    One or more messages are parsed according to payload.
 *                              type // Enum:
 *                                   //   - "report_telemetry"
 *                                   //   - "upload_battery"
 *                                   //   - "upload_interval"
 *                                   //   - "upload_version"
 *                                   //   - "upload_sensor_id"
 *                                   //   - "report_remove_sensor"
 *                                   //   - "unknown_message"
 *
 *
 *
 *
 *  @sample-1
 *      var sample = Decoder(["00", "00", "00", "01", "01", "00", "01", "00", "07", "00", "64", "00", "3C", "00", "01", "20", "01", "00", "00", "00", "00", "28", "90"], null);
 *      {
 *        valid: true,
 *        err: 0,
 *        payload: '0000000101000100070064003C00012001000000002890',
 *        messages: [
 *           { type: 'upload_version',
 *             hardwareVersion: '1.0',
 *             softwareVersion: '1.1' },
 *           { type: 'upload_battery', battery: 100 },
 *           { type: 'upload_interval', interval: 3600 },
 *           { type: 'report_remove_sensor', channel: 1 }
 *        ]
 *      }
 * @sample-2
 *      var sample = Decoder(["01", "01", "10", "98", "53", "00", "00", "01", "02", "10", "A8", "7A", "00", "00", "AF", "51"], null);
 *      {
 *        valid: true,
 *        err: 0,
 *        payload: '01011098530000010210A87A0000AF51',
 *        messages: [
 *           { type: 'report_telemetry',
 *             measurementId: 4097,
 *             measurementValue: 21.4 },
 *           { type: 'report_telemetry',
 *             measurementId: 4098,
 *             measurementValue: 31.4 }
 *        ]
 *      }
 * @sample-3
 *      var sample = Decoder(["01", "01", "00", "01", "01", "00", "01", "01", "02", "00", "6A", "01", "00", "15", "01", "03", "00", "30", "F1", "F7", "2C", "01", "04", "00", "09", "0C", "13", "14", "01", "05", "00", "7F", "4D", "00", "00", "01", "06", "00", "00", "00", "00", "00", "4C", "BE"], null);
 *      {
 *        valid: true,
 *        err: 0,
 *        payload: '010100010100010102006A01001501030030F1F72C010400090C13140105007F4D0000010600000000004CBE',
 *        messages: [
 *            { type: 'upload_sensor_id', sensorId: '30F1F72C6A010015', channel: 1 }
 *        ]
 *      }
 */

/**
 * Entry, decoder.js
 */
function decodeUplink (input) {
    var bytes = input['bytes'];
    // // init
    var bytesString = bytes2HexString(bytes)
        .toLocaleUpperCase();
    // var bytesString = input
    var decoded = {
      // valid
      valid: true, err: 0, // bytes
      payload: bytesString, // messages array
      messages: []
    }
  
    // CRC check
    if (!crc16Check(bytesString)) {
      decoded['valid'] = false
      decoded['err'] = -1 // "crc check fail."
      return { data: decoded }
    }
  
    // Length Check
    if ((((bytesString.length / 2) - 2) % 7) !== 0) {
      decoded['valid'] = false
      decoded['err'] = -2 // "length check fail."
      return { data: decoded }
    }
  
    // Cache sensor id
    var sensorEuiLowBytes
    var sensorEuiHighBytes
  
    // Handle each frame
    var frameArray = divideBy7Bytes(bytesString)
    for (var forFrame = 0; forFrame < frameArray.length; forFrame++) {
      var frame = frameArray[forFrame]
      // Extract key parameters
      var channel = strTo10SysNub(frame.substring(0, 2))
      var dataID = strTo10SysNub(frame.substring(2, 6))
      var dataValue = frame.substring(6, 14)
      var realDataValue = isSpecialDataId(dataID) ? ttnDataSpecialFormat(dataID, dataValue) : ttnDataFormat(dataValue)
  
      if (checkDataIdIsMeasureUpload(dataID)) {
        // if telemetry.
        decoded.messages.push({
          type: 'report_telemetry', measurementId: dataID, measurementValue: realDataValue
        })
      } else if (isSpecialDataId(dataID) || (dataID === 5) || (dataID === 6)) {
        // if special order, except "report_sensor_id".
        switch (dataID) {
          case 0x00:
            // node version
            var versionData = sensorAttrForVersion(realDataValue)
            decoded.messages.push({
              type: 'upload_version', hardwareVersion: versionData.ver_hardware, softwareVersion: versionData.ver_software
            })
            break
          case 1:
            // sensor version
            break
          case 2:
            // sensor eui, low bytes
            sensorEuiLowBytes = realDataValue
            break
          case 3:
            // sensor eui, high bytes
            sensorEuiHighBytes = realDataValue
            break
          case 7:
            // battery power && interval
            decoded.messages.push({
              type: 'upload_battery', battery: realDataValue.power
            }, {
              type: 'upload_interval', interval: parseInt(realDataValue.interval) * 60
            })
            break
          case 9:
            decoded.messages.push({
              type: 'model_info',
              detectionType: realDataValue.detectionType,
              modelId: realDataValue.modelId,
              modelVer: realDataValue.modelVer
            })
            break
          case 0x120:
            // remove sensor
            decoded.messages.push({
              type: 'report_remove_sensor', channel: 1
            })
            break
          default:
            break
        }
      } else {
        decoded.messages.push({
          type: 'unknown_message', dataID: dataID, dataValue: dataValue
        })
      }
  
    }
  
    // if the complete id received, as "upload_sensor_id"
    if (sensorEuiHighBytes && sensorEuiLowBytes) {
      decoded.messages.unshift({
        type: 'upload_sensor_id', channel: 1, sensorId: (sensorEuiHighBytes + sensorEuiLowBytes).toUpperCase()
      })
    }
    // return
    return { data: decoded }
  }
  
  function crc16Check (data) {
    return true
  }
  
  // util
  function bytes2HexString (arrBytes) {
    var str = ''
    for (var i = 0; i < arrBytes.length; i++) {
      var tmp
      var num = arrBytes[i]
      if (num < 0) {
        tmp = (255 + num + 1).toString(16)
      } else {
        tmp = num.toString(16)
      }
      if (tmp.length === 1) {
        tmp = '0' + tmp
      }
      str += tmp
    }
    return str
  }
  
  // util
  function divideBy7Bytes (str) {
    var frameArray = []
    for (var i = 0; i < str.length - 4; i += 14) {
      var data = str.substring(i, i + 14)
      frameArray.push(data)
    }
    return frameArray
  }
  
  // util
  function littleEndianTransform (data) {
    var dataArray = []
    for (var i = 0; i < data.length; i += 2) {
      dataArray.push(data.substring(i, i + 2))
    }
    dataArray.reverse()
    return dataArray
  }
  
  // util
  function strTo10SysNub (str) {
    var arr = littleEndianTransform(str)
    return parseInt(arr.toString()
      .replace(/,/g, ''), 16)
  }
  
  // util
  function checkDataIdIsMeasureUpload (dataId) {
    return parseInt(dataId) > 4096
  }
  
  // configurable.
  function isSpecialDataId (dataID) {
    switch (dataID) {
      case 0:
      case 1:
      case 2:
      case 3:
      case 4:
      case 7:
      case 9:
      case 0x120:
        return true
      default:
        return false
    }
  }
  
  // configurable
  function ttnDataSpecialFormat (dataId, str) {
    var strReverse = littleEndianTransform(str)
    if (dataId === 2 || dataId === 3) {
      return strReverse.join('')
    }
  
    // handle unsigned number
    var str2 = toBinary(strReverse)
    var dataArray = []
    switch (dataId) {
      case 0: // DATA_BOARD_VERSION
      case 1: // DATA_SENSOR_VERSION
        // Using point segmentation
        for (var k = 0; k < str2.length; k += 16) {
          var tmp146 = str2.substring(k, k + 16)
          tmp146 = (parseInt(tmp146.substring(0, 8), 2) || 0) + '.' + (parseInt(tmp146.substring(8, 16), 2) || 0)
          dataArray.push(tmp146)
        }
        return dataArray.join(',')
      case 4:
        for (var i = 0; i < str2.length; i += 8) {
          var item = parseInt(str2.substring(i, i + 8), 2)
          if (item < 10) {
            item = '0' + item.toString()
          } else {
            item = item.toString()
          }
          dataArray.push(item)
        }
        return dataArray.join('')
      case 7:
        // battery && interval
        return {
          interval: parseInt(str2.substr(0, 16), 2), power: parseInt(str2.substr(-16, 16), 2)
        }
      case 9:
        let dataValue = {
          detectionType: parseInt(str2.substring(0, 8), 2),
          modelId: parseInt(str2.substring(8, 16), 2),
          modelVer: parseInt(str2.substring(16, 24), 2)
        }
        // 01010000
        return dataValue
    }
  }
  
  // util
  function ttnDataFormat (str) {
    var strReverse = littleEndianTransform(str)
    var str2 = toBinary(strReverse)
    if (str2.substring(0, 1) === '1') {
      var arr = str2.split('')
      var reverseArr = []
      for (var forArr = 0; forArr < arr.length; forArr++) {
        var item = arr[forArr]
        if (parseInt(item) === 1) {
          reverseArr.push(0)
        } else {
          reverseArr.push(1)
        }
      }
      str2 = parseInt(reverseArr.join(''), 2) + 1
      return parseFloat('-' + str2 / 1000)
    }
    return parseInt(str2, 2) / 1000
  }
  
  // util
  function sensorAttrForVersion (dataValue) {
    var dataValueSplitArray = dataValue.split(',')
    return {
      ver_hardware: dataValueSplitArray[0], ver_software: dataValueSplitArray[1]
    }
  }
  
  // util
  function toBinary (arr) {
    var binaryData = []
    for (var forArr = 0; forArr < arr.length; forArr++) {
      var item = arr[forArr]
      var data = parseInt(item, 16)
        .toString(2)
      var dataLength = data.length
      if (data.length !== 8) {
        for (var i = 0; i < 8 - dataLength; i++) {
          data = '0' + data
        }
      }
      binaryData.push(data)
    }
    return binaryData.toString()
      .replace(/,/g, '')
  }
  
  // Samples
  // var sample = Decoder(["00", "00", "00", "01", "01", "00", "01", "00", "07", "00", "64", "00", "3C", "00", "01", "20", "01", "00", "00", "00", "00", "28", "90"], null);
  // var sample = Decoder(["01", "01", "10", "98", "53", "00", "00", "01", "02", "10", "A8", "7A", "00", "00", "AF", "51"], null);
  // var sample = Decoder(["01", "01", "00", "01", "01", "00", "01", "01", "02", "00", "6A", "01", "00", "15", "01", "03", "00", "30", "F1", "F7", "2C", "01", "04", "00", "09", "0C", "13", "14", "01", "05", "00", "7F", "4D", "00", "00", "01", "06", "00", "00", "00", "00", "00", "4C", "BE"], null);
  // console.log(sample);

and the config

sensor:
  - name: "S2104_Battery"
    state_topic: "application/1/device/2cf7f1c053000714/event/up"
    
    #value_template: "{{value_json.objectJSON.messages.battery }}"
    
    json_attributes_topic: "application/1/device/2cf7f1c053000714/event/up"
    json_attributes_template: "{{ (value_json.objectJSON | from_json).messages[0].battery }}"
  
  - name: "S2104_Soil_Temp_4102"
    state_topic: "application/1/device/2cf7f1c053000714/event/up"
    json_attributes_topic: "application/1/device/2cf7f1c053000714/event/up"
    json_attributes_template: "{{ ((value_json.objectJSON | from_json).messages | selectattr('measurementId','eq',4102) | list | first).measurementValue }}"
    
  - name: "S2104_Soil_Moisture_4103"
    state_topic: "application/1/device/2cf7f1c053000714/event/up"
    json_attributes_topic: "application/1/device/2cf7f1c053000714/event/up"
    json_attributes_template: "{{ ((value_json.objectJSON | from_json).messages | selectattr('measurementId','eq',4103) | list | first).measurementValue }}"

This is what it gives me
image

Hope that helps

Thank you!

Your welcome,
I am currently battling with trying to get Seeed Studio external Lorawan gateways working…totally different to the M2 dev unit…

Oops, it’s suposed to be easy. I already decided I will not buy more seeed studio lorawan devices. Thanks for confirming that’s the correct decision.

Yeah, its a shame as its good quality gear.

Update:
So it turns out after emails with Seeed Support that their M2 development gateway has version 4 of chirpstack and is compatible with the HA integration BUT thier industrial outdoor gateway has version 3… great. So I am back to trying to use MQTT to get the tracker data into HA, which I have partially done but am now stuck and confused as to where I am going wrong.
So I have activated the tracker in the chirpstack gateway and I can see the tracker device data coming into Chirpstack.

So I wrote a test template and put this data into the template editor like this:

{% set value_json = {
  "applicationID": "1",
  "applicationName": "HomeAssistant",
  "deviceName": "Tracker T1000-A MNL2",
  "devEUI": "LPfxwFMAA9Q=",
  "rxInfo": [
    {
      "gatewayID": "LPfxEURAABE=",
      "time": "2024-05-14T03:50:33.970560220Z",
      "timeSinceGPSEpoch": null,
      "rssi": -87,
      "loRaSNR": 12,
      "channel": 3,
      "rfChain": 0,
      "board": 0,
      "antenna": 0,
      "location": {
        "latitude": -40.33129247197204,
        "longitude": 175.88169336318973,
        "altitude": 50,
        "source": "UNKNOWN",
        "accuracy": 0
      },
      "fineTimestampType": "NONE",
      "context": "7N3QVw==",
      "uplinkID": "PVcjfmV7QMOC+HbEHViaOA==",
      "crcStatus": "CRC_OK"
    }
  ],
  "txInfo": {
    "frequency": 904500000,
    "modulation": "LORA",
    "loRaModulationInfo": {
      "bandwidth": 125,
      "spreadingFactor": 7,
      "codeRate": "4/5",
      "polarizationInversion": false
    }
  },
  "adr": false,
  "dr": 3,
  "fCnt": 152,
  "fPort": 5,
  "data": "EQEAAEBmQt9wgACAAGQ=",
  "objectJSON": "{\"data\":{\"err\":0,\"messages\":[[{\"measurementId\":\"3576\",\"measurementValue\":{\"id\":1,\"statusName\":\"The GNSS scan timed out and failed to obtain the location.\"},\"timestamp\":1715658608000,\"type\":\"Positioning Status\"},{\"measurementId\":\"4200\",\"measurementValue\":[{\"eventName\":\"SOS event.\",\"id\":7}],\"timestamp\":1715658608000,\"type\":\"Event Status\"},{\"measurementId\":\"3000\",\"measurementValue\":100,\"timestamp\":1715658608000,\"type\":\"Battery\"}]],\"payload\":\"11010000406642DF708000800064\",\"valid\":true}}",
  "tags": {},
  "confirmedUplink": true,
  "devAddr": "AY6AXA=="
}
%}

{{ (value_json.objectJSON | from_json).data.messages[0][1].measurementValue[0].id }}

Which in this case gives me a result of 7, which is the ID number when an SOS event has been triggered (you get an 8 with a single button press on the tracker).
So far so good, this works…
Next I put this into an MQTT tempate sensor like this:

  - name: "TEST Tracker 2 Message"
    state_topic: "application/1/device/2cf7f1c0530003d4/event/up"
    
    value_template: '{{ value_json.objectJSON.data.messages[0][1].measurementValue[0].id }}' 
    
    json_attributes_topic: "application/1/device/2cf7f1c0530003d4/event/up"
    json_attributes_template: '{{ value_json.objectJSON | from_json.data.messages[0][0] | tojson }}' 

and this is what I get in the states tab:

and the 7 or 8 state does not show up and stays unknown… I am assuming the state topic in the sensor is correct as all this data is showing up but why does the attribute I selected not update?
@koying any idea what I am still not seeing or understanding?

I changed the title of this thread in the hope some expert at MQTT and JSON may be able to help me out somehow (and bump the thread, sorry if thats wrong) and explain what I am doing wrong?