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

USB dongle issue, no more data #345

Closed
vini59fr opened this issue May 13, 2021 · 34 comments
Closed

USB dongle issue, no more data #345

vini59fr opened this issue May 13, 2021 · 34 comments
Labels
bug Something isn't working

Comments

@vini59fr
Copy link

Hi there

I have an issue since I use a USB dongle and I don't where it comes :(
config : HassOS uptodate + Pi4 + USB BT dongle (Trendnet TBW-106UB)

The BLE integration stop receiving datas frequently
2021-05-05 14_12_28-Aperçu - Home Assistant

I checked the bluetoothctl and it appears to be "power off" by itself. I can power it on, but it goes off again after a couple of minutes/hours
2021-05-05 13_45_47-Terminal - Home Assistant

I really don't know where to find a solution :(

@vini59fr vini59fr changed the title USB dongle power off, no more data USB dongle issue, no more data May 13, 2021
@sakislad
Copy link

Same problem here, with Pi4 and Belkin USB Dongle, a workarround is to just enable official BT Xiaomi Sensors (in parallel operation) on HA, this way Passive BLE addon keep working all day long.

@vini59fr
Copy link
Author

Same problem here, with Pi4 and Belkin USB Dongle, a workarround is to just enable official BT Xiaomi Sensors (in parallel operation) on HA, this way Passive BLE addon keep working all day long.

do you have a link ?
I don't only have temperature sensors, but plants sensors too

Thank's for help :)

@Ernst79
Copy link
Collaborator

Ernst79 commented May 13, 2021

@sakislad means this component

If you google for the issue of Bluetooth being powered down, there are numerous similar problems.

It might be possible to build in routine that checks the power state after not receiving updates for a while and power up the dongle, but I'll have to look into that.

@vini59fr
Copy link
Author

vini59fr commented May 13, 2021

I'm looking for a solution since I had my dongle and didn't find anything :(

I just add a "mitemp_bt" sensor. I hope this will work :)

@borpin
Copy link

borpin commented May 13, 2021

I had this too. I think it is a bug in the kernel used on the Pi. I gave up and coughed up for a Blue and I have had no issues since (but can only get one dongle to work at a time).

@vini59fr
Copy link
Author

