Coder Social home page Coder Social logo

home-is-where-you-hang-your-hack / sensor.goveetemp_bt_hci Goto Github PK

View Code? Open in Web Editor NEW
157.0 13.0 29.0 68 KB

Govee Temperature/Humidity BLE Home Assistant Component

License: MIT License

Python 100.00%
govee h5075 home-assistant home-assistant-component h5074 ble hacs h5072 h5051 h5102

sensor.goveetemp_bt_hci's Introduction

Govee Temperature/Humidity BLE Home Assistant Component

NOTICE Jul, 15,2021:
Govee support has been added to Passive BLE Monitor integration as of version 4.1.0.

For any new users I would strongly suggest using that integration. BLE Monitor has better support Bluetooth support (including Intel NUC), more sensors and sensor discovery so there is no longer a need to list MAC addresses.

Existing users: I will continue to support this component for the foreseeable future but new development will likely only occur for Passive BLE Monitor integration. Sadly, you will not be able to use both components at the same time.

Thank you @Ernst79 for adding the Govee devices. Ultimately, it makes more sense for you, the end users, to have one component that does everything well and to pool development resources to ensure issues can be resolved quickly.

Govee Temperature/Humidity BLE Home Assistant Component

A custom component for Home Assistant that listens for the advertisement message broadcast by Govee Bluetooth Thermometer/Hygrometers.

hacs_badge hassfest_badge

Supported Devices

Installation

1. Install the custom component:

  • The easiest way is to install it with HACS. First install HACS if you don't have it yet. After installation, the custom component can be found in the HACS store under integrations.

  • Alternatively, you can install it manually. Just copy paste the content of the sensor.goveetemp_bt_hci/custom_components folder in your config/custom_components directory. As example, you will get the sensor.py file in the following path: /config/custom_components/govee_ble_hci/sensor.py.

NOTE: the following instructions about setting device permissions are an edge case for a very specific set up. (If you do not understand it, do not worry about).

  • If running Home Assistant without root access the Bleson Python library used for accessing bluetooth requires the following permissions applied to the Python 3 binary. If using a virtual environment for HA, this binary will be in the virtual environment path.

    NOTE: Replace "path" with the path to the Python3 binary (example: /srv/homeassistant/bin/python3)

    sudo setcap cap_net_raw,cap_net_admin+eip $(eval readlink -f path)
    

2. Stop and start Home Assistant:

  • Stop and start Home Assistant. Make sure you first stop Home Assistant and then start Home Assistant again. Do this before step 5, as Home Assistant will otherwise complain that your configuration is not valid (as it still uses the build in govee_ble_hci integration), and won't restart when hitting restart in the server management menu.

3. Add the platform to your configuration.yaml file (see below)

4. Restart Home Assistant:

  • A second restart may be required to load the configuration. Within a few minutes, the sensors should be added to your home-assistant automatically (at least two period may be required. If the period is set to a time greater than two minutes, at least four period may be required).

5. If the entities are still not displaying data, a restart of the host device may be required.

Troubleshooting and help

Any questions or support should be asked on this component's Home Assistant community post.

Configuration Variables

Specify the sensor platform govee_ble_hci and a list of devices with unique MAC address.

NOTE: device name is optional. If not provided, devices will be labeled using the MAC address

sensor:
  - platform: govee_ble_hci
    govee_devices:
      - mac: "A4:C1:38:A1:A2:A3"
        name: Bedroom
      - mac: "A4:C1:38:B1:B2:B3"
      - mac: "A4:C1:38:C1:C2:C3"
        name: Kitchen
Additional component configuration options
Option Type Default Value Description
rounding Boolean True Enable/disable rounding of the average of all measurements taken within the number seconds specified with 'period'.
decimals positive integer 2 Number of decimal places to round if rounding is enabled. NOTE: the raw Celsius is rounded and setting decimals: 0 will still result in decimal values returned for Fahrenheit as well as temperatures being off by up to 1 degree F.
period positive integer 60 The period in seconds during which the sensor readings are collected and transmitted to Home Assistant after averaging. The Govee devices broadcast roughly once per second so this limits amount of mostly duplicate data stored in Home Assistant's database.
log_spikes Boolean False Puts information about each erroneous spike in the Home Assistant log.
use_median Boolean False Use median as sensor output instead of mean (helps with "spiky" sensors). Please note that both the median and the mean values in any case are present as the sensor state attributes.
hci_device string hci0 HCI device name used for scanning.
temp_range_min_celsius float -20.0 Set the lower bound of reasonable measurements, in Celsius. Temperature measurements lower than this will be discarded. Warning: temperatures returned by the Govee device that are outside of the specified range may not be accurate. It is not advised to change this value.
temp_range_max_celsius float 60.0 Set the upper bound of reasonable measurements, in Celsius. Temperature measurements higher than this will be discarded. Warning: temperatures returned by the Govee device that are outside of the specified range may not be accurate. It is not advised to change this value.

Example with all defaults:

sensor:
  - platform: govee_ble_hci
    rounding: True
    decimals: 2
    period: 60
    log_spikes: False
    hci_device: hci0
    govee_devices:
      - mac: "A4:C1:38:A1:A2:A3"
        name: Bedroom
      - mac: "A4:C1:38:B1:B2:B3"
      - mac: "A4:C1:38:C1:C2:C3"
        name: Kitchen

Credits

This was originally based on/shamelessly copied from custom-components/sensor.mitemp_bt. I want to thank @tsymbaliuk and @Magalex for providing a blueprint for developing my Home Assistant component.

sensor.goveetemp_bt_hci's People

Contributors

billprozac avatar sfjes avatar spinningmonkey avatar thrilleratplay avatar wrt54g avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sensor.goveetemp_bt_hci's Issues

Integration crashed due the socket being unavailable

It's me again :) thanks to your last fix in #36, my sensor ran for a few days straight, until it crashed again, thanks to:

2021-04-04 06:20:01 ERROR (MainThread) [homeassistant] Error doing job: Future exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/govee_ble_hci/sensor.py", line 190, in update_ble_loop
    adapter.start_scanning()
  File "/usr/local/lib/python3.8/site-packages/bleson/providers/linux/linux_adapter.py", line 279, in start_scanning
    self.set_scan_enable(False)
  File "/usr/local/lib/python3.8/site-packages/bleson/providers/linux/linux_adapter.py", line 135, in set_scan_enable
    self.write_buffer(cmd)
  File "/usr/local/lib/python3.8/site-packages/bleson/providers/linux/linux_adapter.py", line 51, in write_buffer
    self._socket.send(data)
OSError: [Errno 100] Network is down

I have no idea how this could even happen but I guess spurious errors could happen all the time. Right now, the only option to fix this is to restart home assistant. Would it be possible to wrap this in a try / except, catch this exception, retry and keep the integration alive?

Latest Update not Starting

After installing the latest beta I am receiving the following error:

Configuration invalid:

Platform error sensor.govee_ble_hci - No module named 'bleson'

I validated that a version of bleson is installed and does respond when I perform the --observer option.

H5101 Sensor

What would you need to be able to add this sensor. I have two and it is bluetooth as well, I have a raspberry pi setup, with python exposure ( just cloud related is all ), so if there is any methodology or approach to figure it out im down to try myself, just not sure where to start.

command line/test harness

This is not an issue, but a question. Do you have any type of test setup or command-line version of the code to pull the data from a govee sensor and simply dump it out to the screen? I'm interested in setting up a very lightweight tool to pull data very infrequently and am hoping to get to the data from my H5179 without needing to set up an entire home automation software system.

I have searched and this is the closest I have found to what I'm looking for, and I could start trying to unravel the plugin code from the data access code, but I thought I'd check to see if you have a simple example you already use to test the code that yields basically this result.

Either way, thanks for the software and thanks for reading!

Error doing job: Future exception was never retrieved

I get the below error after restarting HA and the sensors show as unavailable. I'm using a USB Bluetooth dongle connected via USB Extension Cable.

Running Home Assistant OS 5.12 on a RPi4.

This is my first time reporting an issue like this so I'm not sure I'm providing everything that would help. Let me know if more information is needed.

Logger: homeassistant
Source: custom_components/govee_ble_hci/sensor.py:190
First occurred: 7:44:53 PM (1 occurrences)
Last logged: 7:44:53 PM

Error doing job: Future exception was never retrieved
Traceback (most recent call last):
File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/govee_ble_hci/sensor.py", line 190, in update_ble_loop
adapter.start_scanning()
File "/usr/local/lib/python3.8/site-packages/bleson/providers/linux/linux_adapter.py", line 276, in start_scanning
self.set_scan_enable(False)
File "/usr/local/lib/python3.8/site-packages/bleson/providers/linux/linux_adapter.py", line 132, in set_scan_enable
self.write_buffer(cmd)
File "/usr/local/lib/python3.8/site-packages/bleson/providers/linux/linux_adapter.py", line 51, in write_buffer
self._socket.send(data)
OSError: [Errno 100] Network is down

This is my config

  • platform: govee_ble_hci
    rounding: True
    decimals: 1
    period: 60
    log_spikes: False
    hci_device: hci0
    govee_devices:
    • mac: "A4:C1:38:A0:22:F4"
      name: ****
    • mac: "A4:C1:38:15:FD:F9"
      name: ****
    • mac: "A4:C1:38:97:EF:47"
      name: ****

good job but...

