Skip to content

Latest commit

 

History

History
607 lines (417 loc) · 40.4 KB

README.md

File metadata and controls

607 lines (417 loc) · 40.4 KB

Custom firmware for BLE thermometers on the Telink chipset.

Warning: Firmware LYWSD03MMC version 2.1.1_0159 is temporarily not supported!

Please post questions about using and setting up Home Assistant integrations on the appropriate resources!

Next year (2024), a transition to modern Bluetooth SIG standards is planned. Linux has not supported Bluetooth open-standards since 2014. There is no point in waiting more than 10 years for progress in Linux. The path will sink into oblivion :).

This repository contains custom firmware for several Bluetooth Thermometer & Hygrometer devices. The download of the appropriate firmware for your device will be presented automatically in TelinkMiFlasher.html. Downloading files from this repository is not required. Alternative firmware and configurator from ATC1441 (variant ATC_Thermometer.bin) can be found here: atc1441/ATC_MiThermometer. Custom firmware is not supported in MiHome. But it is possible to work LYWSD03MMC with 'Xiaomi Gateway 3' by first registering in MiHome on the official firmware, flashing to custom firmware with restoring the binding key from MiHome, replacing the device name with "LYWSD03MMC" and setting the advertising type to "MIJIA (MiHome)" marked "encrypted".

Support for Zigbee firmware is in the ZigbeeTLc repository.

Support for BLE-Zigbee firmware is in the BZdevice repository.

There is an alternative firmware from Ivan Belokobylskij for LYWSD03MMC to work in Zigbee 3.0 mode.

The custom firmware can be flashed via a modern browser and over-the-air (OTA) without opening the device and unlocks several customization options. You can go back to the original firmware at any time. OTA and configuration main page - TelinkMiFlasher.html.

Key features

  • Extended battery life (over a year)
  • Improved measurement accuracy and extended format in 0.01 units
  • Full support Home Assistant 'BTHome integration', 'Passive BLE Monitor' and other.
  • Supports encrypted connections using PIN-code and encrypted bindkey beacon
  • Supports Bluetooth v5.0+ LE Long Range (LE 1M/2M/Coded 500K/125K), CSA1/CSA2 (Channel Selection Algorithm), Advertising Extensions: primary and secondary Coded PHY S=8, Connectable. LE Long Range - distance of 1 km in a straight line at TX +0 dB.
  • 3 LCD Display Screens (Looping): Temperature & Humidity & Comfort, Temperature & Battery Level, Clock
  • Measurement values recording & Charting. See Reading Measurements from Flash
  • Adjustable correction offsets and Comfort zones
  • Support for 4 beacon formats: Xiaomi, ATC, Custom, BTHome v2 and encrypted options. Legacy and Extended Advertisements.
  • Adjustable RF TX Power (-20..+10dB) & Bluetooth advertising interval. +3..+10 dB require a more powerful power supply.
  • DIY improvements - relay control by temperature or humidity, transmission of the reed switch status - open / closed or pulse counter
  • Firmware download support for Zigbee
  • Flashing third party Zigbee OTA files.
  • Support Low cost BLE Advertisements Repeater into Zigbee:

b2z.gif

Supported models:

  • Thermometers with display
Xiaomi Mijia (LYWSD03MMC)
6 HW versions
Xiaomi Miaomiaoce (MHO-C401)
2 HW versions
Qingping Temp & RH Monitor (CGG1-Mijia) CGDK2 Qingping Temp & RH Monitor Lite Xiaomi Mijia MJWSD05MMC MHO-C122 (2AWMOMHOC122)
Xiaomi Mijia (LYWSD03MMC) Xiaomi Miaomiaoce (MHO-C401) E-ink CGG1 'Qingping Temp & RH Monitor', Xiaomi Mijia DevID: 0x0B48 CGDK2 Qingping Temp & RH Monitor Lite Xiaomi Mijia (MJWSD05MMC) MHO-C122 (2AWMOMHOC122)
OTA OTA OTA OTA OTA Programmator
BLE and Zigbee BLE and Zigbee BLE BLE and Zigbee BLE BLE and Zigbee
  • Thermometers without display
Tuya ZigBee TS0201 TZ3000 Tuya ZigBee TH03Z Tuya ZigBee ZTH01 Tuya ZigBee ZTH02
Programmator/Zigbee OTA, OTA Programmator/Zigbee OTA, OTA Programmator/Zigbee OTA, OTA Programmator/Zigbee OTA, OTA
BLE and Zigbee BLE and Zigbee BLE and Zigbee BLE and Zigbee
  • Tuya devices (SOC PHY62x2)
