Select values from JSON

Good evening,
I’m trying to get some values from a Json file:

Nachricht 1 empfangen auf SHRDZM/308398802817/308398802817/sensor um 22:43:
{
    "timestamp": "2022-02-03T22:43:05",
    "32.7.0": "244",
    "52.7.0": "244",
    "72.7.0": "244",
    "31.7.0": "95",
    "51.7.0": "90",
    "71.7.0": "187",
    "1.7.0": "546",
    "2.7.0": "0",
    "1.8.0": "30297176",
    "2.8.0": "9207787",
    "uptime": "0000:07:29:09"
}
QoS: 0 - Retain: false

I tried two ways:

# MQTT - Smart Meter

  - platform: mqtt
    name: "aktueller Verbrauch"
    state_topic: "SHRDZM/308398802817/308398802817/sensor"
    unit_of_measurement: "W"
    value_template: "{{ value_json[1.7.0] }}"
    
  - platform: mqtt
    name: "Zählerstand"
    state_topic: "SHRDZM/308398802817/308398802817/sensor"
    unit_of_measurement: "W"
    value_template: "{{ value_json[1.8.0] }}"
    
  - platform: mqtt
    name: "aktuelle Einspeisung"
    state_topic: "SHRDZM/308398802817/308398802817/sensor"
    unit_of_measurement: "W"
    value_template: "{{ value_json.2.7.0 }}"

the output I get is nothing or everything :slight_smile:

Bildschirmfoto 2022-02-03 um 22.35.45

Maybe someone can help me what I am doing wrong.

Thank you in advance!

Wrap the key’s name in quotes.

  - platform: mqtt
    name: "aktueller Verbrauch"
    state_topic: "SHRDZM/308398802817/308398802817/sensor"
    unit_of_measurement: "W"
    value_template: "{{ value_json['1.7.0'] }}"

Demonstrated in the Template Editor:

Sometimes the solution is so simple - thank you!

1 Like