Tasmota & Xaomi BLE temp sensors

I’m trying to use a Tasmota flashed ESP32 module to send temp/humidity data from a connected BLE Xaomi sensor to HA. I have a Xaomi LYWSD03MMC sensor flashed with this custom firmware.

I have a ESP32 board flashed with Tasmota hooked up to a PIR sensor brought into HA as a binary sensor used for motion detection automations, which works great:

15:51:34.358 RUL: SWITCH1#STATE=1 performs "Publish stat/laundry_pir/PIR ON"
15:51:34.368 MQT: stat/laundry_pir/PIR = ON
15:51:35.411 RUL: SWITCH1#STATE=0 performs "Publish stat/laundry_pir/PIR OFF"
15:51:35.424 MQT: stat/laundry_pir/PIR = OFF

I also have the BLE sensor flashed and connected to the ESP32:

The board temp and BLE sensor data seem to be publishing on MQTT correctly:

16:12:11.824 MQT: tele/laundry_pir/STATE = {"Time":"2021-05-26T16:12:11","Uptime":"0T15:39:48","UptimeSec":56388,"Heap":119,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"MqttCount":6,"Wifi":{"AP":1,"SSId":"****************","BSSId":"**:**:**:**:**:**","Channel":11,"RSSI":70,"Signal":-65,"LinkCount":6,"Downtime":"0T00:01:27"}}
16:12:11.854 MQT: tele/laundry_pir/SENSOR = {"Time":"2021-05-26T16:12:11","Switch1":"OFF","ESP32":{"Temperature":53.3},"TempUnit":"C"}
16:12:11.865 MQT: tele/laundry_pir/BLE = {"Time":"2021-05-26T16:12:11","BLEDevices":{"total":6,"************":{"i":0,"r":-78},"************":{"i":1,"r":-58},"************":{"i":2,"r":-93},"************":{"i":3,"r":-98},"************":{"i":4,"r":-96},"************":{"i":5,"r":-100}}}
16:12:11.896 MQT: tele/laundry_pir/BLE = {"Time":"2021-05-26T16:12:11","BLE":{"scans":2813,"adverts":1192170,"devices":6,"resets":0}}
16:12:24.819 MQT: tele/laundry_pir/SENSOR = {"Time":"2021-05-26T16:12:24","ATC******":{"mac":"************","Temperature":24.9,"Humidity":40.0,"DewPoint":10.3,"Battery":100,"RSSI":-61}}

But only the board temp is showing in HA:

Do I have to explicitly define the BLE data as entities to use them in HA, or did I miss something simple?

Edit: This is only part of the answer, and will result in a flood of JSON errors. A better way is to run MI32Option6, splitting each sensor on to its own topic. See the later post below for changes.

Original Post:

To answer my own question, I added these sensors to my sensors.yaml:

#Laundry Environmental Sensors
- platform: mqtt
  name: "Laundry Temperature"
  state_topic: "tele/laundry_pir/SENSOR"
  value_template: "{{value_json['ATC******'].Temperature }}"
  unit_of_measurement: "°C"
- platform: mqtt
  name: "Laundry Humidity"
  state_topic: "tele/laundry_pir/SENSOR"
  value_template: "{{value_json['ATC******'].Humidity }}"
  unit_of_measurement: "%"
  icon: mdi:water-percent
- platform: mqtt
  name: "Laundry DewPoint"
  state_topic: "tele/laundry_pir/SENSOR"
  value_template: "{{value_json['ATC******'].DewPoint }}"
  unit_of_measurement: "°C"
- platform: mqtt
  name: "Laundry Battery"
  state_topic: "tele/laundry_pir/SENSOR"
  value_template: "{{value_json['ATC******'].Battery }}"
  unit_of_measurement: "%"
  icon: mdi:battery-outline

…and everything seems to be working:
Screenshot from 2021-05-26 18-47-34

Screenshot from 2021-05-26 18-47-06

Just odd, since all the info I saw about setting these up indicated that they would automatically populate. I guess something must have changed in the last few months?

1 Like

I have same issue. Nowhere can the scanned sensors be seen inside HA. So kind of makes no sense to even add Tasmota intergration for this Tasmota32 BLE device.

I also tried manually adding MQTT sensor but I get tons of errors in log since the MQTT topic (tele/tasmota32_ble/SENSOR) is same for all sensors and using device specific MQTT path will break when json attribute if not found:

tele/tasmota32_ble/SENSOR = {"Time":"2021-08-20T13:30:29","ESP32":{"Temperature":71.1},"TempUnit":"C"}
Template variable error: 'dict object' has no attribute 'ATCxxxxxx' when rendering '{{value_json['ATCxxxxxx'].Temperature }}

I am sure you get this errors in your log too.

You still have MQTT auto discovery option which works great. Just set this under console:

SetOption19 1 

I am using it currently. Only thing that is not working like I wish it would, is that all the sensor values are unavailable when I restart home assistant and they stay like that until ESP32 scans them again and Tasmota passes the values to MQTT. Would be nice to get last read value when HA restarts.

Any other idea what I can try?

I noticed that I was receiving a flood of log errors like yours. If you run MI32Option6 Tasmota will create individual topics for each connected BT sensor, ie tele/tasmota_ble/ATC*****1 and tele/tasmota_ble/ATC*****2 instead of everything published on tele/tasmota_ble/SENSOR

You can then simplify your json to something like

- platform: mqtt
  name: "Laundry Temperature"
  state_topic: "tele/tasmota_ble/ATC******"
  unit_of_measurement: "°C"
  value_template: "{{ value_json.Temperature }}"

which should stop HA from complaining about missing json attributes.

1 Like

Great tip! One more question as you are in same situation like me. When you restart Home Assistant, are all sensors unavailable until first scan or the show last read value?

Typically, this is the exact use case for SensorRetain. Unfortunately, this setting only enables the retain flag on message tele/%topic%/SENSOR which won’t help if you have each sensor split out on it’s own custom topic.

Is the unavailable status for the first minute after HA restarts actually causing issues?

Not yet sure if it will cause issues as heating season has not yet started.

I am using temperature values in generic thermostat that will manage my floor heating (relay switching on valves per room). Now when I restart HA all the temperature values are unavailable until first scan. Proper way would be to keep the last read value. Default period (MI32Period) is set to 5 minutes (300 seconds). I could set it less but it will probably impact on battery consumption.

Documentation for MQTT Sensor clearly states that without retain flag the initial state will be undefined.

And SensorRetain is on for tele/%topic%/SENSOR

I can try and open ticket for Tasmota to add retain option also for MI32Option6 topics or you perhaps have any other idea?

Found this TT:

And fix:

Not sure if this is inside production already. Flashed my ESP32 with development but I do not see retain flag on message.

The commit showed that this fix should have been part of the newly released 10.0.0, but I don’t see it in the changelog.

I have updated my ESP32 to version today. The tele/tasmota_ble/XXX messages are still not retained. No clue why not. You tried it yourself?

The problem I am having is that MI32Option6 resets to 0, when the ESP32 is restarted.

Have tried it on and and on 2 different ESP32 devices.

I think I saw you on the issue thread, but for anyone else, this has been committed in and seems to be finally working!

Might be a bug. You could also try adding a rule that sets it on reboot:

rule1 on system#boot do backlog MI32Option6 1; sensorretain 1 endon

I am using 12.0.2, also cannot get option 6 to work at all, not by setting during runtime or setting a rule:

rule1 on system#boot do backlog MI32Option6 1; sensorretain 1 endon


01:34:10.859 MQT: tele/tasmota_975B88/BLE = {"Time":"2022-06-25T01:34:10","BLEDevices":{"total":10,"445CE98FF2FF":{"i":0,"r":-84},"D003DFA22ED7":{"i":1,"r":-73},"2AE7934593E1":{"i":2,"r":-97},"A4C138029E5F":{"i":3,"r":-82},"24FCE52703C5":{"i":4,"r":-87},"6C4A85378905":{"i":5,"r":-59},"105DDC4780A5":{"i":6,"r":-96},"CDD751150F7E":{"i":7,"r":-41},"CC2E4DD968F0":{"i":8,"r":-93},"004279034616":{"i":9,"n":"OS888 10022717","r":-86}}}
01:34:10.897 MQT: tele/tasmota_975B88/BLE = {"Time":"2022-06-25T01:34:10","BLE":{"scans":0,"adverts":152,"devices":10,"resets":0}}
01:34:12.587 MQT: tele/tasmota_975B88/SENSOR = {"Time":"2022-06-25T01:34:12","MJ_HT_V1dcc73e":{"mac":"4c65a8dccxxe","Temperature":27.3,"Humidity":76.3,"DewPoint":22.8,"RSSI":-76},"TempUnit":"C"}
01:35:05.174 CMD: MI32Option6
01:35:05.190 MQT: stat/tasmota_975B88/RESULT = {"MI32Option6":0}
01:35:16.049 CMD: MI32Option6=1
01:35:16.061 MQT: stat/tasmota_975B88/RESULT = {"MI32Option6":0}

whenever I check the status it is always 0 !

Did you turn on rule with rule1 1 before rebooting?

As for manually setting, MI32Option6 1 works but MI32Option6=1 does not.

Ahhh, thanks, yes my syntax was wrong, working now.

But is there an option to use the MACID as the topic, as I am getting appreviated topics like:

tele/tasmota_ble/Unknown029e5f = {"Time":"2022-06-25T02:59:02","mac":"a4c138029e5f","RSSI":-76}

Sorry guys to bump this I’m struggling with the change in MQQT config for a while now.
I previously had OMG running on my ESP32 but have since switched to Tasmota - working perfectly - and see my 3 Mi sensors in it’s Web UI and on MQTT:

topic is tele/tasmota_ble/ATC[MAC 1,2&3 individually]


ATCcf0156 = {"Time":"2023-01-01T16:28:09","ATC[redacted1]":{"mac":"[redacted1]","Temperature":18.2,"Humidity":64.6,"DewPoint":11.4,"Btn":1,"Battery":50,"RSSI":-92},"TempUnit":"C"}

ATC134624 = {"Time":"2023-01-01T16:28:07","ATC[redacted2]":{"mac":"[redacted2]","Temperature":21.3,"Humidity":52.8,"DewPoint":11.3,"Btn":1,"Battery":31,"RSSI":-87},"TempUnit":"C"}

ATCdede60 = {"Time":"2023-01-01T16:28:08","ATC[redacted3]":{"mac":"[redacted3]","Temperature":15.0,"Humidity":57.7,"DewPoint":6.7,"Btn":1,"Battery":70,"RSSI":-88},"TempUnit":"C"}

However I can’t get the sensors automatically discovered any more, which I understand.
Here’s the struggle with the manual config:


#MQTT Stuff

  - state_topic: "tele/tasmota_ble/ATCredacted"
    name: "Temperature"
    device_class: temperature
    unit_of_measurement: "°C"
    value_template: "{{ value_json.temperature }}"
  - state_topic: "tele/tasmota_ble/ATC[redacted1]"
    name: "Humidity"
    device_class: humidity
    unit_of_measurement: "%"
    value_template: "{{ value_json.humidity }}"

Nothing else in there.

That gets them created in HA but no values are ever assigned. I also get

* Template variable warning: 'dict object' has no attribute 'temperature' when rendering '{{ value_json.temperature }}'
* Template variable warning: 'dict object' has no attribute 'humidity' when rendering '{{ value_json.humidity }}'

“MI32Option6” is set to 3 as I read somewhere.

Any working configs you could post? I’d really love to add more of those sensors.

SetOption19 0

Thanks, but that’s already set.
The ESP32 Tasmota device shows up like the others I have - what I’m missing is the BLE sensors under the “tasmota_ble” topic.

Capitalize your temp/humidity json values in the value_template.

1 Like