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

CGPR1 motion sensor inconsistent battery report #559

Closed
Ernst79 opened this issue Nov 14, 2021 Discussed in #557 · 23 comments
Closed

CGPR1 motion sensor inconsistent battery report #559

Ernst79 opened this issue Nov 14, 2021 Discussed in #557 · 23 comments
Labels
bug Something isn't working fixed in beta This issue is fixed in the current beta release

Comments

@Ernst79
Copy link
Collaborator

Ernst79 commented Nov 14, 2021

Discussed in #557

Originally posted by hugalafutro November 13, 2021
Hi,
I've noticed that my CGPR1 motion sensor reports battery as such:
Screenshot 2021-11-13 100424
which sometimes triggered my automation to warn me battery in iot device is going low. I selected "use median" for the particular sensor in the integration options, but the graph still looks wonky.

Just wondering if others with this sensor see the same by any chance and could this be indicative of the actual battery being close to dying?

edit: larger history shows this repeats cyclically:
Screenshot 2021-11-13 100903

@Ernst79
Copy link
Collaborator Author

Ernst79 commented Nov 17, 2021

@hugalafutro Are you able to make some hci dumps. I want to check what the sensor is sending.

@hugalafutro
Copy link

I'm at work at the moment, but if you leave me steps how to obtain the dumps I'll get on it when I get back home (around 22:30).

@Ernst79
Copy link
Collaborator Author

Ernst79 commented Nov 17, 2021

You can run the following command.

sudo hcidump --raw hci > dump.txt

If you use HA Os, this won’t work., let me know if that is the case.

The above command will create a text file. Let it run for 15 minutes. You can upload it here.

@hugalafutro
Copy link

hugalafutro commented Nov 17, 2021

I made a ~15mins long hci dump for both hci0 and hci1 (as I have both checked in the integration options), where hci1 is the pi bt and hci0 is bt usb dongle, although sometimes after reboot or when one of the adapters "dies" and restarts it can be other way around.

hci1: Type: Primary Bus: UART
BD Address: B8:27:EB:84:76:27 ACL MTU: 1021:8 SCO MTU: 64:1
UP RUNNING
RX bytes:871932196 acl:0 sco:0 events:21768389 errors:0
TX bytes:515633 acl:0 sco:0 commands:82929 errors:0

hci0: Type: Primary Bus: USB
BD Address: 00:1A:7D:DA:71:11 ACL MTU: 310:10 SCO MTU: 64:8
UP RUNNING
RX bytes:526937404 acl:0 sco:0 events:13449790 errors:0
TX bytes:433721 acl:0 sco:0 commands:82984 errors:0

hci0: dump.txt
hci1: dump2.txt

edit: forgot to mention I run ha in docker with "host" network mode so I believe that shouldn't be an issue as ha os would be.

@Ernst79
Copy link
Collaborator Author

Ernst79 commented Nov 18, 2021

Could you also send me the encryption key. This sensor sends encrypted advertisements.

@hugalafutro
Copy link

Here's the encryption key: 231d39c1d7cc1ab1aee224cd096db932

@Ernst79
Copy link
Collaborator Author

Ernst79 commented Nov 19, 2021

Could you do me a favor, and change line 797-799 in ble_monitor/custom_components/ble_monitor/ble_parser/ and do a restart of HA. (line number is based on 6.0.1, if you are using the beta, its slighly higher).

from

            payload_start = next_start

    return result

to

            payload_start = next_start

    if device_type == "CGPR1":
        if "battery" in result:
            _LOGGER.error("Battery reading for CGPR1 Adv: %s", data.hex())

    return result

This will collect some better filtered data for debugging in your HA log (as error). Keep it running for a few hours and post the error messages here. You can remove the lines after you have the logs.

@hugalafutro
Copy link

I changed the line in xiaomi.py (was the only file that had the string in it), it is running now. It warned in HA log

home-assistant3  | /config/custom_components/ble_monitor/ble_parser/xiaomi.py:799: SyntaxWarning: "is" with a literal. Did you mean "=="?
home-assistant3  |   if device_type is "ATC":

I do not know python so I hope it's still gonna work. If it does I will post the output later.

@Ernst79
Copy link
Collaborator Author

Ernst79 commented Nov 20, 2021

I updated the code in my previous post, I should have used CGPR1 of course, not ATC. Also fixed the warning you get. Could you change the code and try again?

@hugalafutro
Copy link

I did the changes and it's now outputting lines like

