pvvx / ATC_MiThermometer

Custom firmware for the Xiaomi Thermometers and Telink Flasher
https://github.com/pvvx/pvvx.github.io/tree/master/ATC_MiThermometer
Other
2.9k stars 202 forks source link

Request: Change number of digits #248

Closed Mopfus closed 1 year ago

Mopfus commented 2 years ago

Hello there. First of all, very nice work! For me and my HomeAssistant Setup it would be really handy, if it would be possible to change the number of digits that are send. So choosing between 0.01, 0.1 and 1 would be great! For my humidity, integers are fine. And for my temperature readings, 1 digit is enough. Thank you in advance :-)

Protoncek commented 2 years ago

Yes, i agree, that would be nice. However, i just created a separate sensors in HA and you're done:

- platform: template
   sensors:
    room_temperature_bthome:
      friendly_name: Room temperature
      unique_id: ani_temperatura_bthome
      value_template: "{{states('sensor.room_7d93_temperature')| round(1)}}"
      unit_of_measurement: "°C"
      device_class: temperature

    room_humidity_bthome:
      friendly_name: Room humidity
      unique_id: ani_vlaga_bthome
      value_template: "{{states('sensor.room_7d93_humidity')| round(0)}}"
      unit_of_measurement: "%"
      device_class: humidity
Mopfus commented 2 years ago

Thats a good workaround. Thank you very much.

But as I have around 20 Sensors here, I would need 40 templates just to cancel out information, that is not really necessary or useful.

For me this many digits are just "data-trash" that are send around where it is not necessary. They also suggest an accuracy of my $4 sensor that is far from being achieved.

pvvx commented 2 years ago

The number of displayed digits is specified in the integration settings used in Home Assistant. Example, description for integration with a passive BLE monitor: https://custom-components.github.io/ble_monitor/configuration_params#decimals

Mopfus commented 2 years ago

The number of displayed digits is specified in the integration settings used in Home Assistant. Example, description for integration with a passive BLE monitor: https://custom-components.github.io/ble_monitor/configuration_params#decimals

Ah cool. I was not aware of that. Thank you for that! Sadly this is not possible with BTHome (which is available since HA 9.0). BTHome is per default on HA 9.0, which makes it super easy and flawless for using ATCs.

And still. More digits are extra information, that is not really necessary to send around in my opinion. But I also don't know how complicated it is, to implement the option of chose the numbers of digits.

pvvx commented 2 years ago

With limited accuracy and data coarsening, instead of a smooth normal graph, we get squares. The sensors used in the thermometer give a relative accuracy better than 0.1% of full scale. To more quickly determine the change - increase or decrease, even more accurate data is required than a difference of 0.01 from units of degrees or humidity. Used to maintain temperature and humidity. Especially with PID control.

For example, I am not satisfied with such temperature maintenance. image

I wish there were even less fluctuations. But due to the limitation of 0.01 degrees and the inertia of the heater, it is impossible to get a more linear temperature in my warehouse in the country. Although the sensor parameters allow this.

pvvx commented 2 years ago

Sadly this is not possible with BTHome (which is available since HA 9.0). BTHome is per default on HA 9.0, which makes it super easy and flawless for using ATCs.

Displaying data in the required format is not solved by coarsening the data from the sensor. Most programs use averaging of data over a period. With sensor data +20 +19 +20 the display total can be +19.66666... C

I don't use BTHome because my practice of working with him showed that this is the worst decision. Too many data drops and freezes due to the use of ESP chips that are not designed to fully work with TCP protocols. It uses truncated protocols that do not meet the general specifications and the chip architecture is heavily overloaded, which leads to numerous failures. Moreover, such a system is not adapted and is not suitable for autonomous power supply. Those. in case of failure of the external supply of energy, everything goes out of order.

The use of one antenna in ESP for Wifi and BLE leads to the loss of a large amount of information and the limitation of such a system is something like supporting no more than a pair of BLE sensors. As a result, working with BTHome turns into a game with Tamagotchi.

Mopfus commented 2 years ago

Okay, thank you for this good explanations and thoughts. I agree that "squares" for a temperature is not nice. For my use case they are not a problem.

Averaging over a period is of cause a good way to get more accurate values. And yes, then you could get a lot more digits.

Thats new to me, that BTHome is not working good. I just learned that it exists some days ago when they celebrated 9 years of HA (https://www.home-assistant.io/blog/2022/09/07/release-20229/). In the video they claimed, that it works well and you can use ESP32 as proxy to expand the range of your host-system. Sounds for me pretty neat and useful. I have more than 10 Sensors around and using BLE at the moment. But I wanted to switch to BTHome. So maybe I should rethink that.

I understand that the "filtering" of digits should be done on the host system. "Bluetooth Low Energy Monitor" has the possibility to directly throw away one digit. Nevertheless, the "BTHome" AddOn in HA will not get this feature, as can be read here: https://github.com/home-assistant/home-assistant.io/issues/24089#issuecomment-1243032200

Protoncek commented 2 years ago

Thats new to me, that BTHome is not working good. I just learned that it exists some days ago when they celebrated 9 years of HA (https://www.home-assistant.io/blog/2022/09/07/release-20229/). In the video they claimed, that it works well and you can use ESP32 as proxy to expand the range of your host-system. Sounds for me pretty neat and useful. I have more than 10 Sensors around and using BLE at the moment. But I wanted to switch to BTHome. So maybe I should rethink that

Hm... i have 8 xiaomi's with pvvx FW via this new BTHome. I use one BT USB adapter and two ESP proxies. All works excellent. No drop-outs, quite ok temp readings, good signal strength. Before that i've had two ESP32 on ESPHome as BLE receivers - those also worked great, but this BLE proxy is even better - more flexible, since you don't have to decide which BT receiver will receive certain thermometer - system makes this decision based on signal strength. But, i don't request two digits precision, i take these readings more as "info" than laboratory measurement (which temp to two digits is, to be honest).

BTW...you can test new BThome system together with your old "system", if you have atc or pvvx FW on your xiaomi's. Only bad thing is that with atc or pvvx FW auto-discovery doesn't work in HA, you must add BTHome receiver (xiaomi) manually. This way you'll have two sets of entities (your existing and new BTHome) for each device and you'll be able to compare and see if works for you.

pvvx commented 2 years ago

BTHome used to have a dual antenna solution, but it was built on a legacy ESP8266 module and BT via "AT". And I don't see any new WiFi6 and BT5+ compatible implementations. But the modules have been around for a long time. Example ESPxxx (but no WiFi6): image

AythamiEsp commented 1 year ago

So, what's the best way to change the digits to 0,1 accuracy? Or maybe the values could be rounded to 0,1x degrees C ; where x is 0 or 5. (to reduce squaring)

pvvx commented 1 year ago

Value in 0.01. 1234 -> 12.34 Integer division: (Value_x01 + 5)/10 = Value_x1