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.

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
1 Like