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

Don't work after upgrade python to 3.8.6 [SOLVED] #125

Closed Scialla closed 4 years ago

Scialla commented 4 years ago

Don't work anymore with python 3.8.6 (HA core in venv 0.116.4)

tried 0.6.13 and 0.7.3beta version

This is error in log:

Oct 19 22:29:20 raspberrypi hass[3904]: 2020-10-19 22:29:20 ERROR (Thread-7) [root] Uncaught thread exception
Oct 19 22:29:20 raspberrypi hass[3904]: Traceback (most recent call last):
Oct 19 22:29:20 raspberrypi hass[3904]:   File "/usr/local/lib/python3.8/threading.py", line 932, in _bootstrap_inner
Oct 19 22:29:20 raspberrypi hass[3904]:     self.run()
Oct 19 22:29:20 raspberrypi hass[3904]:   File "/home/homeassistant/.homeassistant/custom_components/mitemp_bt/sensor.py", line 129, in run
Oct 19 22:29:20 raspberrypi hass[3904]:     mysocket = aiobs.create_bt_socket(self._interface)
Oct 19 22:29:20 raspberrypi hass[3904]:   File "/srv/homeassistant/lib/python3.8/site-packages/aioblescan/aioblescan.py", line 1280, in create_bt_socket
Oct 19 22:29:20 raspberrypi hass[3904]:     sock = socket.socket(family=socket.AF_BLUETOOTH,
Oct 19 22:29:20 raspberrypi hass[3904]: AttributeError: module 'socket' has no attribute 'AF_BLUETOOTH'

Model LYWSDCGQ

config:

  - platform: mitemp_bt
    batt_entities: true

pi@raspberrypi:~ $ sudo getcap readlink -f \which python3`` /usr/local/bin/python3.8 = cap_net_admin,cap_net_raw+eip

Ernst79 commented 4 years ago

See #123

Are you running HassOs 4.14 on a raspberry pi 3? If so, please downgrade to HassOs 4.13 for now.

Scialla commented 4 years ago

Thanks for your reply, i run Raspian Buster on Raspberry 3b, Ha Core 0.116.4 in venv With Python 3.7.6 all work fine, with 3.8.6 have this problem

Ernst79 commented 4 years ago

Hmm, you have the same error as in #122. I thought it was fixed with 0.7.3 (stable). But apparently not.

When googling this error, I found this which says that your python is build without Bluetooth socket support.

Seems like your python binary was built without Bluetooth socket support. You need to install python from another repository or the official website.

Perhaps you can first try sudo apt-get install bluetooth libbluetooth-dev sudo pip3 install pybluez

or sudo apt-get install bluez

I think you need to run it within the venv, at least the part with pip3. Most likely without sudo then. Please report back if it works

Scialla commented 4 years ago

OK, this evening i will try to install BT library in venv and report back. Thanks

gio-dot commented 4 years ago

Thanks for your reply, i run Raspian Buster on Raspberry 3b, Ha Core 0.116.4 in venv With Python 3.7.6 all work fine, with 3.8.6 have this problem

Hi Scialla! Come stai? I would to report that even on HA updated to the last version, installed in a Raspberry pi3B+ , sensor.mitemp no longer work at all. image

Scialla commented 4 years ago

Hmm, you have the same error as in #122. I thought it was fixed with 0.7.3 (stable). But apparently not.

When googling this error, I found this which says that your python is build without Bluetooth socket support.

Seems like your python binary was built without Bluetooth socket support. You need to install python from another repository or the official website.

Perhaps you can first try sudo apt-get install bluetooth libbluetooth-dev sudo pip3 install pybluez

or sudo apt-get install bluez

I think you need to run it within the venv, at least the part with pip3. Most likely without sudo then. Please report back if it works

Tried now, libbluetooth-dev and pybluez installed in venv (they were missing) and out venv too, rebooted rasp but i've same error in HA:

Oct 20 17:58:08 raspberrypi hass[1968]: 2020-10-20 17:58:08 ERROR (Thread-7) [root] Uncaught thread exception
Oct 20 17:58:08 raspberrypi hass[1968]: Traceback (most recent call last):
Oct 20 17:58:08 raspberrypi hass[1968]:   File "/usr/local/lib/python3.8/threading.py", line 932, in _bootstrap_inner
Oct 20 17:58:08 raspberrypi hass[1968]:     self.run()
Oct 20 17:58:08 raspberrypi hass[1968]:   File "/home/homeassistant/.homeassistant/custom_components/mitemp_bt/sensor.py", line 137, in run
Oct 20 17:58:08 raspberrypi hass[1968]:     mysocket = aiobs.create_bt_socket(self._interface)
Oct 20 17:58:08 raspberrypi hass[1968]:   File "/srv/homeassistant/lib/python3.8/site-packages/aioblescan/aioblescan.py", line 1280, in create_bt_socket
Oct 20 17:58:08 raspberrypi hass[1968]:     sock = socket.socket(family=socket.AF_BLUETOOTH,
Oct 20 17:58:08 raspberrypi hass[1968]: AttributeError: module 'socket' has no attribute 'AF_BLUETOOTH'

tried to install bluez too but is present

I've used this to upgrade python: sudo apt-get install build-essential tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev libopenjp2-7 libtiff5 libjpeg-dev -y

wget https://www.python.org/ftp/python/3.8.6/Python-3.8.6.tgz

(Hi Gio-dot look at https://github.com/custom-components/sensor.mitemp_bt/issues/123 issue)

EDIT: tried 0.7.4 beta, problem persist tried to remove component and reinstall with all official procedure, same problem

Scialla commented 4 years ago

sudo hcitool lescan command can see my device: 4C:65:A8:DD:D2:48 MJ_HT_V1

Magalex2x14 commented 4 years ago

Hi, guys. @Scialla do I understand correctly that you installed python from source? If so, then python should be rebuilt after installing libbluetooth-dev library.

ippo112 commented 4 years ago

same error for me:

_`2020-xx-xx 19:36:01 ERROR (Thread-34) [root] Uncaught thread exception .... .... AttributeError: module 'socket' has no attribute 'AF_BLUETOOTH' "_

python_version | 3.8.6 Home Assistant Core - version |0.116.4 on venv any suggestions?

Ernst79 commented 4 years ago

@Magalex2x14 Welcome back!

@Gio-dot, you have a different issue, see #123 (temporary solution, downgrade HassOs 4.14 to 4.13).

@Scialla, see the comment of @Magalex2x14, you will have to rebuild your python installation, to include Bluetooth socket support. Python 3 has native support for bluetooth sockets, however, it only has support for it if built with bluetooth.h. See also this link

Scialla commented 4 years ago

OK, i've recompiled python installation with Bluetooth socket support and create a new venv. Now, at HA start, i don't have error anymore but, value of sensor don't appare; in log at DEBUG don't find my device This is log at DEBUG with 0.7.4 beta:

Oct 20 22:39:50 raspberrypi hass[2750]: 2020-10-20 22:39:50 DEBUG (SyncWorker_7) [custom_components.mitemp_bt.sensor] Spawning HCIdump thread(s).
Oct 20 22:39:50 raspberrypi hass[2750]: 2020-10-20 22:39:50 DEBUG (SyncWorker_7) [custom_components.mitemp_bt.sensor] HCIdump thread: Init
Oct 20 22:39:50 raspberrypi hass[2750]: 2020-10-20 22:39:50 DEBUG (SyncWorker_7) [custom_components.mitemp_bt.sensor] HCIdump thread: Init finished
Oct 20 22:39:50 raspberrypi hass[2750]: 2020-10-20 22:39:50 DEBUG (SyncWorker_7) [custom_components.mitemp_bt.sensor] Starting HCIdump thread for hci0
Oct 20 22:39:50 raspberrypi hass[2750]: 2020-10-20 22:39:50 DEBUG (Thread-7) [custom_components.mitemp_bt.sensor] HCIdump thread: Run
Oct 20 22:39:50 raspberrypi hass[2750]: 2020-10-20 22:39:50 DEBUG (SyncWorker_7) [custom_components.mitemp_bt.sensor] HCIdump threads count = 1
Oct 20 22:39:50 raspberrypi hass[2750]: 2020-10-20 22:39:50 DEBUG (SyncWorker_7) [custom_components.mitemp_bt.sensor] 0 encryptors mac:key pairs loaded.
Oct 20 22:39:50 raspberrypi hass[2750]: 2020-10-20 22:39:50 DEBUG (SyncWorker_7) [custom_components.mitemp_bt.sensor] 0 whitelist item(s) loaded.
Oct 20 22:39:50 raspberrypi hass[2750]: 2020-10-20 22:39:50 DEBUG (Thread-7) [custom_components.mitemp_bt.sensor] HCIdump thread: Connection
Oct 20 22:39:50 raspberrypi hass[2750]: 2020-10-20 22:39:50 DEBUG (Thread-7) [custom_components.mitemp_bt.sensor] HCIdump thread: Connected
Oct 20 22:39:50 raspberrypi hass[2750]: 2020-10-20 22:39:50 DEBUG (Thread-7) [custom_components.mitemp_bt.sensor] HCIdump thread: start main event_loop

Oct 20 22:39:51 raspberrypi hass[2750]: 2020-10-20 22:39:51 DEBUG (SyncWorker_7) [custom_components.mitemp_bt.sensor] update_ble called
Oct 20 22:39:51 raspberrypi hass[2750]: 2020-10-20 22:39:51 DEBUG (SyncWorker_7) [custom_components.mitemp_bt.sensor] First run, skip parsing.

Oct 20 22:40:51 raspberrypi hass[2750]: 2020-10-20 22:40:51 DEBUG (SyncWorker_39) [custom_components.mitemp_bt.sensor] update_ble called
Oct 20 22:40:51 raspberrypi hass[2750]: 2020-10-20 22:40:51 DEBUG (SyncWorker_39) [custom_components.mitemp_bt.sensor] Discovering Bluetooth LE devices
Oct 20 22:40:51 raspberrypi hass[2750]: 2020-10-20 22:40:51 DEBUG (SyncWorker_39) [custom_components.mitemp_bt.sensor] Time to analyze...
Oct 20 22:40:51 raspberrypi hass[2750]: 2020-10-20 22:40:51 DEBUG (SyncWorker_39) [custom_components.mitemp_bt.sensor] Getting data from HCIdump thread
Oct 20 22:40:51 raspberrypi hass[2750]: 2020-10-20 22:40:51 DEBUG (SyncWorker_39) [custom_components.mitemp_bt.sensor] HCIdump thread: joining
Oct 20 22:40:51 raspberrypi hass[2750]: 2020-10-20 22:40:51 DEBUG (Thread-7) [custom_components.mitemp_bt.sensor] HCIdump thread: main event_loop stopped, finishing
Oct 20 22:40:51 raspberrypi hass[2750]: 2020-10-20 22:40:51 DEBUG (Thread-7) [custom_components.mitemp_bt.sensor] HCIdump thread: Run finished
Oct 20 22:40:51 raspberrypi hass[2750]: 2020-10-20 22:40:51 DEBUG (SyncWorker_39) [custom_components.mitemp_bt.sensor] HCIdump thread: joined
Oct 20 22:40:51 raspberrypi hass[2750]: 2020-10-20 22:40:51 DEBUG (SyncWorker_39) [custom_components.mitemp_bt.sensor] Spawning HCIdump thread(s).
Oct 20 22:40:51 raspberrypi hass[2750]: 2020-10-20 22:40:51 DEBUG (SyncWorker_39) [custom_components.mitemp_bt.sensor] HCIdump thread: Init
Oct 20 22:40:51 raspberrypi hass[2750]: 2020-10-20 22:40:51 DEBUG (SyncWorker_39) [custom_components.mitemp_bt.sensor] HCIdump thread: Init finished
Oct 20 22:40:51 raspberrypi hass[2750]: 2020-10-20 22:40:51 DEBUG (SyncWorker_39) [custom_components.mitemp_bt.sensor] Starting HCIdump thread for hci0
Oct 20 22:40:51 raspberrypi hass[2750]: 2020-10-20 22:40:51 DEBUG (Thread-18) [custom_components.mitemp_bt.sensor] HCIdump thread: Run
Oct 20 22:40:51 raspberrypi hass[2750]: 2020-10-20 22:40:51 DEBUG (SyncWorker_39) [custom_components.mitemp_bt.sensor] HCIdump threads count = 1
Oct 20 22:40:51 raspberrypi hass[2750]: 2020-10-20 22:40:51 DEBUG (SyncWorker_39) [custom_components.mitemp_bt.sensor] Finished. Parsed: 0 hci events, 0 xiaomi devices.
Oct 20 22:40:51 raspberrypi hass[2750]: 2020-10-20 22:40:51 DEBUG (Thread-18) [custom_components.mitemp_bt.sensor] HCIdump thread: Connection
Oct 20 22:40:51 raspberrypi hass[2750]: 2020-10-20 22:40:51 DEBUG (Thread-18) [custom_components.mitemp_bt.sensor] HCIdump thread: Connected
Oct 20 22:40:51 raspberrypi hass[2750]: 2020-10-20 22:40:51 DEBUG (Thread-18) [custom_components.mitemp_bt.sensor] HCIdump thread: start main event_loop

Tried with 0.7.3, same problem

sudo hcitool lescan found my device

Ernst79 commented 4 years ago

Looks like the component works now, but doesn’t find your sensor. Could you try to move it closer, to rule out connection issues.

Scialla commented 4 years ago

Sorry, i granted again and now work fine!!!!

Many thanks for support!!!!!

Scialla commented 4 years ago

Now Temperature and Humidity works fine but battery don't work anymore.. can i do anything? (0.7.4 beta)

Thanks

Ernst79 commented 4 years ago

We are getting there..., can you show your config? Battery sensors are called sensor.mi_battery_MAC, so they might have changed names compared to earlier versions.

ippo112 commented 4 years ago

@Scialla , please can you describe the correct workflow to solve the problem? is it enought to reinstall Pyton ? thanks

Scialla commented 4 years ago

@Ernst79 You're right!! Name of sensor is changed!!! Now all work fine!!!! Thanks for your support and your time!!!

@ippo112 As @Magalex2x14 sayed (Thanks) if you have upgrade Python to 3.8.6 from source, python should be rebuilt after installing libbluetooth-dev library.

This is what i did to resolve: Installed BT library with:

sudo apt-get install bluetooth libbluetooth-dev
sudo pip3 install pybluez

rebuilded Python:

cd Python-3.8.6/
./configure
make
sudo make install

Disabled systemctl and rebooted:

sudo systemctl disable home-assistant@homeassistant
sudo reboot

Removed old venv and saved my HomeAssistant Config:

cd /srv/homeassistant 
sudo rm * -R
cd .. 
sudo chown homeassistant:homeassistant homeassistant
cd /home/homeassistant
sudo mv .homeassistant/ .homeassistant_backup
sudo su -s /bin/bash homeassistant

Created new venv and install again HomeAssistant:

cd /srv/homeassistant
python3.8 -m venv .
source bin/activate
pip3 install homeassistant
hass -v

When you see INFO (MainThread) [homeassistant.core] Starting Home Assistant in log use CTRL+C to break and restore your HomeAssistan configuration:

deactivate 
exit
cd /home/homeassistant
sudo rm .homeassistant/ -R
sudo mv .homeassistant_backup/ .homeassistant
sudo chmod -R 0777 /home/homeassistant/
sudo systemctl enable home-assistant@homeassistant
sudo reboot

Wait long time before all plugin are installed in HA

Remember that mi-battery sensor probably has changed name, correct your config

That's all

ippo112 commented 4 years ago

thanks, works for me!

nievamarenostrum commented 3 years ago

@Ernst79 You're right!! Name of sensor is changed!!! Now all work fine!!!! Thanks for your support and your time!!!

@ippo112 As @Magalex2x14 sayed (Thanks) if you have upgrade Python to 3.8.6 from source, python should be rebuilt after installing libbluetooth-dev library.

This is what i did to resolve: Installed BT library with:

sudo apt-get install bluetooth libbluetooth-dev
sudo pip3 install pybluez

rebuilded Python:

cd Python-3.8.6/
./configure
make
sudo make install

Disabled systemctl and rebooted:

sudo systemctl disable home-assistant@homeassistant
sudo reboot

Removed old venv and saved my HomeAssistant Config:

cd /srv/homeassistant 
sudo rm * -R
cd .. 
sudo chown homeassistant:homeassistant homeassistant
cd /home/homeassistant
sudo mv .homeassistant/ .homeassistant_backup
sudo su -s /bin/bash homeassistant

Created new venv and install again HomeAssistant:

cd /srv/homeassistant
python3.8 -m venv .
source bin/activate
pip3 install homeassistant
hass -v

When you see INFO (MainThread) [homeassistant.core] Starting Home Assistant in log use CTRL+C to break and restore your HomeAssistan configuration:

deactivate 
exit
cd /home/homeassistant
sudo rm .homeassistant/ -R
sudo mv .homeassistant_backup/ .homeassistant
sudo chmod -R 0777 /home/homeassistant/
sudo systemctl enable home-assistant@homeassistant
sudo reboot

Wait long time before all plugin are installed in HA

Remember that mi-battery sensor probably has changed name, correct your config

That's all

Hi! Could you tell me the necessary commands for an installation in mac os catalina? Thank you!