Learning hass.io the hard way!

I decided to do everything manual…no discovery…etc
My postings will be short and sweat.
Here is #1
-Dmini01(Wemos) Tasmota DHT11 GPIO 14 The web page displays T & H …no problem here

  • Rpi with stand alone MQTT. Tested and working
  • HA Latest HassOS 2.12
  • Tasmota publish reading (in JSON, see below) I subscribed +/Dmini01/+

Here is what MQTT spell out

11:39:54 MQT: tele/D1mini01/SENSOR = {“Time”:“2019-06-04T11:39:54”,“DHT11”:{“Temperature”:28.0,“Humidity”:29.0},“TempUnit”:“C”}

MY QUESTION:

If I go to in HA to services and select mqtt.publish How I get HA display only temperature
i.e. How do I Publish a message to an MQTT topic based on the JSON above

this did not work !!!
{“payload”: “{{ value_json.DHT11.Temperature }}”, “topic”: “tele/D1mini01/SENSOR”}

You have to use MQTT sensor component, not mqtt.publish service.

Thanks for the redirection…!!!
Here what I did
sensor:

  • platform: mqtt
    name: “DHT11”
    state_topic: “tele/D1mini01/SENSOR”
    unit_of_measurement: ‘C’
    value_template: “{{ value_json.DHT11.Temperature }}”
    availability_topic: “tele/D1mini01/SENSOR”
    payload_available: “online”
    payload_not_available: “offline”
    json_attributes_topic: “tele/D1mini01/SENSOR/attributes”

can you please edit it (refere to the mqtt json)

value_template: "{{ value_json['DHT11'].Temperature }}"
1 Like

Thank you for taking the time …

These two are functionally equivalent:

{{ value_json.DHT11.Temperature }}
{{ value_json['DHT11'].Temperature }}

You can prove it to yourself by pasting the following lines into the Template Editor:

{% set value_json = {"Time":"2019-06-04T11:39:54","DHT11":{"Temperature":28.0,"Humidity":29.0},"TempUnit":"C"} %}

{{ value_json.DHT11.Temperature }}
{{ value_json['DHT11'].Temperature }}

Both forms will produce the same result:

You are right …both have their use. I guess the “array” one is better if you have several values to extract.

I’m not sure what you mean by that but if it’s this:

{{ value_json['DHT11', 'DHT12'].Temperature }}

then, no, that’s invalid.

What it’s useful for is if the key word contains one or more spaces.

For example, let’s say it is this:
DHT 11
instead of:
DHT11
Then this will work:

{{ value_json['DHT 11'].Temperature }}

whereas this will fail:

{{ value_json.DHT 11.Temperature }}

You are right again…my guess was affected by the use of for arrays in other languages !!
Your explanation is very clear and I appreciate your diligence…
There is no “indices” , it is dictionary type arguments.