Interfacing Xiaomi LYWSD03MMC to HA using ESP32

I have 4 sensors but I plan to buy aditional 2…

Ok, it is not that the esp32 is swarmed with requests

I have ordered 4, waiting for them to arrive, and a D1 mini ESP32 ESP-32 ready. I will post if I have the same problem.

Can you run uos.listdir()and let me see the result, and also uos.statvfs("").
Thanks

@Beantree Today this problem occured again. Sorry for dumb question: Can you tell me where should I run: uos.listdir() uos.statvfs("") ?? I tried in putty but doesn’t work also in Python (but probably it should be something more than only this command)

Do you need a specific ESP32 for this. I can’t get it to work on my D1 Mini ESP32

address type = 0, address = a4:c1:38:c3:8e:e5
address type = 0, address = a4:c1:38:c9:bc:21
address type = 0, address = a4:c1:38:50:68:61
address type = 0, address = a4:c1:38:c9:bc:21
address type = 0, address = a4:c1:38:c3:8e:e5
address type = 0, address = a4:c1:38:c9:bc:21
address type = 0, address = a4:c1:38:c3:8e:e5
address type = 0, address = a4:c1:38:c9:bc:21
address type = 0, address = a4:c1:38:50:68:61
address type = 0, address = a4:c1:38:c3:8e:e5
ets Jun  8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:4988
load:0x40078000,len:11408
load:0x40080400,len:6108
entry 0x400806bc
[1B][0;32mI (592) psram: This chip is ESP32-D0WD[1B][0m
[1B][0;31mE (593) spiram: SPI RAM enabled but initialization failed. Bailing out.[1B][0m
[1B][0;32mI (593) cpu_start: Failed to init external RAM; continuing without it.[1B][0m
[1B][0;32mI (600) cpu_start: Pro cpu up.[1B][0m
[1B][0;32mI (604) cpu_start: Application information:[1B][0m
[1B][0;32mI (608) cpu_start: Compile time:     Dec 20 2019 07:58:58[1B][0m
[1B][0;32mI (615) cpu_start: ELF file SHA256:  0000000000000000...[1B][0m
[1B][0;32mI (621) cpu_start: ESP-IDF:          v4.0-beta1[1B][0m
[1B][0;32mI (626) cpu_start: Starting app cpu, entry point is 0x400835e0[1B][0m
[1B][0;32mI (0) cpu_start: App cpu up.[1B][0m
[1B][0;32mI (636) heap_init: Initializing. RAM available for dynamic allocation:[1B][0m
[1B][0;32mI (643) heap_init: At 3FFAFF10 len 000000F0 (0 KiB): DRAM[1B][0m
[1B][0;32mI (649) heap_init: At 3FFB6388 len 00001C78 (7 KiB): DRAM[1B][0m
[1B][0;32mI (655) heap_init: At 3FFB9A20 len 00004108 (16 KiB): DRAM[1B][0m
[1B][0;32mI (661) heap_init: At 3FFBDB5C len 00000004 (0 KiB): DRAM[1B][0m
[1B][0;32mI (667) heap_init: At 3FFCCA50 len 000135B0 (77 KiB): DRAM[1B][0m
[1B][0;32mI (674) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM[1B][0m
[1B][0;32mI (680) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM[1B][0m
[1B][0;32mI (686) heap_init: At 4009E2E4 len 00001D1C (7 KiB): IRAM[1B][0m
[1B][0;32mI (692) cpu_start: Pro cpu start user code[1B][0m
[1B][0;32mI (711) spi_flash: detected chip: generic[1B][0m
[1B][0;32mI (712) spi_flash: flash io: dio[1B][0m
[1B][0;32mI (712) cpu_start: Chip Revision: 1[1B][0m
[1B][0;33mW (713) cpu_start: Chip revision is higher than the one configured in menuconfig. Suggest to upgrade it.[1B][0m
[1B][0;32mI (724) cpu_start: Starting scheduler on PRO CPU.[1B][0m
[1B][0;32mI (0) cpu_start: Starting scheduler on APP CPU.[1B][0m
[1B][0;31mE (40) spiram: SPI RAM not initialized[1B][0m
[1B][0;32mI (160) modsocket: Initializing[1B][0m

Brownout detector was triggered

ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:4988
load:0x40078000,len:11408
load:0x40080400,len:6108
entry 0x400806bc
[1B][0;32mI (592) psram: This chip is ESP32-D0WD[1B][0m
[1B][0;31mE (593) spiram: SPI RAM enabled but initialization failed. Bailing out.[1B][0m
[1B][0;32mI (593) cpu_start: Failed to init external RAM; continuing without it.[1B][0m
[1B][0;32mI (600) cpu_start: Pro cpu up.[1B][0m
[1B][0;32mI (604) cpu_start: Application information:[1B][0m
[1B][0;32mI (609) cpu_start: Compile time:     Dec 20 2019 07:58:58[1B][0m
[1B][0;32mI (615) cpu_start: ELF file SHA256:  0000000000000000...[1B][0m
[1B][0;32mI (621) cpu_start: ESP-IDF:          v4.0-beta1[1B][0m
[1B][0;32mI (626) cpu_start: Starting app cpu, entry point is 0x400835e0[1B][0m
[1B][0;32mI (618) cpu_start: App cpu up.[1B][0m
[1B][0;32mI (637) heap_init: Initializing. RAM available for dynamic allocation:[1B][0m
[1B][0;32mI (643) heap_init: At 3FFAFF10 len 000000F0 (0 KiB): DRAM[1B][0m
[1B][0;32mI (649) heap_init: At 3FFB6388 len 00001C78 (7 KiB): DRAM[1B][0m
[1B][0;32mI (655) heap_init: At 3FFB9A20 len 00004108 (16 KiB): DRAM[1B][0m
[1B][0;32mI (662) heap_init: At 3FFBDB5C len 00000004 (0 KiB): DRAM[1B][0m
[1B][0;32mI (668) heap_init: At 3FFCCA50 len 000135B0 (77 KiB): DRAM[1B][0m
[1B][0;32mI (674) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM[1B][0m
[1B][0;32mI (680) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM[1B][0m
[1B][0;32mI (687) heap_init: At 4009E2E4 len 00001D1C (7 KiB): IRAM[1B][0m
[1B][0;32mI (693) cpu_start: Pro cpu start user code[1B][0m
[1B][0;32mI (711) spi_flash: detected chip: generic[1B][0m
[1B][0;32mI (712) spi_flash: flash io: dio[1B][0m
[1B][0;32mI (712) cpu_start: Chip Revision: 1[1B][0m
[1B][0;33mW (713) cpu_start: Chip revision is higher than the one configured in menuconfig. Suggest to upgrade it.[1B][0m
[1B][0;32mI (724) cpu_start: Starting scheduler on PRO CPU.[1B][0m
[1B][0;32mI (0) cpu_start: Starting scheduler on APP CPU.[1B][0m
[1B][0;31mE (40) spiram: SPI RAM not initialized[1B][0m
[1B][0;32mI (160) modsocket: Initializing[1B][0m
[1B][0;32mI (1834) phy: phy_version: 4102, 2fa7a43, Jul 15 2019, 13:06:06, 0, 0[1B][0m

Brownout detector was triggered

ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:4988
load:0x40078000,len:11408
load:0x40080400,len:6108
entry 0x400806bc
[1B][0;32mI (592) psram: This chip is ESP32-D0WD[1B][0m
[1B][0;31mE (593) spiram: SPI RAM enabled but initialization failed. Bailing out.[1B][0m
[1B][0;32mI (593) cpu_start: Failed to init external RAM; continuing without it.[1B][0m
[1B][0;32mI (600) cpu_start: Pro cpu up.[1B][0m
[1B][0;32mI (604) cpu_start: Application information:[1B][0m
[1B][0;32mI (609) cpu_start: Compile time:     Dec 20 2019 07:58:58[1B][0m
[1B][0;32mI (615) cpu_start: ELF file SHA256:  0000000000000000...[1B][0m
[1B][0;32mI (621) cpu_start: ESP-IDF:          v4.0-beta1[1B][0m
[1B][0;32mI (626) cpu_start: Starting app cpu, entry point is 0x400835e0[1B][0m
[1B][0;32mI (618) cpu_start: App cpu up.[1B][0m
[1B][0;32mI (637) heap_init: Initializing. RAM available for dynamic allocation:[1B][0m
[1B][0;32mI (643) heap_init: At 3FFAFF10 len 000000F0 (0 KiB): DRAM[1B][0m
[1B][0;32mI (649) heap_init: At 3FFB6388 len 00001C78 (7 KiB): DRAM[1B][0m
[1B][0;32mI (655) heap_init: At 3FFB9A20 len 00004108 (16 KiB): DRAM[1B][0m
[1B][0;32mI (662) heap_init: At 3FFBDB5C len 00000004 (0 KiB): DRAM[1B][0m
[1B][0;32mI (668) heap_init: At 3FFCCA50 len 000135B0 (77 KiB): DRAM[1B][0m
[1B][0;32mI (674) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM[1B][0m
[1B][0;32mI (680) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM[1B][0m
[1B][0;32mI (687) heap_init: At 4009E2E4 len 00001D1C (7 KiB): IRAM[1B][0m
[1B][0;32mI (693) cpu_start: Pro cpu start user code[1B][0m
[1B][0;32mI (711) spi_flash: detected chip: generic[1B][0m
[1B][0;32mI (712) spi_flash: flash io: dio[1B][0m
[1B][0;32mI (712) cpu_start: Chip Revision: 1[1B][0m
[1B][0;33mW (713) cpu_start: Chip revision is higher than the one configured in menuconfig. Suggest to upgrade it.[1B][0m
[1B][0;32mI (724) cpu_start: Starting scheduler on PRO CPU.[1B][0m
[1B][0;32mI (0) cpu_start: Starting scheduler on APP CPU.[1B][0m
[1B][0;31mE (40) spiram: SPI RAM not initialized[1B][0m
[1B][0;32mI (160) modsocket: Initializing[1B][0m
[1B][0;32mI (1824) phy: phy_version: 4102, 2fa7a43, Jul 15 2019, 13:06:06, 0, 0[1B][0m

Brownout detector was triggered

ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:4988
load:0x40078000,len:11408
load:0x40080400,len:6108
entry 0x400806bc
[1B][0;32mI (592) psram: This chip is ESP32-D0WD[1B][0m
[1B][0;31mE (593) spiram: SPI RAM enabled but initialization failed. Bailing out.[1B][0m
[1B][0;32mI (593) cpu_start: Failed to init external RAM; continuing without it.[1B][0m
[1B][0;32mI (600) cpu_start: Pro cpu up.[1B][0m
[1B][0;32mI (604) cpu_start: Application information:[1B][0m
[1B][0;32mI (609) cpu_start: Compile time:     Dec 20 2019 07:58:58[1B][0m
[1B][0;32mI (615) cpu_start: ELF file SHA256:  0000000000000000...[1B][0m
[1B][0;32mI (621) cpu_start: ESP-IDF:          v4.0-beta1[1B][0m
[1B][0;32mI (626) cpu_start: Starting app cpu, entry point is 0x400835e0[1B][0m
[1B][0;32mI (618) cpu_start: App cpu up.[1B][0m
[1B][0;32mI (637) heap_init: Initializing. RAM available for dynamic allocation:[1B][0m
[1B][0;32mI (643) heap_init: At 3FFAFF10 len 000000F0 (0 KiB): DRAM[1B][0m
[1B][0;32mI (649) heap_init: At 3FFB6388 len 00001C78 (7 KiB): DRAM[1B][0m
[1B][0;32mI (655) heap_init: At 3FFB9A20 len 00004108 (16 KiB): DRAM[1B][0m
[1B][0;32mI (662) heap_init: At 3FFBDB5C len 00000004 (0 KiB): DRAM[1B][0m
[1B][0;32mI (668) heap_init: At 3FFCCA50 len 000135B0 (77 KiB): DRAM[1B][0m
[1B][0;32mI (674) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM[1B][0m
[1B][0;32mI (680) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM[1B][0m
[1B][0;32mI (687) heap_init: At 4009E2E4 len 00001D1C (7 KiB): IRAM[1B][0m
[1B][0;32mI (693) cpu_start: Pro cpu start user code[1B][0m
[1B][0;32mI (711) spi_flash: detected chip: generic[1B][0m
[1B][0;32mI (712) spi_flash: flash io: dio[1B][0m
[1B][0;32mI (712) cpu_start: Chip Revision: 1[1B][0m
[1B][0;33mW (713) cpu_start: Chip revision is higher than the one configured in menuconfig. Suggest to upgrade it.[1B][0m
[1B][0;32mI (724) cpu_start: Starting scheduler on PRO CPU.[1B][0m
[1B][0;32mI (0) cpu_start: Starting scheduler on APP CPU.[1B][0m
[1B][0;31mE (40) spiram: SPI RAM not initialized[1B][0m
[1B][0;32mI (160) modsocket: Initializing[1B][0m
[1B][0;32mI (1824) phy: phy_version: 4102, 2fa7a43, Jul 15 2019, 13:06:06, 0, 0[1B][0m

Brownout detector was triggered

ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:4988
load:0x40078000,len:11408
load:0x40080400,len:6108
entry 0x400806bc
[1B][0;32mI (592) psram: This chip is ESP32-D0WD[1B][0m
[1B][0;31mE (593) spiram: SPI RAM enabled but initialization failed. Bailing out.[1B][0m
[1B][0;32mI (593) cpu_start: Failed to init external RAM; continuing without it.[1B][0m
[1B][0;32mI (600) cpu_start: Pro cpu up.[1B][0m
[1B][0;32mI (604) cpu_start: Application information:[1B][0m
[1B][0;32mI (609) cpu_start: Compile time:     Dec 20 2019 07:58:58[1B][0m
[1B][0;32mI (615) cpu_start: ELF file SHA256:  0000000000000000...[1B][0m
[1B][0;32mI (621) cpu_start: ESP-IDF:          v4.0-beta1[1B][0m
[1B][0;32mI (626) cpu_start: Starting app cpu, entry point is 0x400835e0[1B][0m
[1B][0;32mI (618) cpu_start: App cpu up.[1B][0m
[1B][0;32mI (637) heap_init: Initializing. RAM available for dynamic allocation:[1B][0m
[1B][0;32mI (643) heap_init: At 3FFAFF10 len 000000F0 (0 KiB): DRAM[1B][0m
[1B][0;32mI (649) heap_init: At 3FFB6388 len 00001C78 (7 KiB): DRAM[1B][0m
[1B][0;32mI (655) heap_init: At 3FFB9A20 len 00004108 (16 KiB): DRAM[1B][0m
[1B][0;32mI (662) heap_init: At 3FFBDB5C len 00000004 (0 KiB): DRAM[1B][0m
[1B][0;32mI (668) heap_init: At 3FFCCA50 len 000135B0 (77 KiB): DRAM[1B][0m
[1B][0;32mI (674) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM[1B][0m
[1B][0;32mI (680) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM[1B][0m
[1B][0;32mI (687) heap_init: At 4009E2E4 len 00001D1C (7 KiB): IRAM[1B][0m
[1B][0;32mI (693) cpu_start: Pro cpu start user code[1B][0m
[1B][0;32mI (711) spi_flash: detected chip: generic[1B][0m
[1B][0;32mI (712) spi_flash: flash io: dio[1B][0m
[1B][0;32mI (712) cpu_start: Chip Revision: 1[1B][0m
[1B][0;33mW (713) cpu_start: Chip revision is higher than the one configured in menuconfig. Suggest to upgrade it.[1B][0m
[1B][0;32mI (724) cpu_start: Starting scheduler on PRO CPU.[1B][0m
[1B][0;32mI (0) cpu_start: Starting scheduler on APP CPU.[1B][0m
[1B][0;31mE (40) spiram: SPI RAM not initialized[1B][0m
[1B][0;32mI (160) modsocket: Initializing[1B][0m
[1B][0;32mI (1824) phy: phy_version: 4102, 2fa7a43, Jul 15 2019, 13:06:06, 0, 0[1B][0m

@Beantree Excellent work!

This works great.
I don’t know if I had to do this, but I did add more MQTT server details to mqtt.py, such as the MQTT port, MQTT user, and MQTT password. I’m using the built-in MQTT Broker in HA running on a Raspi4.

The Mi LYWSD03MMC seems to be broadcasting every minute, is it supposed to do that? I ask because the battery seems to be draining fast, 100% to 90% in about ~24hrs. Can we control the broadcasting rate?

The very last line of mqtt.py is time.sleep(60). This means wait for 60 seconds. You can just change this to, say, 300 for 5 minutes.

@Beantree Please help me with my problem. I even try connect just 2 devices instead 4 but i have got the same problem after 2 days.

@Beantree Works perfect, exactly what I needed. Thanks.

@Asica10 please can you load the latest versions of the software and let me know how you get on. You should also make sure there is no ble.log file on your device.

@Beantree Today during night my sensors stopped working. I connect esp32 to putty and I saw that mqtt.py file was missing. Do you know what was happened?
After reupload mqtt.py sensors works correctly.

Edit// I dont know what was happened with Mqtt files after 1 days, but from this time everything is working like a charn :slight_smile:
Thanks again for great job!

There might be a bug somewhere in code, or there is some other sort of problem.

Thermometer x3 mac in mosquito broker appears with space inside, while correct mac is:a4:c1:38:f6:0a:3e
a4c138f60a3e

ESP32 itself finds the right MAC address, but it does not update my HA entities, because of wrong MAC address :confused:

Have you got any clues how to solve it?

If you use the latest version of the software this is fixed.

I added in my mqtt.py file the station.ifconfig line so my ESP32 has a static ip-address.
Maybe other want that to.

station.active(True)
station.connect(ssid, password)
station.ifconfig((’192.168.1.110′,’255.255.255.0′,’192.168.1.1′,’192.168.1.1′))

Hello,
From time to time I have problem with missing files. It seems to ble.py and mqtt.py are removing from esp32 memory ( sometimes is 1 days sometimes 1 week).
Reflash these two files solve the issue for next few days.

Do you have any idea what is the problem?

I recommend dropping my solution now that the excellent esphome has a lywsd03mmc solution,
See the detail here
I have been using this for some time now,

You need to take a look at this to see how to get the bindkey for your device.

Thank you for answer. I’ve checked it but your
solution seems to be better…
Using integration with esphome values in HA are refreshing very rare ( sometimes one time on hour…). The second problem is bug with battery level
( all time 100% for empty and full battery).

Do you have this issue also?
If no do you add some parameters under: esp_ble_tracker?

If you use the custom firmware the battery level will be working as expected.

Also no more bind_key mess.

How often does your temperature change?

I use mine now with OpenMqttGateway (and the custom firmware). Works very well. Refreshes every minute :slight_smile: