Value_template "{{ value_json[0].value}}"

Hi I would very much appreciate any help debugging my yaml from a HA newbie in this forum of experts!

I have a bunch of sensors integrated in HA but it seems all sensors where the value is encased in double quotation marks are not reading and appearing as unknown in dashboards.

The common theme seems to be the json

[{“propertyId”:“lorawan-v1-0-xspas8wl3iiqksd9-frequency-weight-type-gzqithfy4o”,“timestamp”:1730909017000,“value”:“A”}]

where its the values which are encased in “” are appearing as unknown

Can anyone point me in the right direction I have been scratching my head on this for hours with no luck on other posts

my yaml here:

# MILESIGHT-WS302 ##
  - name: "Sound Frequency Type"
    unique_id: "MILESIGHT-WS302-Frequency-Weight"
    state_topic: "HA/MILESIGHT-WS302/Frequency-weight-type"
    value_template: "{{ value_json.value }}"
    qos: 1
    force_update: true
    device:
      identifiers: "MILESIGHT-WS302"
      name: "MILESIGHT-WS302"
      model: "WS302"
      manufacturer: "MILESIGHT"    

  - name: "Max Sound Level"
    unique_id: "MILESIGHT-WS302-Max-Sound-Level"
    state_topic: "HA/MILESIGHT-WS302/Maximum-sound-level"
    value_template: "{{ value_json[0].value | round(1)}}"
    unit_of_measurement: "dB"
    qos: 1
    force_update: true
    device:
      identifiers: "MILESIGHT-WS302"

The posted code is unformatted. Use “predefined” (cog button in editor).

apologies first time posting here is this any better?

1 Like

None of the names you highlighted in the image match the names in your configurations. Which one is which?

Frequency-weight-type is the problematic value which is the middle highlighted unknown value in the screen shot

I’m not trying to be pedantic here, but you’re not using words that are from your previous post.

Are these all the same?

image

Assuming they are, and assuming that Sound Level is Max Sound Level (which is working). And assuming that this is your json data [{"propertyId":"lorawan-v1-0-xspas8wl3iiqksd9-frequency-weight-type-gzqithfy4o","timestamp":1730909017000,"value":"A"}], then your template should be "{{ value_json[0].value }}" not "{{ value_json.value }}"

Apologies yes they are all the same maybe the image doesn’t help as that’s labelled to be more human readable, its the json payload and yaml code which is is the source of the problem i think!

I have tried “{{ value_json[0].value }}” but to no success unfortunately

If that template doesn’t work, then your topic is wrong.

Hi Petro thanks helping, if it is im not sure how ive tested in MQTT explorer and it works when testing in HA dev tools
image

Well, there’s nothing wrong with your setup if you use the template "{{ value_json[0].value }}". That is the correct template and the rest of your yaml is correct. Are you 100% sure you restarted after changing to that template? And are you 100% sure you had the yaml correct when you tried that template?

Yes to both and it has me stumped… i have a lot of MQTT sensors and the common problem across all is when the values in the JSON payload are encased in “ “

To help debug, see what you get from:

value_template: "{{ value[:200] }}"

…which should return some JSON. Also try removing the qos and force_update lines unless you know why they’re there.

But your payload isn’t encased in quotes. So I’m not sure what you mean. The value_json is JSON (not in quotes), and the only quotes are on the keys and the values inside the JSON object, which is normal.

Boom…! It worked when I removed qos and force update. Many Thanks Troon and others in this thread for your support :+1: