Xiaomi ATC-Sensor via ESPhome does not update if value not changes (but I want force this update)

Hi there,

I have several Xiaomi Mijia ATCs that measure Temperature and Humidity ( LYWSD03MMC). I flashed them with the costume firmware, but still use the ‘Mi like’ option.
One week ago I had implemented them directly with “Bluetooth Low Energy Monitor”. Since there I got some problems with the signal for some sensors, I implemented them via an ESP32 and ESPhome.
With the BLE integration the values got updated regularly (approx every 10min), even if the values are not changing. I used this for example to calculate the temperature-trend for the last 30 minutes.
Now via ESPhome it is not updating the sensor in HA, if the value is not changing. So if for example the temperature was not changing for 1h, my temperature-trend runs into problems. I know/think this is wanted, so that HA is not crowded with useless data.

What I want is, that every time the Xiaomi-sensor pushes a value to the ESP, and the ESP gives this to HA, that HA is updating the data, even if it is still the same value.

Minimal Config for the ESP32:

#...

esp32_ble_tracker:

#...

   - platform: xiaomi_lywsd03mmc
    mac_address: A4:C1:38:??:??:??
    bindkey: "???????"
    temperature:
      name: "ATC4 Temperature"
    humidity:
      name: "ATC4 Humidity"
    battery_level:
      name: "ATC4 Battery Level"

In HA the esphome-entities are automatically generated from the info, that HA gets from the ESPhome. The example is named there: sensor.atc4_temperature.

Here some logs from the ESP while running. The second block repeats every minute or so. So I think this means that esphome pushes the data to HA. Probably HA is not writing the data again, if it receives the same value.

[18:14:42][C][xiaomi_lywsd03mmc:012]: Xiaomi LYWSD03MMC
[18:14:42][C][xiaomi_lywsd03mmc:013]:   Bindkey: ????
[18:14:42][C][xiaomi_lywsd03mmc:014]:   Temperature 'ATC4 Temperature'
[18:14:42][C][xiaomi_lywsd03mmc:014]:     Device Class: 'temperature'
[18:14:42][C][xiaomi_lywsd03mmc:014]:     State Class: 'measurement'
[18:14:42][C][xiaomi_lywsd03mmc:014]:     Unit of Measurement: '°C'
[18:14:42][C][xiaomi_lywsd03mmc:014]:     Accuracy Decimals: 1
[18:14:42][C][xiaomi_lywsd03mmc:015]:   Humidity 'ATC4 Humidity'
[18:14:42][C][xiaomi_lywsd03mmc:015]:     Device Class: 'humidity'
[18:14:42][C][xiaomi_lywsd03mmc:015]:     State Class: 'measurement'
[18:14:42][C][xiaomi_lywsd03mmc:015]:     Unit of Measurement: '%'
[18:14:42][C][xiaomi_lywsd03mmc:015]:     Accuracy Decimals: 0
[18:14:42][C][xiaomi_lywsd03mmc:016]:   Battery Level 'ATC4 Battery Level'
[18:14:42][C][xiaomi_lywsd03mmc:016]:     Device Class: 'battery'
[18:14:42][C][xiaomi_lywsd03mmc:016]:     State Class: 'measurement'
[18:14:42][C][xiaomi_lywsd03mmc:016]:     Unit of Measurement: '%'
[18:14:42][C][xiaomi_lywsd03mmc:016]:     Accuracy Decimals: 0
...
[18:15:41][D][xiaomi_ble:314]: Got Xiaomi LYWSD03MMC (A4:C1:38:??:??:??):
[18:15:41][D][xiaomi_ble:317]:   Temperature: 26.2°C
[18:15:41][D][xiaomi_ble:320]:   Humidity: 56.0%
[18:15:41][D][sensor:125]: 'ATC4 Temperature': Sending state 26.20000 °C with 1 decimals of accuracy
[18:15:41][D][sensor:125]: 'ATC4 Humidity': Sending state 56.00000 % with 0 decimals of accuracy
...

Here an example screenshot, the sensor ATC4 was for 2h on the same temperature, while the ATC5 changed 7min ago. The log is from this period where ATC4 was at 26.2°C. It actually shows the last time changed, but I want the last time updated. I used this option in the lovelace (code below screenshot).
ATC4

  - entity: sensor.atc4_temperature
    secondary_info: last-updated
  - entity: sensor.atc5_temperature
    secondary_info: last-updated

I am looking around to solve this for one week now. The force_update option seems promising (Sensor Component — ESPHome), but is not working for me. Maybe I also doing it wrong. I tried to add this option to the config for the sensor in ESPhome, so like in the code below. This gives an error. So either this option is not available for the platform, or I am using this option wrong. My code in esphome was the following:

   - platform: xiaomi_lywsd03mmc
    mac_address: A4:C1:38:??:??:??
    bindkey: "???????"
    temperature:
      name: "ATC4 Temperature"
    humidity:
      name: "ATC4 Humidity"
    battery_level:
      name: "ATC4 Battery Level"
    force_update: true

One workaround could be, that I am using a Template Sensor, that grabs every 10 minutes or so the value from the esp-sensor. But this would mean a duplicate sensor, which I don’t like (I have 10 of these Thermometers, and all make 3 sensors, …). So hopefully there is another option.

I found this thread (Add force_update support to template sensor) also very promising, but as I am not using a template sensor and as I am not using MQTT, this could not solve my problem.

Hopefully you can follow my problem. If you need more info, feel free to ask. Somehow I have the feeling that the solution should be very easy, and I am overseeing something. Therefore I would be happy, for some tips and hints.
Thank you very much in advance!
:slight_smile:

Greetings,
Balcony

add following in esphome

force_update: true

it might solve the problem

for quicker replies try esphome discord.

I tried it, as you can see above in my code. Or did I past force_update at the wrong place?

I tried several possibilities. But none of them are working. All resulting in an error like: [force_update] is an invalid option for [...]

esphome:
  name: esp32test
  platform: ESP32
  board: esp32dev
  force_update: true

force_update: true

...

esp32_ble_tracker:
  force_update: true


sensor:

  - platform: xiaomi_lywsd03mmc
    mac_address: A4:C1:38:??:??:??
    bindkey: "xxx"
    temperature:
      name: "ATC4 Temperature"
    humidity:
      name: "ATC4 Humidity"
    battery_level:
      name: "ATC4 Battery Level"
    force_update: true

same issue discussed

1 Like

here is your answer

we were placing it in the wrong place. Humidity, Temperature and battery are 3 individual sensors. each with its own attributes.

sensor:
  - platform: xiaomi_lywsd03mmc
    mac_address: "xxxxxxxx"
    bindkey: "xxxxxxxxxxxxxxxxx"
    temperature:
      name: "Room Temperature"
      id: room_temperature
      force_update: "true"   
    humidity:
      name: "room Humidity"
      id: room_humidity 
    battery_level:
      name: "room Battery Level"
1 Like

Oh boy. I must have had tomatoes in my eyes. It is so obvious. :woman_facepalming:
Thank you very very much for this answer!!! :slightly_smiling_face:

Noob question. What’s “ATC” mean?