i've govee temperature 5051 used on HA by bluetooth .
the issue is that if i setup more than 8 govee on my configuration.yaml all sensors stop working (error is unknow).
If i use at least 8 the problem is not present.

-62 RSSI all sensors

Thanks for a very nice custom component!

All sensors are showing -62 RSSI value. It started with version 0.6 and still the same in version 0.7, if this can be fixed it would be nice to tell whether a sensor is in a good bluetooth range.

Integration crashes after a few hours with a bleson exception

Hey,

on my installation (RPi 3B+), integration v0.9.1, the sensor always stops working after a few hours. I found this in the logs:

2021-03-23 00:11:10 ERROR (HCISocketPoller) [root] Uncaught thread exception
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.8/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.8/site-packages/bleson/providers/linux/linux_adapter.py", line 59, in _socket_poller
    self._on_data(data)
  File "/usr/local/lib/python3.8/site-packages/bleson/providers/linux/linux_adapter.py", line 258, in _on_data
    hci_event_packet = parse_hci_event_packet(data[1:])
  File "/usr/local/lib/python3.8/site-packages/bleson/core/hci/type_converters.py", line 33, in parse_hci_event_packet
    subevtcode = struct.unpack("<B", data[2:3])[0]
struct.error: unpack requires a buffer of 1 bytes
2021-03-24 09:02:28 ERROR (MainThread) [homeassistant] Error doing job: Future exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)

It looks like the final failing call (struct.unpack) would not be in your code, sadly, but maybe you can still find a way to catch this error and just restart something?

Interrupted system call error

I'm using HA Container version 2021.2.3 with the 0.9.1 add in through HACS. I get the following error:

`Logger: homeassistant.components.sensor
Source: custom_components/govee_ble_hci/sensor.py:206
Integration: Sensor (documentation, issues)
First occurred: March 5, 2021, 9:50:35 AM (1 occurrences)
Last logged: March 5, 2021, 9:50:35 AM

Error while setting up govee_ble_hci platform for sensor
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 198, in _async_setup_platform
await asyncio.shield(task)
File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/govee_ble_hci/sensor.py", line 206, in setup_platform
adapter = get_provider().get_adapter(int(config[CONF_HCI_DEVICE][-1]))
File "/usr/local/lib/python3.8/site-packages/bleson/providers/linux/linux_provider.py", line 12, in get_adapter
adapter.on()
File "/usr/local/lib/python3.8/site-packages/bleson/providers/linux/linux_adapter.py", line 97, in on
self.send_cmd_value(HCIDEVUP, self.device_id)
File "/usr/local/lib/python3.8/site-packages/bleson/providers/linux/linux_adapter.py", line 47, in send_cmd_value
fcntl.ioctl(self._socket.fileno(), cmd, value)
InterruptedError: [Errno 4] Interrupted system call`

H5179 Wifi

Will the model H5179 be supported through Wifi eventually? I have that model and came here to see it is only ble (for now?).

Not Work on Doker ?

Hi, I have correctly configure it in Hassio the Govee H5075. The temperature and the humidity arrive in perfectly :)
but...after some time, I have decided to install Home Assitant by docket on the Raspberry OS.
After the same operations I not receive anyting ...

....there are some differente cnfiguration to apply ?

unpack error - measurements not stored

I noticed my last device measurements were 3 days old and I had the following error in the developer logs tab:

'Error' doing job: Future exception was never retrieved

Traceback (most recent call last):
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 489, in update_ble
discover_ble_devices(config)
File "/home/homeassistant/.homeassistant/custom_components/govee_ble_hci/sensor.py", line 471, in discover_ble_devices
for mac, sensors in sensors_by_mac:
ValueError: too many values to unpack (expected 2)

I assume this was meant to be mac, sensors = sensors_by_mac.items() ?

On a related topic, is there a way to flag stale measurements? I couldn't find anything suitable in the docs. If there are no measurements then you get a 'not available' message where the value would be on the UI but it doesn't seem like that can be explicitly triggered.

No more than 3 devices

When I add a 4th devices it gives me an error in the config yaml

govee_devices:
- mac: "E3:60:58:E1:91:03"
name: NetworkCab
- mac: "A4:C1:38:FC:FE:81"
name: Bathroom
- mac: "A4:C1:38:69:57:1A"
name: NorthLivingRm

Govee Temp Sensor

Would you consider adding this third govee temp sensor to the integration?

Readme typo

In the readme for setting up the configuration.yaml it says to use the key "devices" but it should actually be "govee_devices"

Period off by 1 second

Looking at the measurements in sqlite I noticed that they are 61 seconds apart using the default period of 60 seconds. 10 measurements from sql select:

entity_id attributes last_changed


sensor.dining_temp {"last packet id": 266653, "rssi": -58, "battery_level": 100, "last mean of": 24, "median": 26.67, "mean": 26.67, "unit_of_measurement": "\u00b0C", "friendly_name": "Dining temp", "device_class": "temperature"} 2020-02-23 02:31:53.150639

sensor.dining_temp {"last packet id": 266656, "rssi": -58, "battery_level": 100, "last mean of": 30, "median": 26.67, "mean": 26.67, "unit_of_measurement": "\u00b0C", "friendly_name": "Dining temp", "device_class": "temperature"} 2020-02-23 02:30:52.200843

sensor.dining_temp {"last packet id": 266656, "rssi": -59, "battery_level": 100, "last mean of": 25, "median": 26.67, "mean": 26.67, "unit_of_measurement": "\u00b0C", "friendly_name": "Dining temp", "device_class": "temperature"} 2020-02-23 02:29:51.179504

sensor.dining_temp {"last packet id": 266656, "rssi": -59, "battery_level": 100, "last mean of": 25, "median": 26.67, "mean": 26.67, "unit_of_measurement": "\u00b0C", "friendly_name": "Dining temp", "device_class": "temperature"} 2020-02-23 02:28:50.171242

sensor.dining_temp {"last packet id": 266655, "rssi": -59, "battery_level": 100, "last mean of": 29, "median": 26.67, "mean": 26.66, "unit_of_measurement": "\u00b0C", "friendly_name": "Dining temp", "device_class": "temperature"} 2020-02-23 02:27:49.141928

sensor.dining_temp {"last packet id": 266654, "rssi": -59, "battery_level": 100, "last mean of": 27, "median": 26.67, "mean": 26.66, "unit_of_measurement": "\u00b0C", "friendly_name": "Dining temp", "device_class": "temperature"} 2020-02-23 02:26:48.183787

sensor.dining_temp {"last packet id": 266653, "rssi": -59, "battery_level": 100, "last mean of": 23, "median": 26.67, "mean": 26.66, "unit_of_measurement": "\u00b0C", "friendly_name": "Dining temp", "device_class": "temperature"} 2020-02-23 02:25:47.156467

sensor.dining_temp {"last packet id": 266652, "rssi": -59, "battery_level": 100, "last mean of": 23, "median": 26.67, "mean": 26.63, "unit_of_measurement": "\u00b0C", "friendly_name": "Dining temp", "device_class": "temperature"} 2020-02-23 02:24:46.138008

sensor.dining_temp {"last packet id": 266653, "rssi": -58, "battery_level": 100, "last mean of": 26, "median": 26.67, "mean": 26.64, "unit_of_measurement": "\u00b0C", "friendly_name": "Dining temp", "device_class": "temperature"} 2020-02-23 02:23:45.178772

sensor.dining_temp {"last packet id": 266653, "rssi": -58, "battery_level": 100, "last mean of": 25, "median": 26.67, "mean": 26.65, "unit_of_measurement": "\u00b0C", "friendly_name": "Dining temp", "device_class": "temperature"} 2020-02-23 02:22:44.167456

Component does not work on standard HASSio installation

The provided Raspberry Pi image does not contain hcitool/hcidump, and I haven't been able to figure out how to install them such that they work inside the HA Docker container. (Bluetooth is working on my device and I can see my hygrometers with bluetoothctl.)

[FEATURE] Assign device to AREA

One nice feature in HA is the ability to define areas that contain your devices. Most commonly this is used to setup rooms in your house. You might have areas for Kitchen, Living Room, Dining Room, Hallway, Master Bedroom, Spare Bedroom, etc...

HA-AreaExample

It doesn't appear there is any way to assign govee devices to areas. From what I gather, the main issue is that govee devices aren't actually added to HA as devices at all. Rather, they are entities, and entities can not be assigned an area. To make this custom integration more "compatible" with HA, it seems each device should be added to HA as a device, and then that device should contain the temperature and humidity entities. This seems to be how other integrations work.

HA-AddtoArea

Having only started using HA a couple of months ago, I'm not familiar enough with it's underpinnings to effectively code this change, however if someone is willing to point me in the right direction, I would be happy to try and tackle this additional functionality and once I have it working add the pull request.

Hopefully we can make this happen as areas are a very effective way to manage devices!

HA unable to find sensors

Hello! HA suddenly stopped updating the sensors about 48 hrs ago. Hoping you can help me find out why!

Core logs are below.