Tuya devices on SoC PHY62x2
7 types
Tuya PHY62x2
PHY62x2BTHome

Warnings

  1. Home Assistant SSD TBW. Using the Home Assistant with Bluetooth leads to rapid wear of the data carrier due to constant database recording and overwriting of small Bluez files in '/var/lib/bluetooth/'.

With a couple dozen BLE devices, a 256GB SSD is only enough for 2 years.

  1. If you have many BLE devices, the adapter must be able to receive BLE advertisements every 3 ms.

UART speeds of 921600 baud and even USB1.1 are not enough to transfer information in binary form in the HCI format.

Requires BT adapter with USB2.0 HS. Otherwise, there will be many gaps in the reception. Do not use ESP32xxx - it cannot work with BLE at normal speed and drains the batteries of all BLE devices when connected! ESPHome does not work with Bluetooth 5.0 and misses a lot of advertising packets from BLE devices.

  1. For reliable connection and refirmware on LYWSD03MMC, the battery level must be more than 40%. This is a design feature - a cheaper version of the hardware from Xiaomi.

On devices with missing power capacities, do not set 'Connect latency' to more than 1000 ms!

  1. Home Assistant in "Bluetooth" integration does not full support Bluetooth 5.0 and is not implied.

How to switch the USB-BT5.0+ adapter to work in LE Long Range in Home Assistant under Linux:

On thermometers with a button, if the button function is set to Connect, then a short application on the button for 80 seconds enables connection in BT4.0 mode.

If you accidentally set the 'LE Long Range' on the thermometer, and your device does not support BT5.0, remove and insert the battery - the thermometer will switch to BT4.2 support mode.

If you have a smartphone with BT5.0+ and the nRFConnect program, then you can reset all settings to default by connecting to a thermometer and sending the 0x56 command, as shown in the screenshot:

img nRFConnect_set_default.png

To disable only the 'Long Range' option, use the code 0xDD.

The Web Bluetooth API in Chrome does not yet allow scanning for Bluetooh 5.0+ devices.

  1. On Linux, when installing large advertising intervals, change the file '/etc/bluetooth/main.conf', variables: LEScanIntervalAutoConnect= LEScanWindowAutoConnect=. Value in ms.

Table of content

Getting Started

You can conveniently flash, update and configure the bluetooth thermometers remotely using a bluetooth connection and a modern web browser.

Flashing or Updating the Firmware (OTA)

