Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 117759

Attaching Timestamp to delayed value array

$
0
0

Hi Everyone,

I got great help earlier today and now I need a little bit more of everyone expertise.

My sensor is measuring every 15 Minutes but only does an uplink every hour. The payload looks like this, please take note of the four value keys:

{
  "end_device_ids": {
    "device_id": "eui-bc97",
    "application_ids": {
      "application_id": "klax-1"
    },
    "dev_eui": "BC9740",
    "join_eui": "70B3D5",
    "dev_addr": "260B7"
  },
  "correlation_ids": [
    "gs:uplink:01HPRZG71HTSG"
  ],
  "received_at": "2024-02-16T12:50:44.094863791Z",
  "uplink_message": {
    "session_key_id": "AY1o2VXaOfg8o",
    "f_port": 3,
    "f_cnt": 344,
    "frm_payload": "BEVVEQMJAUVTWREDm8SFAREPS38Qq0t/EE1Lfw/gS38PdA==",
    "decoded_payload": {
      "header": {
        "batteryPerc": 100,
        "configured": true,
        "connTest": false,
        "deviceType": "SML Klax",
        "meterType": "SML",
        "version": 1
      },
      "msgInfo": {
        "msgCnt": 1,
        "msgIdx": 85,
        "msgNum": 1
      },
      "payloads": [
        {
          "id": "090145535911039bc485",
          "type": "serverID"
        },
        {
          "register": {
            "filterActive": true,
            "filterId": 0,
            "unit": "Wh",
            "values": [
              {
                "valid": true,
                "value": 16715947
              },
              {
                "valid": true,
                "value": 16715853
              },
              {
                "valid": true,
                "value": 16715744
              },
              {
                "valid": true,
                "value": 16715636
              }
            ]
          },
          "type": "filter"
        }
      ],
      "type": "app"
    },
    "rx_metadata": [
      {
        "gateway_ids": {
          "gateway_id": "eui-58a0",
          "eui": "58A0CB"
        },
        "time": "2024-02-16T12:50:43.775126934Z",
        "timestamp": 4243676867,
        "rssi": -91,
        "channel_rssi": -91,
        "snr": 9.5,
        "location": {
          "latitude": 50.950,
          "longitude": 11.0,
          "source": "SOURCE_REGISTRY"
        },
        "uplink_token": "CiIKIAoUZXVpLTU4YTBjYmZmZmU4MDU0NTISCFigy//+gFRSEMO9xecPGgwIo7S9r",
        "received_at": "2024-02-16T12:50:43.863979522Z"
      }
    ],
    "settings": {
      "data_rate": {
        "lora": {
          "bandwidth": 125000,
          "spreading_factor": 7,
          "coding_rate": "4/5"
        }
      },
      "frequency": "868300000",
      "timestamp": 4243676867,
      "time": "2024-02-16T12:50:43.775126934Z"
    },
    "received_at": "2024-02-16T12:50:43.890499663Z",
    "consumed_airtime": "0.092416s",
    "version_ids": {
      "brand_id": "alpha-omega-technology",
      "model_id": "klax",
      "hardware_version": "2.0",
      "firmware_version": "2.0",
      "band_id": "EU_863_870"
    },
    "network_ids": {
      "net_id": "000013",
      "ns_id": "EC656E0000000181",
      "tenant_id": "ttn",
      "cluster_id": "eu1",
      "cluster_address": "eu1.cloud.thethings.network"
    }
  }
}

I can’t even imagine a way on how to deal with this. Basically I need to extract each value item and then associate it with a Timestamp that has an offset of x minutes to the arrival of the uplink. Finally I would have to save the data to HA.

For now I have resorted to just saving the first array Value:

mqtt:
  sensor:
    - name: "Stromverbrauch"
      state_topic: "ttn/v3/klax-1@ttn/devices/eui-bc9740d2c7/up"
      value_template: "{{ value_json['uplink_message']['decoded_payload']['payloads'][1]['register']['values'][0]['value'] }}"
      unit_of_measurement: "Wh"
      device_class: "energy"
      state_class: "total_increasing"
      unique_id: klax_keller
      device:
        identifiers: "klaxhome"
        manufacturer: "AO-T"
        name: "Stromzähler"

As you can see I have a grasp on the concept but I have no idea how to make this happen. Any advice is appreciated.

2 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 117759

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>