Govee BLE Thermometer/Hygrometer sensor

What type of VM? What host OS are you on?

KVM through virtual-manager. Host OS is Ubuntu 20.10

Funny enough I am struggling with the same issue at the moment. I am able to pass a bluetooth adapter in using a hostdev xml file as explained here. Using, lsusb and bluetoothctl show I can verify the adapter appears after adding it using virish, to double check I ran bluetoothctl scan on which displays finds surrounding bluetooth devices. Additionally, running gdbus introspect --system --dest org.bluez --object-path /org/bluez | fgrep -i hci shows the HCI device is hci0.

The error I am running into is OSError: [Errno 22] Invalid argument which I think is due to the VM not having enough permissions over the device.

Oh wow. Thanks for providing that link. I just got HassOS setup in a VM a couple of weeks ago which I struggled with initially because I didn’t know how to properly setup a network bridge and pass that through. Got that fixed and then I found this thread when trying to integrate my H5075 device.

I’m saving that link because there is a lot of useful info in there besides attaching and updating a device with virsh. I kept Googling “How to pass on-board bluetooth to VM” with no success in finding that documentation lol. I’ll keep checking this thread if you figure out the permissions issue or make another post myself if I manage to figure it out. Thanks for all the hard work you provide for this project!

I feel your pain, this is my first time using Libvirt KVM/QEMU. I have been fighting with NetworkManager, Firewalld and Libvirt KVM/QEMU to be able expose the VM through the host ethernet only to run into this. I’m sure I’ll waste another day trying to track it down only to find that all of the references I was reading were out of date, the error was unrelated to the issue or I have a typo somewhere.

EDIT: I think my issue appears to be with the Bluetooth dongle I am using but a patch has just been submitted.

Is the HDD connected via USB 3? Apparently, USB 3 is really bad for Bluetooth interference. Might be worth switching to a USB 2 port to see if it makes a difference.

I have an external HDD hooked up to my RPi 3B+ (USB 2.0 only) and the RPi still does a great job picking up the Bluetooth advertisements from all over the house. USB 2.0 still seems plenty fast enough for my workload.

1 Like

Interesting. I have an external M.2 SSD connected via USB 3 to my RPi 4 and do not notice any interference. Depending on the hard drive, maybe the amount of power drawn through USB3 creates interference?

Good morning/afternoon, all. Been running this quite well for the past month or so, no issues. However, for reasons unknown, and totally random, it lost its connection. Below is the log (note: that I tried rebooting HA, then rebooting Raspbian, itself).

Running Home Assistant 2021.1.5 Core, Python 3.7.3, Not docker.

Fingers crossed on this one. Thanks!

Logger: homeassistant.components.sensor
Source: custom_components/govee_ble_hci/sensor.py:206
Integration: Sensor (documentation, issues)
First occurred: 9:16:44 AM (1 occurrences)
Last logged: 9:16:44 AM

Error while setting up govee_ble_hci platform for sensor

Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/entity_platform.py", line 199, in _async_setup_platform
    await asyncio.shield(task)
  File "/usr/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/homeassistant/.homeassistant/custom_components/govee_ble_hci/sensor.py", line 206, in setup_platform
    adapter = get_provider().get_adapter(int(config[CONF_HCI_DEVICE][-1]))
  File "/srv/homeassistant/lib/python3.7/site-packages/bleson/providers/linux/linux_provider.py", line 11, in get_adapter
    adapter.off()
  File "/srv/homeassistant/lib/python3.7/site-packages/bleson/providers/linux/linux_adapter.py", line 103, in off
    self.send_cmd_value(HCIDEVDOWN, self.device_id)
  File "/srv/homeassistant/lib/python3.7/site-packages/bleson/providers/linux/linux_adapter.py", line 47, in send_cmd_value
    fcntl.ioctl(self._socket.fileno(), cmd, value)
PermissionError: [Errno 1] Operation not permitted

You are running HA on Raspbian but not in a Docker container? Any other recent changes to the system like adding another service or doing an apt-update? The only thing I can think of is that an update on the system changed the bluetooth permissions for the user that runs the HA service. You may also want to double check that bluetooth itself is working using bluetoothctl.

Correct, not in a Docker container.

No other changes whatsoever. bluetoothctl looks solid; I repeatedly see the beacon when I scan on. Also, validated the Thermometer, itself, is working as expected–the Govee app is able to get temp/humidity updates.

That error is definitely related to bluetooth device on the Raspberry Pi. Home Assistant is installed directly on Raspbian? No KVM/QEMU VM? You have run apt update in the past week or so? If it is directly on Raspbian, reboot the device one more time and check the system logs journelctl -xb and look for possible causes. This is a permission issue on the device, something must have changed for this to no longer work. You may have automatic updates running as a service that made a change, maybe it only runs quarterly and updated overnight. It will come down to figuring out what changed.