2020-10-20 17:17:39 WARNING (MainThread) [homeassistant.components.mobile_app.notify] Found duplicate device name iPad
2020-10-20 17:17:39 WARNING (MainThread) [homeassistant.components.mobile_app.notify] Found duplicate device name SM-G988U
2020-10-20 17:19:30 WARNING (MainThread) [homeassistant.components.mobile_app.notify] Found duplicate device name iPad
2020-10-20 17:19:30 WARNING (MainThread) [homeassistant.components.mobile_app.notify] Found duplicate device name SM-G988U
2020-10-20 17:19:30 WARNING (MainThread) [homeassistant.components.mobile_app.notify] Found duplicate device name iPad
2020-10-20 17:19:30 WARNING (MainThread) [homeassistant.components.mobile_app.notify] Found duplicate device name SM-G988U
2020-10-20 17:19:30 WARNING (MainThread) [homeassistant.components.mobile_app.notify] Found duplicate device name iPad
2020-10-20 17:19:30 WARNING (MainThread) [homeassistant.components.mobile_app.notify] Found duplicate device name SM-G988U
2020-10-20 17:19:30 WARNING (MainThread) [homeassistant.components.mobile_app.notify] Found duplicate device name iPad
2020-10-20 17:19:30 WARNING (MainThread) [homeassistant.components.mobile_app.notify] Found duplicate device name SM-G988U
2020-10-20 17:24:31 WARNING (MainThread) [homeassistant.components.mobile_app.notify] Found duplicate device name iPad
2020-10-20 17:24:31 WARNING (MainThread) [homeassistant.components.mobile_app.notify] Found duplicate device name SM-G988U
2020-10-20 17:24:31 WARNING (MainThread) [homeassistant.components.mobile_app.notify] Found duplicate device name iPad
2020-10-20 17:24:31 WARNING (MainThread) [homeassistant.components.mobile_app.notify] Found duplicate device name SM-G988U
[cont-finish.d] executing container finish scripts...
[cont-finish.d] done.
[s6-finish] waiting for services.
Client error on /homeassistant/restart request
s6-svscanctl: fatal: unable to control /var/run/s6/services: supervisor not listening
[s6-finish] sending all processes the TERM signal.
[s6-finish] sending all processes the KILL signal and exiting.
[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] udev.sh: executing...
[17:25:30] INFO: Update udev information
[cont-init.d] udev.sh: exited 0.
[cont-init.d] done.
[services.d] starting services
[services.d] done.
2020-10-20 17:25:51 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for hacs which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant.
2020-10-20 17:25:51 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for smartthinq which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant.
2020-10-20 17:26:01 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for wyzesense which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant.
2020-10-20 17:26:02 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for govee_ble_hci which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant.
2020-10-20 17:26:04 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up govee_ble_hci platform for sensor
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 193, in _async_setup_platform
await asyncio.shield(task)
File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/govee_ble_hci/sensor.py", line 202, in setup_platform
adapter = get_provider().get_adapter(int(config[CONF_HCI_DEVICE][-1]))
File "/usr/local/lib/python3.8/site-packages/bleson/providers/linux/linux_provider.py", line 10, in get_adapter
adapter.open()
File "/usr/local/lib/python3.8/site-packages/bleson/providers/linux/linux_adapter.py", line 32, in open
self._socket.bind((self.device_id,))
OSError: [Errno 19] No such device

Trying to understand payload

Thanks for developing this, just what I've been looking for.

I'm trying to understand how to access the data from the Govee H5074_4C97 from macOS or on a raspberry pi without the need to go through home assistant. So I'm trying to disentangle what is home assistant and what is extracting the temperature and humidity from this device.

If I just run bleson observer on MacOS in a minimal example printing out any advertisement that contains "govee" in the name, I get output like this:

Advertisement(flags=0x00, name='Govee_H5074_4C97', txpower=None, uuid16s=[], uuid128s=[], rssi=-64, mfg_data=b'L\x00\x02\x15INTELLI_ROCKS_HWPt\x97L\xc2')

Advertisement(flags=0x00, name='Govee_H5074_4C97', txpower=None, uuid16s=[], uuid128s=[], rssi=-60, mfg_data=b'\x88\xec\x00\x96\x08\x93\x15d\x02')

Because these messages never change, I'm assuming that the temperature and humidity info is not encoded in either of these mfg_data messages.

I've spent quite a bit of time trying to unpack sensor.py. From what I can gather, Observer is just a wrapper around adapter (though strangely, when I use the adapter I can find devices but if I don't use the wrapper and use the adapter directly it doesn't find any devices).

In any case, what I believe is passed to handle_meta_event() in sensor.py is just an Advertisement object which is being printed out above, which does not seem to indicate temperature info. So how are you extracting it? The data extraction scheme in govee_advertisement.py seems magical -- is there a datasheet that decodes this bytecode for these Govee devices?

Thanks for all your help!

[BUG] period>120 causes component to not run/initialize

Software Version
Home Assistant v0.115.6
sensor.goveetemp_bt_hci v0.7.1

When setting the period to anything greater than 120, the component won't run. The only output in the log (with debug) is:
2020-10-08 13:20:58 DEBUG (SyncWorker_0) [custom_components.govee_ble_hci.sensor] Starting Govee HCI Sensor

Anything 120 or less works fine...

sensor:
  - platform: govee_ble_hci
    period: 121 # >120 Causes Component to Break
    govee_devices:

Passive BLE monitor integration (Xiaomi Mijia BLE MiBeacon monitor) syntax change.

The BLE Monitor integration changed the syntax of the Configuration.yaml file. I'm confused how to get the Govee sensors working again.

My syntax guess, which isn't working:
ble_monitor:

  • platform: govee_ble_hci
    govee_devices:
    - mac: "xxxxxxxxxxxxxxx"
    name: NoIdeaGovee1
    - mac: "xxxxxxxxxxxxxxx"
    name: NoIdeaGovee2

Any help would be greatly appreciated.

Data collection stops after invalid literal for int() with base 16:

I've been having a few cases (average once per day) where data collection stops, with an error like the below in the logs (pardon the line numbers differing from the latest master, I'm still running the pre-multi-update-fix refactoring version).

I'm guessing these might be related to corrupted data in some of the BLE broadcasts, but I haven't had a chance to look more closely.

2020-02-20 16:10:45 DEBUG (SyncWorker_0) [custom_components.goveetemp_bt_hci.sensor] NEW DATA: {'rssi': -78, 'mac': 'MAC', 'temperature': 20.3492, 'humidity': 49.2, 'battery': 100.0, 'packet': 203492}
2020-02-20 16:10:45 ERROR (MainThread) [homeassistant.core] Error doing job: Future exception was never retrieved
Traceback (most recent call last):
  File "/opt/rh/rh-python36/root/usr/lib64/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/var/homeassistant/custom_components/goveetemp_bt_hci/sensor.py", line 551, in update_ble
    discover_ble_devices(config)
  File "/var/homeassistant/custom_components/goveetemp_bt_hci/sensor.py", line 370, in discover_ble_devices
    data = parse_raw_message_gvh5075(msg)
  File "/var/homeassistant/custom_components/goveetemp_bt_hci/sensor.py", line 186, in parse_raw_message_gvh5075
    govee_encoded_data = int(data[80:86], 16)
ValueError: invalid literal for int() with base 16: ''

I don't have the trace handy, but I've also see the same ValueError, but on the line
battery = int(data[86:88], 16)

Also, once:

2020-02-22 17:20:51 DEBUG (SyncWorker_2) [custom_components.goveetemp_bt_hci.sensor] reading hcidump...
2020-02-22 17:20:51 DEBUG (SyncWorker_2) [custom_components.goveetemp_bt_hci.sensor] NEW DATA: {'rssi': -84, 'mac': 'MAC', 'temperature': 65.5363, 'humidity': 36.3, 'battery': 3.0, 'packet': 655363}
2020-02-22 17:20:51 ERROR (SyncWorker_2) [custom_components.goveetemp_bt_hci.sensor] Temperature spike: 65.5363 (MAC)
2020-02-22 17:20:51 ERROR (MainThread) [homeassistant.core] Error doing job: Future exception was never retrieved
Traceback (most recent call last):
  File "/opt/rh/rh-python36/root/usr/lib64/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/var/homeassistant/custom_components/goveetemp_bt_hci/sensor.py", line 551, in update_ble
    discover_ble_devices(config)
  File "/var/homeassistant/custom_components/goveetemp_bt_hci/sensor.py", line 451, in discover_ble_devices
    if m_temp:
UnboundLocalError: local variable 'm_temp' referenced before assignment

In all these cases, the component still goes through its per-period cycle, but no longer logs additional packet messages.

2020-02-26 15:24:29 DEBUG (SyncWorker_4) [custom_components.goveetemp_bt_hci.sensor] update_ble called
2020-02-26 15:24:29 DEBUG (SyncWorker_4) [custom_components.goveetemp_bt_hci.sensor] Discovering Bluetooth LE devices
2020-02-26 15:24:29 DEBUG (SyncWorker_4) [custom_components.goveetemp_bt_hci.sensor] Stopping
2020-02-26 15:24:29 DEBUG (SyncWorker_4) [custom_components.goveetemp_bt_hci.sensor] Analyzing
2020-02-26 15:24:29 DEBUG (SyncWorker_4) [custom_components.goveetemp_bt_hci.sensor] {'MAC': 'Govee 1'}
2020-02-26 15:24:29 DEBUG (SyncWorker_4) [custom_components.goveetemp_bt_hci.sensor] reading hcidump...

Govee H5074 Data Not Parsing

I recently found the custom component and am trying to learn from it to read bluetooth devices. {Thanks for the hard work!} I purchased a Govee H5074 and H5075. The H5075 started showing readings right away. The H5074 is only showing the entity and never provided any values. I have been trying to debug the information but without any luck I cannot see why this does not work.

Here are the specifics of my setup and values from the log:

  • platform: govee_ble_hci
    govee_devices:
    # Govee_H5074_D0B9
    - mac: "E3:37:3C:52:D0:B9"
    name: "Govee Game Room"
    # GVH5075_4297
    - mac: "A4:C1:38:9B:42:97"
    name: "Govee Office"

Log details:
2020-07-04 10:40:56 DEBUG (SyncWorker_3) [custom_components.govee_ble_hci.sensor] NEW DATA: {'rssi': -74, 'mac': 'A4C1389B4297', 'temperature': 25.6401, 'humidity': 40.1, 'battery': 100.0, 'packet': 256401}
2020-07-04 10:39:55 DEBUG (SyncWorker_13) [custom_components.govee_ble_hci.sensor] Starting
2020-07-04 10:39:55 DEBUG (SyncWorker_13) [custom_components.govee_ble_hci.sensor] Start receiving broadcasts
2020-07-04 10:39:55 DEBUG (SyncWorker_13) [custom_components.govee_ble_hci.sensor] [OrderedDict([('mac', 'E3:37:3C:52:D0:B9'), ('name', 'Govee Game Room')]), OrderedDict([('mac', 'A4:C1:38:9B:42:97'), ('name', 'Govee Office')])]
2020-07-04 10:39:55 DEBUG (SyncWorker_13) [custom_components.govee_ble_hci.sensor] update_ble called
2020-07-04 10:39:55 DEBUG (SyncWorker_13) [custom_components.govee_ble_hci.sensor] Discovering Bluetooth LE devices
2020-07-04 10:39:55 DEBUG (SyncWorker_13) [custom_components.govee_ble_hci.sensor] Stopping
2020-07-04 10:39:55 DEBUG (SyncWorker_13) [custom_components.govee_ble_hci.sensor] Stop receiving broadcasts
2020-07-04 10:39:55 DEBUG (SyncWorker_13) [custom_components.govee_ble_hci.sensor] Analyzing
2020-07-04 10:39:55 DEBUG (SyncWorker_13) [custom_components.govee_ble_hci.sensor] {'E3373C52D0B9': 'Govee Game Room', 'A4C1389B4297': 'Govee Office'}
2020-07-04 10:39:55 DEBUG (SyncWorker_13) [custom_components.govee_ble_hci.sensor] reading hcidump...
2020-07-04 10:39:55 DEBUG (SyncWorker_13) [custom_components.govee_ble_hci.sensor]
2020-07-04 10:39:55 DEBUG (SyncWorker_13) [custom_components.govee_ble_hci.sensor] Start receiving broadcasts
2020-07-04 10:39:55 DEBUG (SyncWorker_13) [custom_components.govee_ble_hci.sensor] [OrderedDict([('mac', 'E3:37:3C:52:D0:B9'), ('name', 'Govee Game Room')]), OrderedDict([('mac', 'A4:C1:38:9B:42:97'), ('name', 'Govee Office')])]
2020-07-04 10:40:56 DEBUG (SyncWorker_3) [custom_components.govee_ble_hci.sensor] update_ble called
2020-07-04 10:40:56 DEBUG (SyncWorker_3) [custom_components.govee_ble_hci.sensor] Discovering Bluetooth LE devices
2020-07-04 10:40:56 DEBUG (SyncWorker_3) [custom_components.govee_ble_hci.sensor] Stopping
2020-07-04 10:40:56 DEBUG (SyncWorker_3) [custom_components.govee_ble_hci.sensor] Stop receiving broadcasts
2020-07-04 10:40:56 DEBUG (SyncWorker_3) [custom_components.govee_ble_hci.sensor] Analyzing
2020-07-04 10:40:56 DEBUG (SyncWorker_3) [custom_components.govee_ble_hci.sensor] {'E3373C52D0B9': 'Govee Game Room', 'A4C1389B4297': 'Govee Office'}
2020-07-04 10:40:56 DEBUG (SyncWorker_3) [custom_components.govee_ble_hci.sensor] reading hcidump...
2020-07-04 10:40:56 DEBUG (SyncWorker_3) [custom_components.govee_ble_hci.sensor] HCIsniffer-Bluetoothpacketanalyzerver5.52device:hci0snap_len:1500filter:0x2
.
data dumps
.
2020-07-04 10:40:56 DEBUG (SyncWorker_3) [custom_components.govee_ble_hci.sensor] 043E28020100016BA2249878CA1C0201060AFF5D05000201010B06000D094C48422D4330353645354143B0
2020-07-04 10:40:56 DEBUG (SyncWorker_3) [custom_components.govee_ble_hci.sensor] 043E2902010000B9D0523C37E31D02010607030A18F5FE88EC1109476F7665655F48353037345F44304239B2
2020-07-04 10:40:56 DEBUG (SyncWorker_3) [custom_components.govee_ble_hci.sensor] 043E2802010001D67F8C0B23D61C0201060AFF5D0500020B010B06000D094C48422D3646434530434433B0
.
.
{GVH5075 Reports Correctly}
2020-07-04 10:40:56 DEBUG (SyncWorker_3) [custom_components.govee_ble_hci.sensor] NEW DATA: {'rssi': -77, 'mac': 'A4C1389B4297', 'temperature': 25.64, 'humidity': 40.0, 'battery': 100.0, 'packet': 256400}

