JSON Attributes and values via MQTT to Dashboard

Hi, brand new here and no app developer claims made at all, but I am having a go!

I have a Solar Charge Controller and have managed to get the data being sent to HA via MQTT.

I am receiving the following JSON data into HA and can see the defined Entity I have in the Unused Entities list from the config below. I can add an Entity Card, but the only data in it is the name - “Manufacturer”. The value is showing as “Unknown”.

I cannot for the life of me work out how to get the value data to display in the dashboard.

Please help! I have searched and searched to no avail, and am sure it is something simple I am missing or doing wrong!

Thanks in advance.

HA config:

  - platform: mqtt
    state_topic: "solar/tracer/info"
    name: "Manufacturer"
    value_template: "{{ value_json[1].value }}"

Resulting JSON:
Message 0 received on solar/tracer/info at 4:35 AM:

{
    "0": "Manufacturer",
    "1": "EPsolar Tech co., Ltd Tracer4210A"
}

QoS: 0 - Retain: false

There’s a lot of people on here who are ultimately more qualified than I am, but let me give it a shot:

Have you tried using value_json['1'].value instead of value_json[1].value?

1 Like

What chairstacker said.

The key names are strings so you have to refer to them as strings. If the key names were integers then you could refer to them the way you did.

This screenshot demonstrates the two scenarios (key name as string and as integer):

Thanks so much for the help, but that did not seem to work for some reason.

Plan B is as follows - ie. to simplify, then try and “fix properly later” …

I have changed the MQTT output from the script and HA is receiving the following data now:

Message 322 received on solar/tracer/stat/ambienttemperature at 10:49 PM:
{
    "Ambient temperature": 14.63
}
QoS: 0 - Retain: false

My configuration.yaml file has the following:

  - platform: mqtt
    state_topic: "solar/tracer/stat/ambienttemperature"
    name: "Ambient Temperature"
    value_template: "{{ value_json['Ambient Temperature'].value }}"
    force_update: true

I am still getting values of “Unknown” in the Dashboard and really have no idea what I am doing wrong.

Thanks for the info above, however, I really do not have much idea of what it means, apart from trying the code above from chairstacker (which didn’t seem to make a difference, but thank you!).

I also tried putting the code from 123 Taras into the “templates” file under Developer Tools, but that did not make any difference either as I have no idea how to reference or call it.

I only need to figure this out once and I should be sweet to go!

Thanks again for the help here.

What am I doing wrong!!?? I feel like such a noob gumby! :slight_smile:

You don’t “reference it or call it”. The purpose of the Template Editor is to provide a convenient way of testing templates.

You may have overlooked an important aspect of the templates in my previous post. None of them included the word “.value” like you have in your templates.

In the the first version of your sensor configuration, if the payload is this:

{
    "0": "Manufacturer",
    "1": "EPsolar Tech co., Ltd Tracer4210A"
}

then the template is this:

  - platform: mqtt
    state_topic: "solar/tracer/info"
    name: "Manufacturer"
    value_template: "{{ value_json['1'] }}"

In the second version of your sensor configuration, if the payload is this:

{
    "Ambient temperature": 14.63
}

then the template is this:

  - platform: mqtt
    state_topic: "solar/tracer/stat/ambienttemperature"
    name: "Ambient Temperature"
    value_template: "{{ value_json['Ambient Temperature'] }}"
    force_update: true
2 Likes

123 Taras

You are a LEGEND! Thank you so much …

1 Like

You’re welcome!

If the information I provided helped solve the problem, please mark my post with the Solution tag. This will automatically place a check-mark next to the topic’s title which signals to others that this topic has an accepted solution. It will also automatically place a link below your first post that leads to the Solution post. All of this helps other users who may be seeking answers to similar questions.