Dang it…this might be a project lol. HA is indeed installed directly on Raspbian. And, I’m not familiar with KVM/QEMU VM, so I’ll speculate that the answer to that question is a big ol’ no. I checked the journal, and came across this:

Apr 01 11:00:24 raspberrypi systemd[684]: pam_unix(systemd-user:session): session opened for user pi
Apr 01 11:00:24 raspberrypi bluetoothd[662]: Failed to set privacy: Rejected (0x0b)
Apr 01 11:00:24 raspberrypi bthelper[667]: [CHG] Controller [XX:XX:XX:XX:XX:XX] UUIDs: 00001801-0000-1
Apr 01 11:00:24 raspberrypi bthelper[667]: [CHG] Controller [XX:XX:XX:XX:XX:XX] UUIDs: 0000110e-0000-1
Apr 01 11:00:24 raspberrypi bthelper[667]: [CHG] Controller [XX:XX:XX:XX:XX:XX] UUIDs: 00001200-0000-1
Apr 01 11:00:24 raspberrypi bthelper[667]: [CHG] Controller [XX:XX:XX:XX:XX:XX] UUIDs: 0000110c-0000-1
Apr 01 11:00:24 raspberrypi bthelper[667]: [CHG] Controller [XX:XX:XX:XX:XX:XX] UUIDs: 00001800-0000-1
Apr 01 11:00:24 raspberrypi bthelper[667]: [CHG] Controller [XX:XX:XX:XX:XX:XX] Alias: BlueZ 5.50
Apr 01 11:00:24 raspberrypi bthelper[667]: [CHG] Controller [XX:XX:XX:XX:XX:XX] Pairable: yes
Apr 01 11:00:24 raspberrypi bthelper[667]: Changing power off succeeded
Apr 01 11:00:24 raspberrypi dbus-daemon[346]: [system] Successfully activated service 'org.freedeskt
Apr 01 11:00:24 raspberrypi systemd[1]: Started Hostname Service.
-- Subject: A start job for unit systemd-hostnamed.service has finished successfully
-- Defined-By: systemd
-- Support: https://www.debian.org/support

So, I ran sudo systemctl restart bluetooth which fixed the above error:

● bluetooth.service - Bluetooth service
   Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2021-04-01 11:16:37 EDT; 15min ago
     Docs: man:bluetoothd(8)
 Main PID: 2358 (bluetoothd)
   Status: "Running"
    Tasks: 1 (limit: 2062)
   CGroup: /system.slice/bluetooth.service
           └─2358 /usr/lib/bluetooth/bluetoothd --noplugin=sap

Apr 01 11:16:37 raspberrypi systemd[1]: Starting Bluetooth service...
Apr 01 11:16:37 raspberrypi bluetoothd[2358]: Bluetooth daemon 5.50
Apr 01 11:16:37 raspberrypi systemd[1]: Started Bluetooth service.
Apr 01 11:16:37 raspberrypi bluetoothd[2358]: Starting SDP server
Apr 01 11:16:37 raspberrypi bluetoothd[2358]: Excluding (cli) sap
Apr 01 11:16:37 raspberrypi bluetoothd[2358]: Bluetooth management interface 1.18 initialized
Apr 01 11:16:37 raspberrypi bluetoothd[2358]: Endpoint registered: sender=:1.34 path=/MediaEndpoint/A2DPSource
Apr 01 11:16:37 raspberrypi bluetoothd[2358]: Endpoint registered: sender=:1.34 path=/MediaEndpoint/A2DPSink

But, upon an HA restart, I’m still getting the same issues.

Try stopping all Raspbian Bluetooth systemd services then restart HA. The library this component uses requires full control over the Bluetooth controller and likely is being blocked by another service. You may need to disable the other bluetooth services and reboot the device again to ensure nothing is still binding to the hardware.

I found this:


I think that we need to use the usb2 if we want conserver the bluetooth range
1 Like

Hello!

My name is Anthony and my english is poor, but i will try!

I have a problem with bluetooth connection in raspberry pi 4(all system update… i believe)

I have installed GoveeBTTempLogger for connect H5075 in HA integrated in HACS Govee BLE HCI monitor sensor integration but dont work the connection… and the data of the cards are unavaliable.

This is a screenshot of the manual connection:

