custom-components / ble_monitor

BLE monitor for passive BLE sensors
https://community.home-assistant.io/t/passive-ble-monitor-integration/
MIT License
1.91k stars 247 forks source link

USB dongle issue, no more data #345

Closed vini59fr closed 3 years ago

vini59fr commented 3 years ago

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 :(

sakislad commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

@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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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

sensor:

image

sakislad commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

Could be a good news, thanks for your help

sakislad commented 3 years ago

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:

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

vini59fr commented 3 years ago

@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 commented 3 years ago

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 commented 3 years ago

the commands works fine but ask the root/admin password

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

vini59fr commented 3 years ago

2021-05-24 19_53_20-_config_ ssh_id_rsa

2021-05-24 19_53_32-_config_ ssh_id_rsa

sakislad commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

see if this topic helps... https://community.home-assistant.io/t/how-do-you-create-keys-for-ssh-in-hass-io-and-where-do-you-put-them/54753

vini59fr commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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

Ernst79 commented 3 years ago

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

vini59fr commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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

vini59fr commented 3 years ago

Strange.... Maybe à dongle issue

vini59fr commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

@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 commented 3 years ago

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 commented 3 years ago

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...