MQTT data - 'value_json' is undefined - JSON checks

How do I get this data into HA?

After searching I have reviewed the below discussion and I see similarity in the issue but I remain unclear as to how to resolve my issue, particularly the lack of quotes around some of the returns:
Template variable error: ‘value_json’ is undefined - mqtt

The MQTT broker is receiving the following input:

{
    "stnname": "WiFiLogger",
    "stnmod": 16,
    "ver": 3.15,
    "mac": "70:B8:F6:9B:E6:14",
    "apmac": "70:B8:F6:9B:E6:15",
    "ip": "192.168.9.79",
    "ssid": "AsylumIOT",
    "rssi": -49,
    "wifimod": 0,
    "lastboot": 1716237779,
    "uptime": 2567,
    "wflver": "2.42",
    "loctime": 1716225940,
    "utctime": 1716240340,
    "tzone": 10,
    "units": 4,
    "conlati": 424,
    "conlongi": -715,
    "wfllati": -300,
    "wfllongi": -300,
    "tempout": "71.5",
    "humout": "64",
    "tempin": "66.3",
    "humin": "50",
    "windspd": "0.0",
    "winddir": "138",
    "windavg2": "0.0",
    "windavg10": "0.0",
    "gust": "0.0",
    "gustdir": "130",
    "bar": "29.950",
    "bartr": "-20",
    "dew": "59",
    "cdew": "58.7",
    "chill": "72",
    "heat": "72",
    "thsw": "---",
    "uv": "---",
    "solar": "---",
    "rainr": "0.00000",
    "storm": "0.00000",
    "rain15": "0.00000",
    "rain1h": "0.00000",
    "raind": "0.00000",
    "rain24": "0.00000",
    "rainmon": "2.53000",
    "rainyear": "18.10000",
    "etday": "0.000",
    "etmon": "0.00",
    "etyear": "0.00",
    "xt": [
        "---",
        "---",
        "---",
        "---",
        "---",
        "---",
        "---"
    ],
    "xlt": [
        "---",
        "---",
        "---",
        "---"
    ],
    "xst": [
        "---",
        "---",
        "---",
        "---"
    ],
    "xh": [
        "---",
        "---",
        "---",
        "---",
        "---",
        "---",
        "---"
    ],
    "xsm": [
        "---",
        "---",
        "---",
        "---"
    ],
    "xlw": [
        "---",
        "---",
        "---",
        "0"
    ],
    "bat": "4.49",
    "trbat": "0",
    "foreico": "3",
    "forrule": "187",
    "sunrt": "5:20",
    "sunst": "20:07",
    "hlbar": [
        "29.947",
        "30.038",
        "17:17",
        "8:22",
        "30.342",
        "29.468",
        "30.565",
        "28.889"
    ],
    "hlwind": [
        "---",
        "7.0",
        "---",
        "11:48",
        "15.0",
        "---",
        "34.0",
        "---"
    ],
    "hltempin": [
        "62.6",
        "66.3",
        "6:37",
        "17:24",
        "72.7",
        "58.5",
        "72.7",
        "58.5"
    ],
    "hlhumin": [
        "43",
        "52",
        "10:25",
        "13:25",
        "52",
        "27",
        "52",
        "19"
    ],
    "hltempout": [
        "49.0",
        "73.4",
        "1:37",
        "15:15",
        "82.8",
        "37.4",
        "82.8",
        "9.9"
    ],
    "hlhumout": [
        "58",
        "97",
        "15:16",
        "6:08",
        "97",
        "25",
        "98",
        "17"
    ],
    "hldew": [
        "48",
        "59",
        "1:11",
        "12:36",
        "62",
        "33",
        "62",
        "-1"
    ],
    "hlchil": [
        "49",
        "---",
        "1:19",
        "---",
        "---",
        "37",
        "---",
        " 8"
    ],
    "hlheat": [
        "---",
        "74",
        "---",
        "15:03",
        "82",
        "---",
        "82",
        "---"
    ],
    "hlthsw": [
        "---",
        "---",
        "---",
        "---",
        "---",
        "---",
        "---",
        "---"
    ],
    "hlsolar": [
        "---",
        "0",
        "---",
        "---",
        "0",
        "---",
        "0",
        "---"
    ],
    "hluv": [
        "---",
        "0.0",
        "---",
        "---",
        "0.0",
        "---",
        "0.0",
        "---"
    ],
    "hlrainr": [
        "0.000",
        "0.000",
        "---",
        "---",
        "0.930",
        "---",
        "3.890",
        "---"
    ],
    "hlxt0": [
        "---",
        "---",
        "---",
        "---",
        "---",
        "---",
        "---",
        "---"
    ],
    "hlxt1": [
        "---",
        "---",
        "---",
        "---",
        "---",
        "---",
        "---",
        "---"
    ],
    "hlxt2": [
        "---",
        "---",
        "---",
        "---",
        "---",
        "---",
        "---",
        "---"
    ],
    "hlxt3": [
        "---",
        "---",
        "---",
        "---",
        "---",
        "---",
        "---",
        "---"
    ],
    "hlxt4": [
        "---",
        "---",
        "---",
        "---",
        "---",
        "---",
        "---",
        "---"
    ],
    "hlxt5": [
        "---",
        "---",
        "---",
        "---",
        "---",
        "---",
        "---",
        "---"
    ],
    "hlxt6": [
        "---",
        "---",
        "---",
        "---",
        "---",
        "---",
        "---",
        "---"
    ],
    "hlxh0": [
        "---",
        "---",
        "---",
        "---",
        "---",
        "---",
        "---",
        "---"
    ],
    "hlxh1": [
        "---",
        "---",
        "---",
        "---",
        "---",
        "---",
        "---",
        "---"
    ],
    "hlxh2": [
        "---",
        "---",
        "---",
        "---",
        "---",
        "---",
        "---",
        "---"
    ],
    "hlxh3": [
        "---",
        "---",
        "---",
        "---",
        "---",
        "---",
        "---",
        "---"
    ],
    "hlxh4": [
        "---",
        "---",
        "---",
        "---",
        "---",
        "---",
        "---",
        "---"
    ],
    "hlxh5": [
        "---",
        "---",
        "---",
        "---",
        "---",
        "---",
        "---",
        "---"
    ],
    "hlxh6": [
        "---",
        "---",
        "---",
        "---",
        "---",
        "---",
        "---",
        "---"
    ],
    "hlxst0": [
        "---",
        "---",
        "---",
        "---",
        "---",
        "---",
        "---",
        "---"
    ],
    "hlxst1": [
        "---",
        "---",
        "---",
        "---",
        "---",
        "---",
        "---",
        "---"
    ],
    "hlxst2": [
        "---",
        "---",
        "---",
        "---",
        "---",
        "---",
        "---",
        "---"
    ],
    "hlxst3": [
        "---",
        "---",
        "---",
        "---",
        "---",
        "---",
        "---",
        "---"
    ],
    "hlxlt0": [
        "---",
        "---",
        "---",
        "---",
        "---",
        "---",
        "---",
        "---"
    ],
    "hlxlt1": [
        "---",
        "---",
        "---",
        "---",
        "---",
        "---",
        "---",
        "---"
    ],
    "hlxlt2": [
        "---",
        "---",
        "---",
        "---",
        "---",
        "---",
        "---",
        "---"
    ],
    "hlxlt3": [
        "---",
        "---",
        "---",
        "---",
        "---",
        "---",
        "---",
        "---"
    ],
    "hlxsm0": [
        "---",
        "---",
        "0:00",
        "---",
        "---",
        "---",
        "---",
        "---"
    ],
    "hlxsm1": [
        "---",
        "---",
        "0:00",
        "---",
        "---",
        "---",
        "---",
        "---"
    ],
    "hlxsm2": [
        "---",
        "---",
        "0:00",
        "---",
        "---",
        "---",
        "---",
        "---"
    ],
    "hlxsm3": [
        "---",
        "---",
        "0:00",
        "---",
        "---",
        "---",
        "---",
        "---"
    ],
    "hlxlw0": [
        "---",
        "---",
        "0:00",
        "---",
        "---",
        "---",
        "---",
        "---"
    ],
    "hlxlw1": [
        "---",
        "---",
        "0:00",
        "---",
        "---",
        "---",
        "---",
        "---"
    ],
    "hlxlw2": [
        "---",
        "---",
        "0:00",
        "---",
        "---",
        "---",
        "---",
        "---"
    ],
    "hlxlw3": [
        "---",
        "---",
        "0:00",
        "---",
        "---",
        "---",
        "---",
        "---"
    ]
}
QoS: 2 - Retain: false

The above passes JSON Checker - The JSON Validator and Formatter

Yet the below template still produces the ‘value_json’ is undefined error.

The “lack of quotes” isn’t the issue. That is how numbers are correctly represented in json data.

You cant use the template editor to test your config like that. The template editor has no method of connecting to your mqtt broker and returning a result like the mqtt integration does. All it does is evaluate templates, so value_json does not exist in the template editor unless you manually define it. e.g.

{% value_json = <your_json_data_here> %}

Looking at your data your mqtt sensor config appears correct. Just try it. Though I would add the following options:

      device_class: temperature  # -> nice icon and ability to change units from the UI
      state_class: measurement # -> long term statistics for history older than 10 days

Thanks for the recommendation, but still returning “unknown”.

mqtt:
  sensor:
  - name: "Davis Vantage Pro - Air Temp - Outside "
    state_topic: "/davis/wflexpj.json"
    unit_of_measurement: "°F"
    device_class: temperature  # -> nice icon and ability to change units from the UI
    state_class: measurement # -> long term statistics for history older than 10 days
    value_template: "{{ value_json.tempout }}"

Any thoughts on where to go from here?

This is not correct:

Delete the leading / from your topic:

state_topic: "davis/wflexpj.json"

I highly recommend you download MQTT Explorer (free). It lets you look at topics and values in your broker easily.

