Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MiScale 1 doesn't report Lbs #28

Closed
sgillf opened this issue Aug 21, 2020 · 22 comments
Closed

MiScale 1 doesn't report Lbs #28

sgillf opened this issue Aug 21, 2020 · 22 comments

Comments

@sgillf
Copy link

sgillf commented Aug 21, 2020

Describe the bug
MiScale 1 does not deliver mqtt messaging to Home Assistant when LBS are selected as the designated unit

To Reproduce
Move the slider on the mi scale 1 to the far left, so that it shows the weight as lbs. It will then no longer report the resulting weight to Home Assistant

Expected behaviour
The weight indicated on the scale would be reported in the MQTT message sent to the MQTT broker.

Screenshots

Drawing1

Scale (please complete the following information):

  • Xiaomi Mi Scale
  • Model # xmtzco1hm

Desktop/Server (please complete the following information):

  • The bug occured with a RB3b+ and hassio

Additional context

  • I have had the experience both on Hassio on RP3b and on ubuntu running HA supervised. On built-in bluetooth on the RP3 and on a dongle for Ubuntu
@lolouk44
Copy link
Owner

Thanks I'm on holiday at the moment so limited time available. Can you confirm how you run the script?
It would really help if you could use the issue template

@sgillf
Copy link
Author

sgillf commented Aug 23, 2020

I just updated the post to the issue template - Sorry about that, it's actually my first time every reporting a bug on github

Enjoy your holiday!

When I get the BLE dongle in, I'll take some screen shots of the KG reporting, the JIN, reporting, and then the LBS not reporting.

Thanks!

@lolouk44
Copy link
Owner

do you get any error messages when the slider is set to Lbs?
How are you running the script? Via an HA Add-On? Docker Container? or Manually?
Are you able to run scripts manually? I would need to get some custom debug logging

@sgillf
Copy link
Author

sgillf commented Aug 27, 2020

HI - No error messages are received when the slider is on lbs

The script is running via HA Add-on.

For sure I can run some scripts. Let me know which logs you'd like to see, and I can get them

Here's some of the bluetooth scan logs
KG:
mi scale KG

LBS:
mi scale LB

@lolouk44
Copy link
Owner

great stuff.
I need to see the data received by the scale.
Can you try and run the script for each setting and give me the info pls?
Xiaomi_Scale_Debug.zip

@sgillf
Copy link
Author

sgillf commented Aug 27, 2020

Glad it helps!

Here's the output to the script you gave. I had to remove the time.sleep(1) variable because it wasn't defined

Debug Output

@lolouk44
Copy link
Owner

something doesn't add up. Just checked the data you sent, and I can clearly see 92Kg on one side, and 203 Lbs on the other side:

# uncomment the data you want to test
#data = '1d18a2e047e4070815021928' #kg
#data = '1d1803064fe4070815021a20' #lbs
measunit = data[4:6]
measured = int((data[8:10] + data[6:8]), 16) * 0.01
unit = ''
if measunit.startswith(('03', 'b3')): unit = 'lbs'
if measunit.startswith(('12', 'b2')): unit = 'jin'
if measunit.startswith(('22', 'a2')): unit = 'kg' ; measured = measured / 2
print("weight: %s %s" % (round(measured, 2), unit))

Are you sure nothing is posted on MQTT? Have you tried something like MQTT explorer to confirm nothing is published?
Can you also share your HA sensor config please?

@sgillf
Copy link
Author

sgillf commented Aug 29, 2020

When I listen in on MQTT, only the KG messages show up:

mqtt listening

Here's the sensor config:

name: "Simran MiScale Weight"
state_topic: "miScale/Simran/weight"
value_template: "{{ value_json['Weight'] }}"
unit_of_measurement: "lbs"
json_attributes_topic: "miScale/Simran/weight"
icon: mdi:scale-bathroom    

Also...I was able to get the error message:

error message weight

This happened after switching to Lbs from KGs

Anything else I should provide?

@lolouk44
Copy link
Owner

I'm not sure what's going on.
Can you please try this custom add on and tell me what you get when you measure in Lbs?
you need to unzip and save under the addons folder on your Pi
Then install it via the supervisor (you probably will need to remove my "official" add on and instead install the one under local add-ons
xiaomi_mi_scale.zip
I need to see the calculated measure unit and raw weights to see what's happening pls

@sgillf
Copy link
Author

sgillf commented Aug 31, 2020

Yeah, it's pretty weird!

The last two lines are from when Lbs are selected. It looks like its measured, but it doesn't publish anything. and the measuring unit shows up as a3
output

@sgillf
Copy link
Author

sgillf commented Aug 31, 2020

It looks like its stuck in a loop - it keeps measuring without going to publish (Note that no new measurement was taken on the scale)
image

@lolouk44
Copy link
Owner

lolouk44 commented Sep 1, 2020

Thanks. Can you try this updated add-on and confirm whether it works pls?
xiaomi_mi_scale.zip

@sgillf
Copy link
Author

sgillf commented Sep 1, 2020

NP - Now it works find as long the weight is under 200lbs

Here it is working, and reporting 71.60 lbs:

working find under

Here it is with the error message whenever it goes over 200lbs:

Second version

@sgillf
Copy link
Author

sgillf commented Sep 1, 2020

It also looks like it keeps on measuring perpetually, despite no new measurements on the scale:

image

@lolouk44
Copy link
Owner

lolouk44 commented Sep 1, 2020

It also looks like it keeps on measuring perpetually, despite no new measurements on the scale:

Thanks, that's what it does indeed, but it is published on MQTT only when the weight changes. you have a special version that logs all loops so I could understand what was failing.

Here it is with the error message whenever it goes over 200lbs:

thanks I'd completely overlooked non Kg units for the body metrics. I've made a small adjustment which should cater for it.
Mind trying again pls?
the BMI, Basal Metabolism and Visceral Fat should also be more accurate
xiaomi_mi_scale.zip

@sgillf
Copy link
Author

sgillf commented Sep 1, 2020

Thanks -

Just tried it out... Looks good, except that its publishing the data to MQTT as KG rather than LBS. It's been converted:
image

@lolouk44
Copy link
Owner

lolouk44 commented Sep 2, 2020

Thanks for being my own personal Guinea pig 👍
I've made a change and we should now be ok 🤞
The change also includes an improvement of the BT handling, but that should be transparent since you're not experiencing connection issues.
Hopefully we're good to go after this one and I can publish an updated version of the add-on...
xiaomi_mi_scale.zip

@sgillf
Copy link
Author

sgillf commented Sep 2, 2020

No Problems - Glad to be able to help with it!

One thing more... the MQTT data is malformed when Lbs are used:

{"Weight":"206.80""Weight Unit":"lbs","BMI":"28.63","Basal Metabolism":"1787.75","Visceral Fat":"21.39","TimeStamp":"2020-09-02-12:06:17"}

Its missing a comma between the weight and the weight unit. Other than that, I think it's all good!

@lolouk44
Copy link
Owner

lolouk44 commented Sep 2, 2020

yes thanks. Forgot to update the file after noticing.
xiaomi_mi_scale.zip

If that's ok with you I'll close this issue now.

@sgillf
Copy link
Author

sgillf commented Sep 3, 2020

Sweet! It all looks good

@sgillf sgillf closed this as completed Sep 3, 2020
@sgillf
Copy link
Author

sgillf commented Sep 3, 2020

A couple of small items, while you're doing the update

The MQTT topic that you publish when using Lbs has the "S" as a lower case in "MiScale"
state_topic: "miscale/USERNAME/weight"
The config sample you have, and I think KG also has it as a Upper case

The User weight limits are still functioning in KG - which I think is fine, but might be worth mentioning in the readme

@lolouk44
Copy link
Owner

lolouk44 commented Sep 3, 2020

Thanks for your comments.

The MQTT topic that you publish when using Lbs has the "S" as a lower case in "MiScale"
state_topic: "miscale/USERNAME/weight"

There was a typo difference indeed between the discovery and the manual entry, especially when left blank. I've just checked the code again and there is no hard coded miScale. I have however updated the README example for consistency

The User weight limits are still functioning in KG - which I think is fine, but might be worth mentioning in the readme

Thanks. I've already updated the README

I've also added the weight unit as an attribute as I was originally hoping it would be possible to use a template to set the unit_of_measurement , which is not the case... Ah well I'll still leave it as it's good to have for potential troubleshooting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants