小米体重秤通过ESP接入HASS | 您所在的位置:网站首页 › jojo体重秤 › 小米体重秤通过ESP接入HASS |
本帖最后由 yunsean 于 2021-5-15 09:02 编辑
注意,是小米体重秤,不是体脂秤。
描述:
本来esphome已经支持小米体重秤的接入,但是有两个问题:
第一个,搞不懂写这个代码的人是没有理解中国斤和公斤的换算关系还是其他原因,反正就是逻辑有问题,上原始代码原图:
WX20210511-195328.png (47.95 KB, 下载次数: 0) 下载附件 2021-5-11 19:54 上传 测试开始的时候一直感觉数据不对,看这个代码,没搞懂是要换算成公斤还是斤或者其他单位。 然后,就想办法修改他的代码,直接在系统环境中搜索xiaomi_miscale.cpp文件,找到位置: /usr/local/lib/python3.8/site-packages/esphome/components/xiaomi_miscale/xiaomi_miscale.cpp 打开修改之: ``` c++ // weight, 2 bytes, 16-bit unsigned integer, 1 kg const int16_t weight = (uint16_t(data[1]) | (uint16_t(data[2]) = 60 && id(weight_mi_scale).state = 20 && id(weight_mi_scale).state < 30) { return id(weight_baby).publish_state(x); } else { return id(weight_other).publish_state(x); } - platform: template name: Weight Dad id: weight_dad unit_of_measurement: 'kg' icon: mdi:weight-kilogram accuracy_decimals: 2 - platform: template name: Weight Baby id: weight_baby unit_of_measurement: 'kg' icon: mdi:weight-kilogram accuracy_decimals: 2后边的根据体重识别人,的方式,来自于xiaomi_scale组件,参考: https://esphome.io/components/sensor/xiaomi_miscale.html esphome很神奇!
|
CopyRight 2018-2019 实验室设备网 版权所有 |