2021-11-20 10:11:00 ERROR (Thread-3) [custom_components.ble_monitor.ble_parser.xiaomi] Battery reading for CGPR1 Adv: 191695fe5858830af9bd5d60342d5829e663daa300007264c84c

I will post later when there is more of them.

@Ernst79
Copy link
Collaborator Author

Ernst79 commented Nov 20, 2021

Yes, that’s what we need. Keep it running for a couple of hours.

@hugalafutro
Copy link

Got this so far, let me know if you need more

2021-11-20 10:11:00 ERROR (Thread-3) [custom_components.ble_monitor.ble_parser.xiaomi] Battery reading for CGPR1 Adv: 191695fe5858830af9bd5d60342d5829e663daa300007264c84c
2021-11-20 10:18:26 ERROR (Thread-3) [custom_components.ble_monitor.ble_parser.xiaomi] Battery reading for CGPR1 Adv: 191695fe5858830a00bd5d60342d58cc894c1da400006ee32380
2021-11-20 10:21:55 ERROR (Thread-3) [custom_components.ble_monitor.ble_parser.xiaomi] Battery reading for CGPR1 Adv: 191695fe5858830a0ebd5d60342d5858416f84a40000fa292a18
2021-11-20 10:32:50 ERROR (Thread-3) [custom_components.ble_monitor.ble_parser.xiaomi] Battery reading for CGPR1 Adv: 191695fe5858830a26bd5d60342d58f45fea52a4000093ff389e
2021-11-20 10:43:45 ERROR (Thread-3) [custom_components.ble_monitor.ble_parser.xiaomi] Battery reading for CGPR1 Adv: 191695fe5858830a47bd5d60342d5846415416a40000875116d8
2021-11-20 10:54:44 ERROR (Thread-3) [custom_components.ble_monitor.ble_parser.xiaomi] Battery reading for CGPR1 Adv: 191695fe5858830a90bd5d60342d58b72d44c1a40000f83fa04c
2021-11-20 11:05:38 ERROR (Thread-3) [custom_components.ble_monitor.ble_parser.xiaomi] Battery reading for CGPR1 Adv: 191695fe5858830aa4bd5d60342d58300c74aca4000075569fca
2021-11-20 11:16:32 ERROR (Thread-3) [custom_components.ble_monitor.ble_parser.xiaomi] Battery reading for CGPR1 Adv: 191695fe5858830ab6bd5d60342d5862f7d142a4000088f868e6
2021-11-20 11:18:25 ERROR (Thread-3) [custom_components.ble_monitor.ble_parser.xiaomi] Battery reading for CGPR1 Adv: 191695fe5858830ac9bd5d60342d58eb0ad26fa400005ea5f486
2021-11-20 11:27:28 ERROR (Thread-3) [custom_components.ble_monitor.ble_parser.xiaomi] Battery reading for CGPR1 Adv: 191695fe5858830ae6bd5d60342d58f8753f0ea40000001469ff
2021-11-20 11:38:22 ERROR (Thread-3) [custom_components.ble_monitor.ble_parser.xiaomi] Battery reading for CGPR1 Adv: 191695fe5858830afbbd5d60342d5831017a35a4000034bcd2d5
2021-11-20 11:49:16 ERROR (Thread-3) [custom_components.ble_monitor.ble_parser.xiaomi] Battery reading for CGPR1 Adv: 191695fe5858830a0fbd5d60342d58c3b88094a5000079c4b205
2021-11-20 12:00:10 ERROR (Thread-3) [custom_components.ble_monitor.ble_parser.xiaomi] Battery reading for CGPR1 Adv: 191695fe5858830a28bd5d60342d58e0f9ea9ba50000250276fc
2021-11-20 12:11:07 ERROR (Thread-3) [custom_components.ble_monitor.ble_parser.xiaomi] Battery reading for CGPR1 Adv: 191695fe5858830a7bbd5d60342d582eb92a4ba50000fdb01811
2021-11-20 12:18:25 ERROR (Thread-3) [custom_components.ble_monitor.ble_parser.xiaomi] Battery reading for CGPR1 Adv: 191695fe5858830a86bd5d60342d5872261c85a50000e166b911
2021-11-20 12:22:02 ERROR (Thread-3) [custom_components.ble_monitor.ble_parser.xiaomi] Battery reading for CGPR1 Adv: 191695fe5858830a99bd5d60342d58e4bf36e4a50000318d99bd
2021-11-20 12:33:00 ERROR (Thread-3) [custom_components.ble_monitor.ble_parser.xiaomi] Battery reading for CGPR1 Adv: 191695fe5858830ababd5d60342d582adb5475a50000c9940293
2021-11-20 12:43:56 ERROR (Thread-3) [custom_components.ble_monitor.ble_parser.xiaomi] Battery reading for CGPR1 Adv: 191695fe5858830af7bd5d60342d583ec07610a50000a947821b
2021-11-20 12:54:50 ERROR (Thread-3) [custom_components.ble_monitor.ble_parser.xiaomi] Battery reading for CGPR1 Adv: 191695fe5858830a0fbd5d60342d58c6b7b706a6000047a08628
2021-11-20 13:05:45 ERROR (Thread-3) [custom_components.ble_monitor.ble_parser.xiaomi] Battery reading for CGPR1 Adv: 191695fe5858830a25bd5d60342d5844033fefa60000a357bc9f

