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

Sensors not working when MAC address characters written in lower case #734

Closed
theliquid opened this issue Feb 20, 2022 · 9 comments
Closed
Labels
bug Something isn't working

Comments

@theliquid
Copy link

Hi,
I just discovered that my Xiaomi BLE sensors don't work, when I write the characters in the MAC address in the configuration.yaml file in lower case.
Since writing the MAC address in lower case is a common practice, this seems to be a bug.

@Ernst79
Copy link
Collaborator

Ernst79 commented Feb 20, 2022

Can confirm the bug. It’s also happening in the UI configuration. When I change the upper case MAC to a lower case MAC, It will create additional entities with _2 at the end in the unique ID (sensor name is lower case) but it won’t update these, it will keep on updating the old ones with the upper case names.

@Ernst79
Copy link
Collaborator

Ernst79 commented Feb 20, 2022

Hmm, if I add a new sensor with lower case MAC, is does seem to works OK. Looking further....

@Ernst79 Ernst79 added the bug Something isn't working label Feb 20, 2022
@Ernst79
Copy link
Collaborator

Ernst79 commented Feb 20, 2022

Now, I tried with YAML.

ble_monitor:
  hci_interface: 0
  bt_auto_restart: False
  active_scan: False
  discovery: False
  period: 60
  use_median: False
  decimals: 1
  log_spikes: False
  restore_state: False
  report_unknown: False
  devices:
    # sensor
    - mac: 'a4:c3:38:5d:18:b4'
      name: 'Livingroom'
      encryption_key: 'b9ea895fac7eea6d30532432a5123456'
      temperature_unit: C
      decimals: 2
      use_median: False
      restore_state: default

It's working fine.

image

Could you show me your configuration?

@Ernst79
Copy link
Collaborator

Ernst79 commented Feb 20, 2022

Ok, when I remove the sensor name from my YAML config, I see the issue. It seems to initially create the correct entities:

  • lower case sensor name: ble temperature a4c1388d18b2
  • entity_id: sensor.ble_temperature_a4c1388d18b2

Later on in the process, it creates a second entity of each sensor

  • upper case sensor name: ble temperature A4C1388D18B2
  • entity_id: sensor.ble_temperature_a4c1388d18b2_2 (note the added _2)

image

The last one is the one that is being updated with data.

@Ernst79
Copy link
Collaborator

Ernst79 commented Feb 20, 2022

I can see the same in the logs.

First with lower case letters

2022-02-20 20:04:50 DEBUG (MainThread) [custom_components.ble_monitor.sensor] async_added_to_hass called for ble temperature a4c1388d18b2
2022-02-20 20:04:50 DEBUG (MainThread) [custom_components.ble_monitor.sensor] async_added_to_hass called for ble humidity a4c1388d18b2
2022-02-20 20:04:50 DEBUG (MainThread) [custom_components.ble_monitor.sensor] async_added_to_hass called for ble battery a4c1388d18b2
2022-02-20 20:04:50 DEBUG (MainThread) [custom_components.ble_monitor.sensor] async_added_to_hass called for ble voltage a4c1388d18b2
2022-02-20 20:04:50 DEBUG (MainThread) [custom_components.ble_monitor.sensor] async_added_to_hass called for ble rssi a4c1388d18b2

and 5 seconds later with upper case letters

2022-02-20 20:04:55 DEBUG (MainThread) [custom_components.ble_monitor.sensor] async_added_to_hass called for ble temperature A4C1388D18B2
2022-02-20 20:04:55 DEBUG (MainThread) [custom_components.ble_monitor.sensor] async_added_to_hass called for ble humidity A4C1388D18B2
2022-02-20 20:04:55 DEBUG (MainThread) [custom_components.ble_monitor.sensor] async_added_to_hass called for ble battery A4C1388D18B2
2022-02-20 20:04:55 DEBUG (MainThread) [custom_components.ble_monitor.sensor] async_added_to_hass called for ble voltage A4C1388D18B2
2022-02-20 20:04:55 DEBUG (MainThread) [custom_components.ble_monitor.sensor] async_added_to_hass called for ble rssi A4C1388D18B2

@Ernst79
Copy link
Collaborator

Ernst79 commented Feb 20, 2022

I tried it a second, third and 4th time, and now it only adds the sensor with uppercase letters, with exactly the same config. Working fine.

Edit. Ok, it only goes wrong if the sensor is already added, and you remove the name. Steps to reproduce. First add a sensor with a name (e.g. Livingroom), Next, remove the line with name: "Livingroom" from YAML, and restart HA. After that, it will create the lowercase and uppercase sensors.

I'll look further tomorrow.

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

Ernst79 commented Feb 22, 2022

Fixed in beta version 7.9.0-beta. Could you check if it works for you?

@theliquid
Copy link
Author

Works for me with the beta version! Thanks!

@Ernst79 Ernst79 removed the fixed in beta This issue is fixed in the current beta release label Feb 26, 2022
@Ernst79
Copy link
Collaborator

Ernst79 commented Feb 26, 2022

Fixed as final in 7.9.2

@Ernst79 Ernst79 closed this as completed Feb 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants