I tried a lot of configurations but could not get it running, i also read a few other threads and also the help file, but already wasted some hours.
Could anybody help me out?
Thanks, best regards,
Dominik
1.yes see first screen shot. Mqtt messages are published on the configured topic
2.yes many other sensors already work for a long time
3. Yes see the posted cutout of my config it is under sensor.
4. Restarted HA many times
5. No errors in this mosquitto broker log.
I have a somehow similar problem. My ESP8266 Arduino sends MQTT topics to Mosquito Broker. And it is successfully received in HA. Below is the extract from MQTT Settings page:
Listen to a topic
Listening to
vrane/meteo1/env
Message 0 received on vrane/meteo1/env at 21:04:
{
"data": {
"Temp": 23.75,
"humid": 51.02929688,
"press": 993.3134155,
"batt": 1.771000028
}
}
QoS: 0 - Retain: false
So ESP8266 sends topics, MQTT is properly configured and receives topics.
I have configured sensors in the configuration.yaml as follows:
But I am not able to get rid of this error from Logs. I probably do some silly mistakes, but I cannot solve them.
Logger: homeassistant.helpers.template
Source: helpers/template.py:582
First occurred: 20:55:14 (428 occurrences)
Last logged: 21:09:23
Template variable warning: 'dict object' has no attribute 'Temp' when rendering '{{ value_json.Temp }}'
Template variable warning: 'dict object' has no attribute 'humid' when rendering '{{ value_json.humid }}'
Template variable warning: 'dict object' has no attribute 'press' when rendering '{{ value_json.press }}'
Template variable warning: 'dict object' has no attribute 'batt' when rendering '{{ value_json.batt }}'
Other MQTT sensors (Tasmota) already work for a long time
I have restarted HA many times
No errors in this Mosquitto broker log.
Those warning messages will appear if the received payload doesn’t look like the example you posted. In other words, if the payload isn’t a dictionary containing a Temp key then this template {{ value_json.Temp }} will fail.
Try this version:
value_template: '{{ value_json.Temp if value_json.Temp is defined else this.state }}'
@123 Thank you. I will try.
Nevertheless, the example is taken directly from MQTT Mosquitto, from the menu “Listen to topic” and this is exactly what is received inside HA. If I understand well this version will avoid the error in the log, but will not read the value from MQTT message.
value_template: '{{ value_json.Temp if value_json.Temp is defined else this.state }}'