Still the same issue with a mitemp_bt sensor configured :( :(

sensor:

  • platform: mitemp_bt
    mac: 58:2D:34:37:81:AD

image

@sakislad
Copy link

I use this addon with success for a while in docker on Ubuntu vm on qnap Nas. 3 weeks ago I have migrated on o Raspberry pi4 using the same adapter, running stable for 2 weeks. On 3rd week this situation comes up and I decided to give mitemp_bt a try but I didn't uninstalled the passive ble addon and I have them running in parallel with success.
If I uninstall the mitemp_bt sensors from configuration the problem rises again...

@vini59fr
Copy link
Author

I use this addon with success for a while in docker on Ubuntu vm on qnap Nas. 3 weeks ago I have migrated on o Raspberry pi4 using the same adapter, running stable for 2 weeks. On 3rd week this situation comes up and I decided to give mitemp_bt a try but I didn't uninstalled the passive ble addon and I have them running in parallel with success.
If I uninstall the mitemp_bt sensors from configuration the problem rises again...

Could you show me your mitemp_bt lines in your configuration.yaml ?

I added it and tried with the "bluetooth_le_tracker" ... my dongle still going off, more and more frequently :( :( :( :(

@sakislad
Copy link

I use this addon with success for a while in docker on Ubuntu vm on qnap Nas. 3 weeks ago I have migrated on o Raspberry pi4 using the same adapter, running stable for 2 weeks. On 3rd week this situation comes up and I decided to give mitemp_bt a try but I didn't uninstalled the passive ble addon and I have them running in parallel with success.
If I uninstall the mitemp_bt sensors from configuration the problem rises again...

Could you show me your mitemp_bt lines in your configuration.yaml ?

I added it and tried with the "bluetooth_le_tracker" ... my dongle still going off, more and more frequently :( :( :( :(

  • platform: mitemp_bt
    mac: "4B:65:A6:DE:78:AF"
    name: Living Room
    force_update: true
    median: 1
    timeout: 15
    retries: 1
    adapter: hci0 -- this is my external Bluetooth as default...
    cache_value: 300
    monitored_conditions:
    • temperature
    • humidity
    • battery

@sakislad
Copy link

Bluetooth has so many problems in rpi4, I want to replace the sensors with zigbee ones!
Basically I want to replace those sensors and my 3 xiaomi cameras and go with sonoff...

@sakislad
Copy link

I'm trying another workaround...
Tried to power off and on the Bluetooth controller, once stopped working and that worked.
So I create an automation that every 15 minutes runs two shell commands, first: Bluetoothctl power off and next: Bluetooth CTL power on....
I thing this is a very good workaround for me as I don't use the Bluetooth controller for anything else and I thing it will work. At least in my tests it did.

@Ernst79
Copy link
Collaborator

Ernst79 commented May 24, 2021

I think that is a good workaround. Perhaps it would even be possible to do a check on the status of Bluetooth, and if down, power on Bluetooth.? Can you share your script?

@vini59fr
Copy link
Author

Could be a good news, thanks for your help

@sakislad
Copy link

sakislad commented May 24, 2021

In configuration.yaml i put those shell_commands:
shell_command:
turn_bluetooth_off: 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i /config/.ssh/id_rsa root@127.0.0.1 sudo bluetoothctl power off'
turn_bluetooth_on: 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i /config/.ssh/id_rsa root@127.0.0.1 sudo bluetoothctl power on'

Then I prepare the ssh login without password...
see this topic for help: https://community.home-assistant.io/t/hass-io-shell-command-error/36312/15

And finally create an automation to run the shell commands every 15 minutes:
**
alias: Restart Bluetooth
description: ''
trigger:

  • platform: time_pattern
    minutes: /15
    condition: []
    action:
  • service: shell_command.turn_bluetooth_off
  • service: shell_command.turn_bluetooth_on
    mode: single
    **

The trick works, bluetooth was down in 7:00am and the automation bring it back after 15 minutes!

@vini59fr
Copy link
Author

@sakislad

I did all you said

1st : the shell commands seems to be good. But nothing happen when I triggered them, on Dev Tools, services

2nd : I follow the topic, but don't know if it's good or not :(

3rd : error on the automation creation

@sakislad
Copy link

sakislad commented May 24, 2021

What happens if you run the commands from ssh; is the Bluetooth powering off with the first command only;

I use the community ssh add-on, not the official and I have enabled something on my dad level which I don't remember... I'll check and respond soon...

@vini59fr
Copy link
Author

the commands works fine but ask the root/admin password

So, my problem is the 2nd part. Have to check that

@vini59fr
Copy link
Author

2021-05-24 19_53_20-config ssh_id_rsa

2021-05-24 19_53_32-config ssh_id_rsa

@sakislad
Copy link

sakislad commented May 24, 2021

you save the key on /root/.ssh/id_rsa you have to edit the two shell commands and put this path instead of /config/.ssh/id_rsa or copy the files to /config/.ssh/

@vini59fr
Copy link
Author

I missed the path on the 2nd part. Now this part seems good

2021-05-25 09_52_02-Window

But it still ask me the root password :(
image

@sakislad
Copy link

@vini59fr
Copy link
Author

At least, everything works fine :) Thank you @sakislad

Just a question, on your automation, why don't you just use a "power on" ?
if it's off -> it will be on
if it's on -> nothing happen

@sakislad
Copy link

sakislad commented May 25, 2021

I just think that this way I make a full refresh of Bluetooth state.
Im not sure that in my case bluetooth is off when the communication stops...
We can try this way to see the results...
The problem of bluetooth range remains to be solved, i think i need a bigger extension cable...
Happy that works for you too!

@sakislad
Copy link

After 3 days working great, bluetooth adapter disappeared from the system and the script doesnt work anymore until physical disconnect of the adapter.

@Ernst79
Copy link
Collaborator

Ernst79 commented May 28, 2021

Isn't this some kind of hardware failure? Or perhaps firmware issue?

@vini59fr
Copy link
Author

After 3 days working great, bluetooth adapter disappeared from the system and the script doesnt work anymore until physical disconnect of the adapter.

damn, bad news for you ... still working fine for me, actually

@sakislad
Copy link

I think this was a hardware failure, but the overall problem i think is kernel problem. I will go Debian Supervised to see how it goes...

@sakislad
Copy link

same problem on Debian 10 (+ 1-2 more problems that needs to be solved) reverting to Home Assistant OS for now...

@vini59fr
Copy link
Author

Strange.... Maybe à dongle issue

@vini59fr
Copy link
Author

vini59fr commented Jun 7, 2021

Hello.

Today, my dongle stay off (first time off since I use the @sakislad feature)
I checked the terminal and have this loop message :( (1900 lines actually)
Don't know what it mean and how to fix it

I had to disconnect my dongle to get terminal access again

any ideas ?

image

@sakislad
Copy link

sakislad commented Jun 9, 2021

I sold the 3 sensors and also one Bed side lamp V1 that i have for 2 years and moving away from Xiaomi as they start to lock products to Xiaomi ecosystem, so i will not use the ble monitor integration anymore. I will go for zigbee temp & humidity sensors...

@Ernst79
Copy link
Collaborator

Ernst79 commented Jun 9, 2021

@vini59fr Enter pass key is normally for pairing to other Bluetooth devices. No idea why you got this message, BLE monitor isn’t pairing to anything at all, must be something else

@Ernst79
Copy link
Collaborator

Ernst79 commented Jun 12, 2021

There have been some Bluetooth firmware updates in HAos for multiple devices, including raspberry Pi, but also others, please try updating to HAos 6 and let me know if this solves it or not.

@Magalex2x14
Copy link
Collaborator

Magalex2x14 commented Jul 28, 2021

I will share my experience of dealing with a similar problem (this message suggests that my assumptions may be close to the truth).

I also started with a script that reboots the Bluetooth module. My solution was as follows:

  1. a script shell command in HomeAssistant that created an empty text file in a specific folder;
  2. a binary sensor that became true if none of my Bluetooth sensors received an update within a few minutes;
  3. automation that executed the script from point 1 when the sensor from point 2 was triggered;
  4. a shell script, executed every minute as a cron job, which checked for the presence of the file created by the script from point 1, and, if present, restarts the Bluetooth module reloads bt_usb kernel module and deletes this empty file-flag.

If my memory serves me, then somewhere I have already described this solution and provided the code of all the scripts - I will try to find it. UPDATE: found it

After a while, I abandoned this solution in favour of another, based on the assumption that the problem with my Bluetooth module manifested itself as a result of some kind of suspicious ("probing") activity of a neighbour's smartphone - after a while I noticed a corresponding pattern...
The essence of the method that has been working for me for a long time is to disable all capabilities of the Bluetooth interface except BT LE:

btmgmt --index 0 info
btmgmt --index 0 power off
btmgmt --index 0 bredr off
btmgmt --index 0 power on
btmgmt --index 0 bondable off
btmgmt --index 0 sc off
btmgmt --index 0 ssp off
btmgmt --index 0 info

the result should be as follows (btmgmt info, under current settings: remains only powered and le):

hci2:	Primary controller
	addr 28:37:37:15:3E:58 version 6 manufacturer 15 class 0x000000
	supported settings: powered connectable fast-connectable discoverable bondable link-security ssp br/edr hs le advertising secure-conn debug-keys privacy static-addr
	current settings: powered le
	name mini2x14
	short name
hci1:	Primary controller
	addr 00:1A:7D:DA:71:11 version 6 manufacturer 10 class 0x000000
	supported settings: powered connectable fast-connectable discoverable bondable link-security ssp br/edr hs le advertising secure-conn debug-keys privacy static-addr
	current settings: powered le
	name mini2x14 #2
	short name
hci0:	Primary controller
	addr 00:00:00:00:00:00 version 10 manufacturer 1521 class 0x000000
	supported settings: powered connectable discoverable bondable le advertising secure-conn debug-keys privacy static-addr
	current settings: powered le static-addr
	name mini2x14 #1
	short name

However, it should be noted that these changes are not permanent, you need to add these commands somewhere in the host autorun. I don't know how to do this best in the case of Home Assistant OS...

Even though this method works successfully for me, I have no objective evidence that it was it that solved my problem...

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

5 participants