Data is never parsed for the H5074 for some reason.

Any thoughts on what I may need in my setup of change for the existing code to receive values for the H5074?

Thx

HASS receives state changes many times per period

Home Assistant is getting updated with a new state change for every message that contains valid data, which results in 3-20 state changes per period. With a 60 second period, I've accumulated 27k+ state changes in Home Assistant in the last 48 hours (per sensor, temp and humid each).

Among other things it's noticeable by slower graph generation.

pi3b+ docker error

I tried to follow the instructions in the readme. I'm running on a pi3b+ with docker and homeassistant 0.117.6. My docker-compose looks like:

version: "3.8"
services:
homeassistant:
container_name: homeassistant
image: homeassistant/raspberrypi3-homeassistant:stable
network_mode: host
volumes:
- "./homeassistant/:/config/"

I'm getting an error in homeassistant of:

Logger: homeassistant.components.sensor
Source: custom_components/govee_ble_hci/sensor.py:202
Integration: Sensor (documentation, issues)
First occurred: 11:04:24 AM (1 occurrences)
Last logged: 11:04:24 AM
Error while setting up govee_ble_hci platform for sensor

Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 197, in _async_setup_platform
await asyncio.shield(task)
File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/govee_ble_hci/sensor.py", line 202, in setup_platform
adapter = get_provider().get_adapter(int(config[CONF_HCI_DEVICE][-1]))
File "/usr/local/lib/python3.8/site-packages/bleson/providers/linux/linux_provider.py", line 11, in get_adapter
adapter.off()
File "/usr/local/lib/python3.8/site-packages/bleson/providers/linux/linux_adapter.py", line 100, in off
self.send_cmd_value(HCIDEVDOWN, self.device_id)
File "/usr/local/lib/python3.8/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

I believe this has to do with step1 and setcap which wouldn't work in docker. Any ideas?

Automatically adding Govee Temp Senors - Feature Request

Since the Govee Temp Sensors have the same starting series of alphanumeric characters in the MAC address (A4:C1:38) during the scan for BLE devices, the app could automatically add ONLY the listed devices that correspond with the MAC address "A4:C1:38" to the user's configuration.yaml file.

Beta testers for H5072 sensor

@dturgel @diogosalazar and/or @enarik, could one of you test the latest v0.6 beta with the H5072? This version is a major rewrite and I want to make sure that the H5072 is still functioning as expected. The sensor should interact with HomeAssistant the same way so rolling back is an option if something goes wrong. Thus far, the only problem that seems to occur during the upgrade process the new dependency does not always install so a reboot of the device may be needed after install.

No version number in manifest file

When loading this integration into HA 2021.03.0, the following message is reported on startup:

No 'version' key in the manifest file for custom integration 'govee_ble_hci'. This will not be allowed in a future version of Home Assistant. Please report this to the maintainer of 'govee_ble_hci'

Readme needs setup instructions

Readme should include which linux packages are required, ie:
sudo apt-get install bluez-hcidump

I was also required to set permissions to hcidump so it would run without requiring sudo, with:
sudo setcap 'cap_net_raw,cap_net_admin+eip' which hcidump

You should probably also consider adding a section on installing with HACS

Mac address?

As there are no stupid questions: where do I find my devices Mac address?

Integration is using deprecated `DEVICE_CLASS_*` constants

This custom integration uses deprecated DEVICE_CLASS_* constants in its codebase.

The DEVICE_CLASS_* constants have been deprecated and replaced in Home Assistant Core 2021.12 (over a year ago). I would highly suggest updating/migrating this integration to the new enums.

For example, for the device classes supported by the sensor platform, there is now a SensorDeviceClass enum. So if a sensor previously used the DEVICE_CLASS_ENERGY constant, it should now use SensorDeviceClass.ENERGY. Other platforms (like binary_sensor, and number) provide similar enumerations for their supported device classes.

The migration thus only consists of replacing constants with an enumeration member and is, therefore, very low impact and should be fairly straightforward.

If I can help resolve any questions regarding this change or migration, feel free to ask or respond to this issue. I'm happy to help!

Kindest regards,

../Frenck

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.