I doubt your topic is named davis/wflexpj.json. The .json is not normal.

I initially mentioned that too but deleted it when I saw this:

I think that really is the topic.

2 Likes

weird

Thank you. Deleting the ‘/’ and it is all accessible.

Re: MQTT Explorer - Got it - using it

1 Like

currently i think i am having a similar issues "

e[31m2025-11-09 00:25:53.337 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'value_json' is undefined when rendering '{{ value_json.current }}'e[0m
e[31m2025-11-09 00:25:53.338 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'value_json' is undefined when rendering '{{ value_json.state }}'e[0m
e[31m2025-11-09 00:25:53.338 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'value_json' is undefined (value: , template: {{ value_json.state }})e[0m
e[31m2025-11-09 00:25:53.339 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'value_json' is undefined when rendering '{{ value_json.energy }}'e[0m
e[33m2025-11-09 00:25:53.339 WARNING (MainThread) [homeassistant.components.mqtt.update] Unable to process payload '' for topic zigbee2mqtt/Plug (router), with value template 'Template<template=({"latest_version":"{{ value_json['update']['latest_version'] }}","installed_version":"{{ value_json['update']['installed_version'] }}","update_percentage":{{ value_json['update'].get('progress', 'null') }},"in_progress":{{ (value_json['update']['state'] == 'updating')|lower }}}) renders=2>'e[0m
e[31m2025-11-09 00:25:53.340 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'value_json' is undefined when rendering '{{ value_json.power_on_behavior }}'e[0m
e[31m2025-11-09 00:25:53.340 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'value_json' is undefined (value: , template: {{ value_json.power_on_behavior }})e[0m
e[31m2025-11-09 00:25:53.340 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'value_json' is undefined when rendering '{{ value_json.voltage }}'e[0m
e[31m2025-11-09 00:25:53.340 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'value_json' is undefined when rendering '{{ value_json.power }}'e[0m

any idea what i would need to do ?

You already have a topic about this. Please don’t cross post to year old topics.