ble_monitor
ble_monitor copied to clipboard
[Bug]: Device names for BLE trackers are not persisted after HA Core restarts
What happened?
I have several BLE devices added by mac address with track device
enabled.
After they have been found, I rename the devices and their entities from their defaults. Following an HA Core restart, the renamed entity names persist, but the Device names revert to the default upper case mac address (colons removed):
This does not affect any iBeacon devices that I am also tracking, or specific devices such as a HHCCJCY01 plant monitor or LYWSD03MMC sensors.
There are no errors in the log and the devices are otherwise tracked without issue.
Sensor type
BLE Trackers
Relevant log output
No response
I've done a little bit of digging. Here is the device in core.device_registry
immediately after a device is given a new name of "Foo" in HA.
Note the value of name_by_user
:
{
"config_entries": [
"97cf05922d2ff31cb7b7cebc07974dcc"
],
"connections": [],
"identifiers": [
[
"ble_monitor",
"CC:98:8B:21:E6:13"
]
],
"manufacturer": null,
"model": null,
"name": "CC988B21E613",
"sw_version": null,
"hw_version": null,
"entry_type": null,
"id": "8cf36c8868bd4662bcb9975609760f5d",
"via_device_id": null,
"area_id": null,
"name_by_user": "Foo",
"disabled_by": null,
"configuration_url": null
}
The same device following an HA Core restart:
{
"config_entries": [
"97cf05922d2ff31cb7b7cebc07974dcc"
],
"connections": [],
"identifiers": [
[
"ble_monitor",
"CC:98:8B:21:E6:13"
]
],
"manufacturer": null,
"model": null,
"name": "CC988B21E613",
"sw_version": null,
"hw_version": null,
"entry_type": null,
"id": "8cf36c8868bd4662bcb9975609760f5d",
"via_device_id": null,
"area_id": null,
"name_by_user": null,
"disabled_by": null,
"configuration_url": null
}
Hopefully this helps debug the issue.
How did you configure BLE monitor, in the UI or in YAML?
And can you show me the debug logging, the FAQ explains how you can get this (chapter Debug).
Thanks for picking this up so quickly.
I have configured via UI.
As requested, debug logging enabled and restarted HA Core. Renamed a BLE Tracker device, no logs added. Initiated restart of HA Core, the following appeared in the log:
2022-04-08 20:02:55 DEBUG (SyncWorker_3) [custom_components.ble_monitor] Shutdown event fired: <Event homeassistant_stop[L]>
2022-04-08 20:02:55 DEBUG (SyncWorker_3) [custom_components.ble_monitor] HCIdump thread: joining
2022-04-08 20:02:55 DEBUG (Thread-3) [custom_components.ble_monitor] HCIdump thread: main event_loop stopped, finishing.
2022-04-08 20:02:55 DEBUG (Thread-3) [custom_components.ble_monitor] HCIdump thread: Run finished
2022-04-08 20:02:55 DEBUG (SyncWorker_3) [custom_components.ble_monitor] HCIdump thread: joined
2022-04-08 20:02:55 DEBUG (SyncWorker_3) [custom_components.ble_monitor] BLE monitor stopped
2022-04-08 20:02:56 DEBUG (MainThread) [custom_components.ble_monitor.binary_sensor] Entities updater loop stopped
2022-04-08 20:02:56 DEBUG (MainThread) [custom_components.ble_monitor.sensor] Entities updater loop stopped
2022-04-08 20:02:56 DEBUG (MainThread) [custom_components.ble_monitor.device_tracker] Entities updater loop stopped
After the reboot finished, there were no additional log items. Not sure if it's related, but after my first reboot, two of my BLE Tracked devices were missing and haven't yet reappeared, but when I go to re-add them via the UI, the mac addresses are already present (is this because they haven't been scanned yet?)
I've also noticed that during scanning, the last-changed
timestamp on BLE tracked devices always resets on each scan, regardless of whether the status has changed. Again, not sure if this is related.
I've noticed something interesting. As previously reported, the Entities themselves persist their rename. I recently deleted all of the tracked devices and after several days and several restarts, I readded one of the devices and noticed that the entity's name and icon has been persisted, even after it was deleted. Could this be related?
Sorry I didn’t got back to you, I totally forgot.
the mac addresses are already present (is this because they haven't been scanned yet?)
Yes, that is normal. The Mac addresses in the options is a “setting”. So they won’t disappear, unless you delete the Thevissen from the ble monitor options.
The last-changed timestamp on BLE tracked devices always resets on each scan
that is also as expected. We need the last time stamp to make sure it is still “at home”
name and icon has been persisted, even after it was deleted
that’s normal HA behavior. HA stores deleted items somewhere, if I remember correct, and will use this info if it is readded.
Thanks for the clarifications. Absolutely no need to apologise; we all really appreciate your efforts on this component!
Is there anything more that I can do to help diagnose the issue? Any devices marked as "track device" in the settings have their names reset to the mac access (without colons) after a reboot.
I will first try to replicate your issue this weekend. I’ll get back to you afterwards.
Thank you! Please let me know if there's anything I can do to help.
As an experiment, I just unchecked "track device" from one of my devices, then restarted. The device no longer appeared in the integration (as expected), but the device was still in the "devices" list of "Passive BLE Monitor options" in the integration configuration menu (it had remembered the device name!), but when I re-enabled the track device and submitted, the device was added back and lost its name (reverted to mac address)