To flash or update the firmware, use a Google Chrome, Microsoft Edge or Opera Browser.

  1. Go to the Over-the-air Webupdater Page TelinkMiFlasher.html *
  2. If using Android, Windows, Linux: Ensure you enabled "experimental web platform features". Therefore copy the according link (i.e. chrome://flags/#enable-experimental-web-platform-features for Chrome), open a new browser tab, paste the copied URL. Now sten the Experimental Web Platform features flag to Enabled. Then restart the browser.
  3. For all sensors with a button, before activation, it is necessary to reset the past bindings by holding the button for a long time.
  4. In the Telink Flasher Page: Press Connect: The browser should open a popup with visible Bluetooth devices. Choose the according target device (i.e. LYWSD03MMC) to pair.
  5. After connection is established a Do Acivation button appears. Press this button to start the decryption key process.
  6. Now you can press the Custom Firmware ver x.x button to directly flash the custom firmware. Alternatively you can choose a specific firmware binary (i.e. the original firmware) via the file chooser
  7. Press Start Flashing.
  • Use TelinkOTA to flash old or alternative versions (ATC1441). This is a program for OTA projects with Telink SDK, no third-party (mijia) protections.

  • Addition for CGG1-M: Press and hold the button on the back of CGG1-M for 2 seconds until the Bluetooth icon starts blinking on the e-ink display, and then click the 'Connect' and 'Do Activation' buttons on the TelinkMiFlasherl.

  • Addition for MJWSD05MMC: Press and hold both buttons for a few seconds until the screen blink (device resets). Next, briefly press the top side button, then briefly press the bottom button. The Bluetooth icon will start flashing. Next 'Connect' and 'Do Activation' in TelinkMiFlasher.

Configuration

After you have flashed the firmware, the device has changed it's bluetooth name to something like ATC_F02AED. Using the TelinkMiFlasher.html you have various configuration options.

General process:

  1. Press Connect
  2. Select the according device to connect/pair (i.e. ATC_F02AED)
  3. Several configuration options appear
  4. Choose Send Config to send changed value to the device. Or press Set default and then Send config to revert to the Defaults
Option Description
Temperature and Humidity offset Enter a value to correct the offset of the Temperature or Humidity displayed: For example -1.4 will decrease the Temperature by 1.4°
Smiley or Comfort Choose a static smiley or check the "Comfort" Radio box to change the smiley depending on current Temperature and Humidity.
Comfort Parameters Defines the Lower (Lo) and Upper (Hi) Range for Temperature and Humidity interpreted as comfort zone. In the default configuration a smiley will appear.
Advertising Type Type of supported Bluetooth Advertising Formats.
Set time sends the current time to the device
Comfort, Show batt, Clock Ticking the according boxes you can enable interval rotation between different LCD screens. See the example video below.
  • For SHTC3 in "lowPower" the accuracy is reduced.
  • For SHT4x in "lowPower" you get a delay for the polling period, but the accuracy remains.

Example of LCD display modes

You can configure different LCD Display modes using Comfort, Show batt and Clock configuration checkboxes. The enabled LCD Display Modes will appear one-by-one in a loop.

YoutubeVideo

Battery and clock display are enabled in the settings. The rest of the settings is kept default. The video contains 2 cycles.

  1. Temperature and humidity
  2. Temperature and % of battery
  3. Temperature and humidity
  4. Hours and minutes

Firmware

Firmware Binaries

You can directly update/flash the firmware without downloading the binaries below.

Custom Firmware Versions:

The download of the appropriate firmware for your device will be presented automatically in TelinkMiFlasher.html. Downloading files from this repository is not required.

Original Manufacturer Firmware Version

In case you want to go back to the original firmware, you can download them here:

Firmware version history

Version Changes
1.2 Bind, Set Pin-code, Support MHO-C401
1.3 Get/Set comfort parameters
1.4 Get/Set device name, Get/Set MAC
1.5 Add Standard Device Information Characteristics
1.6 Fix alternation of Advertising in mi mode
1.7 Authorization and encryption in permissions to access GAP ATT attributes, if pin code is enabled
1.8 Time display (instead of a blinking smile)
1.9 Recording measurements to flash memory (cyclic buffer for 20000 measurements)
2.0 Recording measurements with averaging to flash memory
2.1 Periodic display refresh for MHO-C401
'Erase mi-keys' option to return to original firmware
2.2 Added parameter "Encrypted Mi Beacon"
2.3 Added "Delete all records"
2.4 Added parameter "Clock time step"
2.5 Remove TRG/FLG errors, minor optimization
2.6 Expanding the ranges of threshold parameters (TRG)
2.7 Reducing power consumption of MHO-C401 (EDP update), adding version for CGG1-M 2020-2021
2.8 Added saving bindkey to EEP if mi-keys are erased, reduced TX power to 0 dB for defaults
2.9 Added additional id flags to advertising packages
3.0 Added toggle support for advertising package structures for third-party software
3.1 Fix security attributes (for pincode)
3.2 Added new encrypted beacon formats, reed switch maintenance
3.3 Added autodetection for LYWSD03MMC hardware versions B1.6 and B1.9. For CGG1-M and MHO-C401 - autodetection of SHTV3 or SHT4x sensors
3.4 Correct Hardware Version Setting for LYWSD03MMC B1.7
3.5 Correction of moisture readings for SHT4x sensors. Rounding off sensor values on display.. Saving HW string B2.0 on LYWSD03MMC. Eliminated battery voltage noise in CGG1-M. CGG1 - correction of the battery charge display. Added CGDK2 and modified (DIY) variant of CGDK2-2.
3.6 Additional parameters: Support BT5.0 PHY, Channel Selection Algorithm 2, Correct RF-TX Power in suspend
3.7 Added format 'HA BLE', reed switch operation mode: Switch and Count. Full support for "HA BLE" encryption. Speed correction I2C for LCD controller LYWSD03MMC HW:1.9. Support for CGG1-M hardware version 2022.
3.8 Fix clear_memo, renaming 'HA BLE' format to 'BTHome'
3.9 Changed the calculation of battery readings in %, optimization of consumption for the solar battery when the voltage drops below 2V (deep-sleep), added op