pi@raspberrypi:~ $ bluetoothctl
Agent registered
[bluetooth]# devices
Device A4:--:--:--:--:CC GVH5075_38CC
[bluetooth]# info A4:--:--:--:--:CC
Device A4:--:--:--:--:CC (public)
	Name: GVH5075_38CC
	Alias: GVH5075_38CC
	Paired: no
	Trusted: yes
	Blocked: no
	Connected: no
	LegacyPairing: no
	UUID: Generic Access Profile    (00001800-0000-1000-8000-00805f9b34fb)
	UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
	UUID: Device Information        (0000180a-0000-1000-8000-00805f9b34fb)
	UUID: Vendor specific           (00010203-0405-0607-0809-0a0b0c0d1912)
	UUID: Vendor specific           (494e5445-4c4c-495f-524f-434b535f4857)
	Modalias: usb:v248Ap8266d0001
[bluetooth]# agent on
Agent is already registered
[bluetooth]# scan on
Discovery started
[CHG] Controller DC:--:--:--:--:21 Discovering: yes
[CHG] Device A4:--:--:--:--:CC RSSI: -31
[CHG] Device A4:--:--:--:--:CC ManufacturerData Key: 0xec88
[CHG] Device A4:--:--:--:--:CC ManufacturerData Value:
  00 03 23 4d 50 00                                ..#MP.          
[CHG] Device A4:--:--:--:--:CC ManufacturerData Key: 0x004c
[CHG] Device A4:--:--:--:--:CC ManufacturerData Value:
  02 15 49 4e 54 45 4c 4c 49 5f 52 4f 43 4b 53 5f  ..INTELLI_ROCKS_
  48 57 50 75 f2 ff c2                             HWPu...         
[bluetooth]# scan off
Discovery stopped
[CHG] Controller DC:--:--:--:--:21 Discovering: no
[CHG] Device A4:--:--:--:--:CC RSSI is nil
[bluetooth]# trust  A4:--:--:--:--:CC
Changing A4:--:--:--:--:CC trust succeeded
[bluetooth]# pair A4:--:--:--:--:CC
Attempting to pair with A4:--:--:--:--:CC
[CHG] Device A4:--:--:--:--:CC Connected: yes
Failed to pair: org.bluez.Error.AuthenticationFailed
[CHG] Device A4:--:--:--:--:CC Connected: no
[bluetooth]# connect A4:--:--:--:--:CC
Attempting to connect to A4:--:--:--:--:CC
[CHG] Device A4:--:--:--:--:CC Connected: yes
Connection successful
[NEW] Primary Service
	/org/bluez/hci0/dev_A4_--_--_--_--_CC/service0008
	00001801-0000-1000-8000-00805f9b34fb
	Generic Attribute Profile
[NEW] Characteristic
	/org/bluez/hci0/dev_A4_--_--_--_--_CC/service0008/char0009
	00002a05-0000-1000-8000-00805f9b34fb
	Service Changed
[NEW] Descriptor
	/org/bluez/hci0/dev_A4_--_--_--_--_CC/service0008/char0009/desc000b
	00002902-0000-1000-8000-00805f9b34fb
	Client Characteristic Configuration
[NEW] Primary Service
	/org/bluez/hci0/dev_A4_--_--_--_--_CC/service000c
	0000180a-0000-1000-8000-00805f9b34fb
	Device Information
[NEW] Characteristic
	/org/bluez/hci0/dev_A4_--_--_--_--_CC/service000c/char000d
	00002a50-0000-1000-8000-00805f9b34fb
	PnP ID
[NEW] Primary Service
	/org/bluez/hci0/dev_A4_--_--_--_--_CC/service000f
	494e5445-4c4c-495f-524f-434b535f4857
	Vendor specific
[NEW] Characteristic
	/org/bluez/hci0/dev_A4_--_--_--_--_CC/service000f/char0010
	494e5445-4c4c-495f-524f-434b535f2011
	Vendor specific
[NEW] Descriptor
	/org/bluez/hci0/dev_A4_--_--_--_--_CC/service000f/char0010/desc0012
	00002902-0000-1000-8000-00805f9b34fb
	Client Characteristic Configuration
[NEW] Descriptor
	/org/bluez/hci0/dev_A4_--_--_--_--_CC/service000f/char0010/desc0013
	00002901-0000-1000-8000-00805f9b34fb
	Characteristic User Description
[NEW] Characteristic
	/org/bluez/hci0/dev_A4_--_--_--_--_CC/service000f/char0014
	494e5445-4c4c-495f-524f-434b535f2012
	Vendor specific
[NEW] Descriptor
	/org/bluez/hci0/dev_A4_--_--_--_--_CC/service000f/char0014/desc0016
	00002902-0000-1000-8000-00805f9b34fb
	Client Characteristic Configuration
[NEW] Descriptor
	/org/bluez/hci0/dev_A4_--_--_--_--_CC/service000f/char0014/desc0017
	00002901-0000-1000-8000-00805f9b34fb
	Characteristic User Description