@Ernst79
Copy link
Collaborator Author

Ernst79 commented Nov 20, 2021

I analyzed the data. It is indeed sending these strange readings. As you can see, the 100% readings are send once every 11 minutes approx. The other "wrong" messages that increase by 1 and are send once an hour (at 18 minutes past the hour). But the strange thing is that in both payloads, the 0a10 object type is used (this is a definition of the MiBeacon protocol to indicate that it is a battery reading).

Line  Battery    Decrypted payload
1      100%      0a10 0164  
2      42%       0a10 012a
3      100%      0a10 0164
4      100%      0a10 0164
5      100%      0a10 0164
6      100%      0a10 0164
7      100%      0a10 0164
8      100%      0a10 0164
9      43%       0a10 012b
10     100%      0a10 0164
11     100%      0a10 0164
12     100%      0a10 0164
13     100%      0a10 0164
14     100%      0a10 0164
15     44%       0a10 012c
16     100%      0a10 0164
17     100%      0a10 0164
18     100%      0a10 0164
19     100%      0a10 0164
20     100%      0a10 0164

What I can do is applying a filter on the battery readings to ignore readings that deviate more than x%, but that would still record wrong readings that are close to 100% (e.g. if I set x = 10%, than all wrong advertisements between 90% and 99% are still taken into account.

@Ernst79
Copy link
Collaborator Author

Ernst79 commented Nov 20, 2021

I'm curious what MiHome is showing. could you check around 18 minutes after the hour, what Mi Home is showing? If it is also using this data, it would be showing the "wrong" value for about 3-4 minutes.

@hugalafutro
Copy link

The xiaomi home app doesn't show the battery info just a full battery icon like so: https://turbomrak.o5.ddns.net/s/5ftJ9L32rnzfriM Clicking on anything just shows empty data. This is honestly 2nd time ever I opened the app since I got the token. Perhaps it's because I use older version with the vevs modification to get the encryption token?

@Ernst79
Copy link
Collaborator Author

Ernst79 commented Nov 20, 2021

I have no idea, it looks like a firmware issue. Can you check if there is a firmware update?

@hugalafutro
Copy link

Says I have latest version 1.1.1_0228 when I try firmware update. I tried updating the app, but same result. I think your idea about just filtering the wrong readings out could work.

@Ernst79 Ernst79 added the bug Something isn't working label Nov 28, 2021
@pvvx
Copy link

pvvx commented Nov 29, 2021

In Qingping mode, everything is fine. I have not tested the change in battery readings. So far, only 100%.
image
image
FW v1.1.1_0228

@shift-del1
Copy link

I also have the same issue, however I have the sensor connected through Xiaomi Gateway 3 integration too, everything is normal:
Passive BLE
Screenshot_2022-02-17-18-34-50-604_io homeassistant companion android

XG3
Screenshot_2022-02-17-18-35-16-661_io homeassistant companion android

firmware
Screenshot_2022-02-17-18-47-22-823_com xiaomi smarthome

Everything is updated to the latest version (HAOS 7.4, Core 2022.2.8, Passive BLE 7.7.1).

@Ernst79
Copy link
Collaborator Author

Ernst79 commented Feb 25, 2022

I have (finally) created a fix. Please try by installing 7.9.2-beta. Sorry for the long wait.

Let me know if it fixes the issue.

@Ernst79 Ernst79 added the fixed in beta This issue is fixed in the current beta release label Feb 25, 2022
@hugalafutro
Copy link

I have installed the beta, will report if the graph stopped misbehaving later. Thanks for your work!

@hugalafutro
Copy link

happy to report all is well, thanks again.
image

@Ernst79
Copy link
Collaborator Author

Ernst79 commented Feb 26, 2022

Released as final in 7.9.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed in beta This issue is fixed in the current beta release
Projects
None yet
Development

No branches or pull requests

4 participants