sarishy
(Samir El-Arishy)
June 4, 2019, 10:48am
1
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
sarishy
(Samir El-Arishy)
June 4, 2019, 11:25am
2
this did not work !!!
{“payload”: “{{ value_json.DHT11.Temperature }}”, “topic”: “tele/D1mini01/SENSOR”}
Bieniu
(Maciek)
June 4, 2019, 11:56am
3
You have to use MQTT sensor component, not mqtt.publish service.
sarishy
(Samir El-Arishy)
June 4, 2019, 12:24pm
4
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)
Bieniu
(Maciek)
June 4, 2019, 2:07pm
5
value_template: "{{ value_json['DHT11'].Temperature }}"
1 Like
sarishy
(Samir El-Arishy)
June 4, 2019, 6:00pm
6
Thank you for taking the time …
123
(Taras)
June 4, 2019, 6:18pm
7
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:
sarishy
(Samir El-Arishy)
June 5, 2019, 4:52am
8
You are right …both have their use. I guess the “array” one is better if you have several values to extract.
123
(Taras)
June 5, 2019, 10:45am
9
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 }}
sarishy
(Samir El-Arishy)
June 5, 2019, 5:35pm
10
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.