[NEW] Characteristic
	/org/bluez/hci0/dev_A4_--_--_--_--_CC/service000f/char0018
	494e5445-4c4c-495f-524f-434b535f2013
	Vendor specific
[NEW] Descriptor
	/org/bluez/hci0/dev_A4_--_--_--_--_CC/service000f/char0018/desc001a
	00002902-0000-1000-8000-00805f9b34fb
	Client Characteristic Configuration
[NEW] Descriptor
	/org/bluez/hci0/dev_A4_--_--_--_--_CC/service000f/char0018/desc001b
	00002901-0000-1000-8000-00805f9b34fb
	Characteristic User Description
[NEW] Primary Service
	/org/bluez/hci0/dev_A4_--_--_--_--_CC/service001c
	00010203-0405-0607-0809-0a0b0c0d1912
	Vendor specific
[NEW] Characteristic
	/org/bluez/hci0/dev_A4_--_--_--_--_CC/service001c/char001d
	00010203-0405-0607-0809-0a0b0c0d2b12
	Vendor specific
[NEW] Descriptor
	/org/bluez/hci0/dev_A4_--_--_--_--_CC/service001c/char001d/desc001f
	00002901-0000-1000-8000-00805f9b34fb
	Characteristic User Description
[CHG] Device A4:--:--:--:--:CC ServicesResolved: yes
[CHG] Device A4:--:--:--:--:CC ServicesResolved: no
[CHG] Device A4:--:--:--:--:CC Connected: no
[bluetooth]# select A4:--:--:--:--:CC
Controller A4:--:--:--:--:CC not available
[bluetooth]# 

The system connect… and disconnect in seconds…

Help please!
Thanks!

I think I understand your problem and will try to explain it as simple as possible. If you end up needing Google Translate, I am not sure how well the technical terms will convert.

By GoveeBTTempLogger, I assume you mean https://github.com/wcbonner/GoveeBTTempLogger. That is a separate project. If you installed GoveeBTTempLogger on your Home Assistant device, as it is a systemd, it will connect to the Bluetooth controller first and block this component, https://github.com/Home-Is-Where-You-Hang-Your-Hack/sensor.goveetemp_bt_hci. Both of these devices use active scanning and block usage of the Bluetooth controller. You can use one project or the other but not both. If you want to connect to the Govee H5075 to Home Assistant, I suggest using this component and uninstalling the GoveeBTTempLogger. Be sure to disable and stop the systemd service to prevent it starting when the Raspberry Pi is rebooted. After disabling GoveeBTTempLogger, reboot the Raspberry Pi to make sure a background process is not running.

As for the bluetoothctl output, this is normal. Both projects use Bluetooth scanning to capture the packets being broadcasted instead of connecting to the Govee H5075 directly. The connecting and disconnecting is the Bluetooth controller trying to pair (not exactly “pairing”, but close enough for this description). It will connect and after a moment where no commands are sent, the connection is dropped to save energy. The Govee App connects to the device this way but this component does not and simply listens for broadcasted messaged.

You can see the manual scan did pick up one device. The ManufacturerData Value “00 03 23 4d 50 00” breaks down into:

# hex (base 16) converted to decimal (base 10)
# Encoded data
0x03234d = 205645
205645/10000 = 20.5645 # temperature in Celsius, 20.5C
(205645%1000)/10 = 64.5 # humidity, 64.5%

0x50 = 80 # this is the battery level, 80%

So if you remove GoveeBTTempLogger, reboot the Raspberry Pi and wait a few minutes, assuming the device is configured correctly, the values should appear in Home Assistant.

I apologize for poaching on this conversation a bit, but I was wondering if a couple of users wouldn’t mind trying out a HACS component I built based on some of the information from this and a couple of other resources. It uses a different bluetooth library underneath, but it auto discovers devices after setting up rather than requiring adding data to the configuration.yaml file. I only have a couple of Govee sensors (H5074,H5174) myself, so those with other types that could try it out and see if it works would be awesome!

If you can, you can add it from https://github.com/natekspencer/hacs-govee_ble

Thank you!

3 Likes

Hot damn and a long list of expletives…this looks amazing. At the moment, the caffeine has yet to kick in and my brain is the equivalent of an under powered flickering light bulb and yet to dive through the ins and outs of this. At first glance, it looks like the Bleak library is non-blocking and/or passively scanning. The auto discovery looks impressive too. These are features I wanted to add in at some point. I need to set up a VM and will try this out.

1 Like

Hi, Thankyou so much, installed like a dream and picked the temp sensor striaght away :slight_smile:

1 Like

Curious, which sensor do you have?