MQTT payload to lovelace card

I’m trying to use the platform: mqtt to capture temp/humidity sensor values via MQTT. The device the temp/humidity sensor is connected to runs the latest Tasmota release.

I configured the mqtt platform in configuation.yaml (following MQTT Sensor - Home Assistant) but I’m stuck in adding this sensor to lovelace; i.e. the mapping from MQTT payload to entity. What entity am I looking for in lovelace?

btw I’m using the Tasmota integration in Home Assistant

If you configure a name in your mqtt sensor config this will generate the entity id by replacing spaces with underscores and using all lower case.

e.g. this

  - platform: mqtt
    name: "Bedroom Temperature"
    state_topic: "home/bedroom/temperature"

Will generate a sensor with the following entity id:


This is what you use in your Lovelace card.

You can check this in the Developer Tools / States menu.

Open your Home Assistant instance and show your state developer tools.

I’m starting with the following from the Tasmota console

01:26:07.386 MQT: tele/tasmota_16CDAC/SENSOR = {“Time”:“2021-05-03T01:26:07”,“ATC-34ef40”:{“Temperature”:18.9,“Humidity”:61.0,“DewPoint”:11.2,“Battery”:91,“RSSI”:-75},“ATC-72b49c”:{“Temperature”:18.9,“Humidity”:62.0,“DewPoint”:11.4,“Battery”:71,“RSSI”:-95},“ATC-7052de”:{“Temperature”:19.0,“Humidity”:67.0,“DewPoint”:12.7,“Battery”:55,“RSSI”:-89},“TempUnit”:“C”}

and then created the mqtt platform entry as follows

  - platform: mqtt
    state_topic: "tele/tasmota_16CDAC/SENSOR"
    name: "tasmota_16CDAC SENSOR"
    unit_of_measurement: "°C"
    value_template: "{{ value_json['ATC-34ef40']['Temperature'] }}"

Under developer tools | states I can find an entity called ‘sensor.tasmota_16cdac_sensor’ but the state is 'unknown'

It should be created by the integration automagically… all mine are… example.

Check the integration>devices> and see if those entities are disabled by default… but you do not need any MQTT sensors etc created for these.

Saw that when I first enabled the integration.

The issue is I have 3 ESP32 around the house running Tasmota but I have no control over which ESP32 picks up which sensor. Say ESP32#1 picks up temp sensor#1. I go and update the entity IDs based on my rules and add them to lovelace. All good.

If an ESP restarts for whatever reason another ESP might pick up sensor#1 and the entity IDs set initially suddenly become unavailable.

So I thought I use MQTT to pull this data…

I don’t understand how that can happen. I have 9 sonoff/nodemcu devices, 4 with temperature sensors. All of the sensor ID’s/entity id’s include that device name and are thus unique.

I don’t see how that would be possible

This is what I’m doing, maybe I’m going wrong somewhere.

I’m using Xiaomi BLE temp/humidity sensors (LYWSD03MMC) running the custom firmware (ATC). Say one of the sensors MAC ends in 52:DE. Starting ESP#1 I see 52:DE. 52:DE might be in range for ESP#2 as well.

With the Tasmota integration on Home Assistant the sensor entities for 52:DE appear in both devices (ESP#1 and ESP#2). I take the nearest ESP (based on signal) and change the entity ID according to my entity model and leave the other ESPs entity IDs unchanged.

The changed entity IDs go to lovelace. Coming back to lovelace after a while I might find an entity ID unavailable and when I go to the Tasmota device it’s gone even though the entity ID is still available on the other Tasmota device.

Do you have situations where a sensor appears in multiple ESPs?

Never. They are physically connected to a ESP and always take on the id of the esp.
What do you see in the Tasmota console?

This is unique for that device. If your sensors are jumping between devices… i have no words to say except something appears to be wrong.

oic. Maybe I wasn’t specific enough earlier.

I’m using ESP32s as BLE gateway devices. The ESP32 picks up the Xiaomi sensor data via BLE and the ESP32 makes this data available to Home Assistant. I thought I hit the jackpot when I found the Tasmota integration in Home Assistant making this an easy process.

For example on TMR04 I see these 3 sensors. As long as there’s Bluetooth coverage I might see 52:DE on another ESP as well and as a result get multiple entity IDs in Home Assistant from the same sensor.

I might have to star another thread as this must be a use case others have as well.

Ah! So you must pair the sensor with an ESP or are you pairing them with all esp’s seperately? I would suspect the latter in which case there is some duplication?

I am not familiar with this BLE gateway though.

I do have a similar problem with my fuel station pricing sensor whereby all entities are randomly allocated a name which is a PITA for the exact same reason but I can get around it as there is some unique data I can use with a template sensor to sort out the mess… maybe you can as well?

There’s no pairing involved with BLE. ESP32’s have a Bluetooth stack which can be used to “listen” to BLE traffic and once known to Tasmota it then can be integrated into Home Assistant via MQTT or the new Tasmota integration on Home Assistant - until you have more than 1 ESPs :slight_smile: :smile:

Back on this…

MQTT topics vs Home Assistant entities

I have a standard mosquitto setup on Home Assistant and have an ESP32 running Tasmota and BLE enabled. The ESP acts as a gateway for Xiaomi sensors.

Looking at the SENSOR topic tele/tasmota_16CDCAC/SENSOR from the ESP32 I see the following:

  "Time" : "2021-05-07T12:16:29",
  "ATC-34ef40" : {
    "Temperature" : 20.7,
    "Humidity" : 59.0,
    "DewPoint" : 12.4,
    "Battery" : 90,
    "RSSI" : -87
  "ATC-7052de" : {
    "Temperature" : 19.8,
    "Humidity" : 63.0,
    "DewPoint" : 12.5,
    "Battery" : 54,
    "RSSI" : -95
  "ATC-72b49c" : {
    "Temperature" : 20.8,
    "Humidity" : 60.0,
    "DewPoint" : 12.7,
    "Battery" : 70,
    "RSSI" : -92
  "TempUnit" : "C"

This means from these 3 sensors I have 3x5=15 entities. In configuration.yaml I configured the following (extract)

- platform: mqtt
    state_topic: "tele/tasmota_16CDAC/SENSOR"
    name: "tasmota_16CDAC SENSOR"
    unit_of_measurement: "°C"
    value_template: "{{ value_json['ATC-72B490']['Temperature'] }}"

  - platform: mqtt
    state_topic: "tele/tasmota_16CDAC/SENSOR"
    name: "tasmota_16CDAC SENSOR"
    unit_of_measurement: "°C"
    value_template: "{{ value_json['ATC-72B490']['Humidity'] }}"

  - platform: mqtt
    state_topic: "tele/tasmota_16CDAC/SENSOR"
    name: "tasmota_16CDAC SENSOR"
    unit_of_measurement: "°C"
    value_template: "{{ value_json['ATC-72B490']['Battery'] }}"

What ends up happening is I get entitiy IDs as follows: tasmota_16cdac_sensor, tasmota_16cdac_sensor_1, tasmota_16cdac_sensor_2 and so on with state unknown in lovelace and no state history.

Where do I go wrong here?

Further to my post above I have restarted mosquitto on HA and checked the log. Two things to note:

  1. There’s a message about not being able to setup the mqtt service
[services.d] starting services
[services.d] done.
[09:45:39] INFO: Setup mosquitto configuration
[09:45:39] INFO: No local user available
[09:45:39] INFO: Initialize Home Assistant Add-on services
[09:45:39] ERROR: Can't setup Home Assistant service mqtt
[09:45:39] INFO: Initialize Home Assistant discovery
[09:45:39] INFO: Start Mosquitto daemon
  1. The ESP in question above does indeed connect to the broker
1620431149: New connection from on port 1883.
1620431149: New connection from on port 1883.
1620431149: New client connected from as DVES_16CDAC (p2, c1, k30, u'mqttuser').

I used mqtt.fx to connect to the HA broker and subscribed to the topic of 2.70; i.e. tasmota_16cdac/SENSOR to see whether sensor data is transmitted and I can see the correct payload.

Using a standard mosquitto config

logins: []
anonymous: false
  active: true
  folder: mosquitto
certfile: fullchain.pem
keyfile: privkey.pem
require_certificate: false

So is this related to the above message about failing to setup the Home Assistant service mqtt?

I hope it’s ok to revive this old thread but I have very much the same issue and the original issue seemed not resolved yet.

I too am trying to get a dashboard card to display a payload value of an mqtt topic.

But which ever syntax I try I get errors in the visual studio code server.

syntaxt found in this thread

 - platform: mqtt
    state_topic: "tele/tasmota_16CDAC/SENSOR"
    name: "tasmota_16CDAC SENSOR"

results in

syntax found at MQTT Sensor - Home Assistant

  - sensor:
      name: "RSSI"
      state_topic: "home/sensor1/infojson"

same errors

I am pretty sure the indentation is correct.

Can anyone please help me get through this?