Hi Everyone,
I am struggling to extract a value from a JSON Object and was wondering if someone could help me out.
This is the JSON:
{
"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"
}
}
}
and this is my config
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"
unique_id: klax_keller
device:
identifiers: "klaxhome"
manufacturer: "AO-T"
name: "Stromzähler"
This approach has already worked a couple of times but this is the first time I am using “” to choose object within a JSON. And somehow this doesn’t work. I don’t see a value beeing registered in the MQTT Entity.
Really appreciate any help I can get.
1 post - 1 participant