#devs_bluetooth-archived
1 messages · Page 5 of 1
Sometimes you get lucky and the custom chars are more self documenting (on the ip transport we get a name field)
🥲 sounds a lil painful, any examples? Could I pass the real lock through a homekit bridge-like system and intercept it?
Could the app limit itself to only talk the right stuff to a SENSE lock when connected over bluetooth? (It doesn't come in with any other connectivity systems afaik)
No, I’ve only ever done it for ip based devices and it was a long time ago
And as for decompiling, usually that was done on android apps (not HomeKit stuff) and I bet iOS apps are harder to decompile:)
Yep it's not too fun
People have fooled the Eve app into thinking their home bridge stuff are Eve devices - and they were Bluetooth only at the time
I believe the lock does have Android support but I feel like reversing everything would be a lot more work than just one homekit service
The project was called fakegato
ooh elgato
..is this from the company that does capture cards? strange side buisness
gonna look into this project
They were definitely mocking out characteristics because they unlocked app features that don’t map to the current eve lineup
The capture cards were the side business I think
The elgato brand and cards were sold to Corsair and eve systems was what remained
This was back in 2018 or so
yeah i just did a lil reading
elgato brand & capture cards came first in 2012, then eve in 2014, then elgato brand (and cards) was sold to corsair in 2018
fakegato looks neat. I wonder if there's a more recent similar thing
Do you have a Mac?
I do
I don’t know if it has enough logging but maybe the accessory simulator might work? I’ve not really done anything with it myself so not even sure if the lock app would see it.
https://developer.apple.com/documentation/homekit/testing_your_app_with_the_homekit_accessory_simulator suggests your iPhone will be able to see simulator accessories
I'm gonna give this a try
I just hope it supports custom chars
this is very clearly old sw based on the icon and the old font
but like, updated with the new design language in parts
kinda funny
lol i turned on the BLE switch (which i guess starts broadcasting and it instantly showed up
1s, tryna share screenshot
oh i can't send images here that's why
nvm then, it shows up that's a good sign
custom characteristics?
So if you look at the file you linked to
A bunch of UUID’s end 0000-1000-8000-0026BB765291
And they have name fields
Those are the apple ones and part of the HomeKit spec
The others are custom or vendor characteristics
I’m just hoping the simulator doesn’t limit itself to apple defined features
I don't know if it does
let me screenshot this so i know if it's what you're looking for
This app is actually really neat lol, I can expose a BLE accessory or a IP accessory
That looks perfect
okay so i need to just replicate that json from earlier?
Yep hopefully
this is hopefully a good sign
AHAH you can export simulated accessories - and they're just (binary) plists
really freaking big ones but plists
It doesn't like this UUID: 00000054-0000-1000-8000-0026BB765291
oh that's software revision
I haven't gotten any logs yet
but it shows up in the schlage app
i wasn't able to replicate all of the services and characteristics but it seems like enough
09/22/23 04:03:36: SENSE (INFO) Remote write performed on: service: Unnamed (7F0DEE73-…), characteristic: AFAE7AD2-8DD3-4B20-BAE0-C0B18B79EDB5, new value -> {length = 49, bytes = 0x002f0010 00000000 00000000 dd8a065a ... 0000173b 00050100 }
@wicked prawn i've got it
the lock writes to the AFAE7AD2-8DD3-4B20-BAE0-C0B18B79EDB5 characteristic. not sure how this looks with multiple codes though
OH you made aiohomekit
i had no idea
Where would the vendor service get added? I don't see any other vendor services, only characteristics
To be fair it was originally homekit_python but we couldn’t figure out a sane way to keep Async in that project so I forked it
We’ve never had a vendor service before
Usually you can just key off the characteristic
and wasn't reserved (so it let me add it)
In which case you don’t neeeed the service
So there are 3 entity types in HomeKit
Ones that are tied to a single characteristic
Ones that are tied to a service
And ones that are tied to an accessory
Generally we use single characteristic entities for vendor stuff
interesting
Don't I need the service though to actually update the value?
or does that not matter
can you just tell homekit "update this characteristic" without the service
I think I'm gonna get some sleep but really happy to have even gotten this far. The lock writes 002f00100000000000000000849f640915f8b13d01044841535302043905000003050000173b7f04050000173b000501 (hexed.it link) to AFAE7AD2-8DD3-4B20-BAE0-C0B18B79EDB5 and the access code length to EEC26990-F628-11E3-A3AC-0800200C9A66 (Maybe only for the first code?)
The code name (HASS) and code (1337) are pretty obviously seen in there, but it also contains data like schedule, that I haven't even begun to look into
The lock tries to read access codes from 87D91EC6-C508-4CAD-89F1-A21B0BF179A0 but I don't know what this is meant to contain.
Other thing I noticed is they aren't using the standard battery level characteristic? Battery level is stored in 63D23C2F-2FBB-45E8-8540-47CC26C517D0
Is this still the right channel to do this in or is there a homekit channel? I don't see one
There isn’t a HomeKit channel sadly!
You could start a thread
Yeah sure, why not
(Bit frantic on my end but this looks like a good start)
Schlage SENSE HomeKit reversing
#bluetooth-archived is for help
Hi. I have question about BT classic connection speed and GATT Service caching. Should I do this? Or this is build-in? Or some other things for increase connection speed?
Hi friends, I am wondering if there is a basic skeleton for a fairly simple BLE integration (discover by service UUID, read/write some GATTs). The docs have a lot of info but I'm having trouble tying together how the overall flow runs.
In the past somebody's mentioned LD2410 as a good example, but it's still a fairly big integration by the looks
I'm having trouble understanding the basic flow... I am putting my service UUID(s) in the manifest.json, but I'm not sure how that 'discovered' device comes to be - does it need to go through the config flow?
hmm, this https://github.com/search?type=code&q=service_uuid+path%3A**%2Fmanifest.json+bluetooth helps a bit, looks like there's this bit of boilerplate that ~all of them seem to have https://github.com/ec-blaster/magicswitchbot-homeassistant/blob/980ddab0cfc4eca66ed3d7802f18f66120b3d8ce/custom_components/magicswitchbot/config_flow.py#L30-L129
Yep
When the core Bluetooth integration sees the uuids you told us in manifest.json it calls async_step_bluetooth
If the user is doing the manual “add integration” ui flow, then it’s async_step_user
All config flows in core have 100% test coverage and they have to drive a flow to completion
So they are a good way to see all the outcomes
I wonder whether there's a good debugging tool to dig through what the Bluetooth proxy sees. I have LightBlue BLE on my iPhone which works okish but (a) I'm not always in the short range of the device (tap timer outside) and (b) this particular device likes to disconnect immediately if I connect to it
I guess it wouldn't be too hard to implement a custom integration that provides services and/or API endpoints to call some of these methods: https://github.com/home-assistant/core/blob/dev/homeassistant/components/bluetooth/api.py
I'm getting a bleak.exc.BleakDBusError: [org.bluez.Error.AuthenticationFailed] Authentication Failed error when using a integrated bluetooth adapter, when calling bleak pair(), but not when connecting using ESPHome proxies.
If I first pair manually using bluetoothctl, then everythin works.
Is this some known issue? Anything I can/need to add to the integration to make it pair?
I just found that that if I have bluetoothctl running, it prompts me with [agent] Accept pairing (yes/no): and if I enter yes everything works.
That also explains why there is no issues with ESPHome BT Proxy I guess
bah, it is a bleak limitation since it does not have an agent 😦
@frosty plinth maybe you know the answer?
If you are talking about using bleak retry connectors connection option to enable caching that I would say yes as long as the device doesn’t have a problem with it and properly implements the service hashing. pySwitchbot and aiohomekit both have methods to clear the service’s cache in the event bluez caches it incorrectly which was a problem on older versions
Sooo.... I've been messing around with making a custom integration to track bluetooth devices by area. I think it's ready to have some other people poke holes in it, so thought I'd post it here first in case it has some significant issues that I'd want to address before unleashing it on unsuspecting users. Also huge thanks to those in here who have helped me out with my muddling around the codebase! 😄
https://github.com/agittins/bermuda/
Hey. Don’t have time to look into it now but very interested to. (Context - Just landed a private ble tracker in core in the last cycle and thinking about adding an area sensor for it, and looking at ways to improve/calibrate the distance calc etc)
Great - yeah I saw that (congrats) and was thinking it would be great to see if I could hook into it to keep tabs on those devices too.
I'm getting user reports on dropped active connections with HAOS 11. Appearantly it's an "Unlikely error"...
[org.bluez.Error.Failed] Operation failed with ATT error: 0x0e (Unlikely Error)
looks like there is an open issue https://github.com/home-assistant/operating-system/issues/2821
or two
The first one is for the same devices.
someone mentioned the yale lock issue in #bluetooth-archived .. I'm travelling so I won't be able to update/test it until after the 23rd though
Except that addon uses the Bluetooth adapter directly, while my integration uses HA bluetooth.
So probably the BlueZ update
seems haos has 5.69
which doesn't have that fix
I'll just tell people to have patience or revert to 10.5. Enjoy your travels.
I love it when people know their stuff well enough to see "Unlikely error" and immedietely go "Oh. I know what that is!"
More like “unlikely upstream didn’t break something error”
There was a big kernel regression last time
where is the "glue" between esphome bluetooth proxy and bleak client?
I'm trying to debug why the disconnect_callback passed to bleak.client is not being called when using ESPHome...
I checked it, but it looked something else
oh, it is it indeed 🤦♂️
since it did not have the disconnect_callback arg, I dismissed it
thanks!
_on_bluetooth_connection_state is not called when I call disconnect() on the client. do you know if that is intended?
should it be called only when the disconnection is not "intended"?
I think the disconnected callback is only called when the device/esp disconnects not when its requested
yeah, that is the issue
that fixes it, but I am in no way familiar with the bluetooth proxy code to be sure that it is fine to do it that way
it does look like bleak calls it unconditionally https://github.com/hbldh/bleak/blob/2fe1b69f89929ec95dbc8027fd58c47b7a1e3e0a/bleak/backends/bluezdbus/client.py#L151
still checking though
that was my experience when I was using my laptop's bluetooth radio
hmm
that will call the disconnected callback even if the device was never connected
true. I can do was_connected = self.is_connected before disconnecting
and check was_connected to call the callback method
suggested change in the PR
diff --git a/homeassistant/components/esphome/bluetooth/client.py b/homeassistant/components/esphome/bluetooth/client.py
index d44d331248b..970e866b27b 100644
--- a/homeassistant/components/esphome/bluetooth/client.py
+++ b/homeassistant/components/esphome/bluetooth/client.py
@@ -392,8 +392,8 @@ class ESPHomeClient(BaseBleakClient):
return await self._disconnect()
async def _disconnect(self) -> bool:
- self._async_disconnected_cleanup()
await self._client.bluetooth_device_disconnect(self._address_as_int)
+ self._async_ble_device_disconnected()
await self._wait_for_free_connection_slot(DISCONNECT_TIMEOUT)
return True
when it calls _async_ble_device_disconnected(), won't is_connected be False already?
ah no, that is done on the cleanup
let me test it locally
yep, works!
is that an appartment complex? 😆
nope, the previous owner really liked to put in doors for some reason
I'm trying to figure out the appropriate coordinator to use for a custom integration (https://developers.home-assistant.io/docs/core/bluetooth/bluetooth_fetching_data/). The underlying device library uses Bleak, sending commands with write_gatt_char and then listening for responses with start_notify. I don't really know much about bluetooth (e.g. "advertisements" and what qualifies as active vs. passive). Anyone more knowledgeable able to point me towards the appropriate coordinator setup? (each update I get from the device I need to use to update multiple different entities)
Sounds like your device requires an active connection
Some devices (sensors) you don’t need to use bleak and you don’t need to connect to them. They just blast their current state into that air (sometimes once a second). And we can decode those broadcasts and turn them into entities. That’s what passive is all about.
You probably want to look at ld2410_ble as a starting point
thanks so much!
Oh nice, this example even handles debouncing. Perfect.
Interesting. with this approach, does _async_update_data still get called by the system and just act as a no-op? Or does omitting update_interval mean the system never tries to poll?
I've an integration that connects to a bt device. If the device is not online, the integration fails and I need to reload it when the device is online. Is there some kind of bt event that the integration could listen to to self heal?
Yes. Look at the ld2410_ble integration. It uses async_register_callback from the Bluetooth integration to do that.
Does anyone have any advice or somewhere to look for why BleakClient() would not setup?
if not client.is_connected:
await client.connect()
print(f"Connected: {client.is_connected}")```
Sample code in a config_flow never gets past line 1, the only relevent log data i can see is:
```2023-11-12 14:44:36.000 INFO (SyncWorker_0) [homeassistant.loader] Loaded nespresso from homeassistant.components.nespresso
2023-11-12 14:44:39.514 INFO (MainThread) [asyncio] execute program 'bluetoothctl': <_UnixSubprocessTransport pid=660937 running stdout=<_UnixReadPipeTransport fd=27 polling>>
2023-11-12 14:44:39.522 INFO (MainThread) [asyncio] <_UnixSubprocessTransport pid=660937 running stdout=<_UnixReadPipeTransport fd=27 polling>> exited with return code 0
2023-11-12 14:44:39.523 INFO (MainThread) [asyncio] <_UnixReadPipeTransport fd=27 polling> was closed by peer
2023-11-12 14:45:09.534 ERROR (MainThread) [aiohttp.server] Error handling request```
Appreciate any help.
(discovered.device is a BLEDevice)
Turns out HABleakClientWrapper overrides BleakClient and doesnt return a cooroutine so client = BleakClient(BLEDevice) is sufficient.
Hi, how can I modify the example sensor example in order to add notifications support? In my case I'm using a BLE device, and I'd like to wait for notifications and when they're received the integration should process the data and update it. I couldn't find many infos online (at least that I could understand). Thanks!
In general it’s discouraged
The proxies and dongles both have limited numbers of parallel connections, and using GATT notifications would quickly chew through that.
Many devices use the blue advertisements as a way to work around this, by either putting the sensor data in the advertisement and or including some sort of counter to help the controller know when to connect.
If you are making your own firmware that’s definitely the best route.
There’s a presence sensor in core that does it anyway. In that situation, presence detection you don’t want lag. Its name starts ld2 something or other.
trying to make a standalone ble scanner with esp32 to detect my phone.
can someone guide me to how I can check advertised MAC against IRK:key ?
reason: this esp is far from any wifi, I cannot use esphome there
On the same vein. I'm working on an integration for a coffee machine. It uses a notify method to provide a response to the given command. Should i expose this as a sensor to feedback into HA? Wondering how to let the frontend know if the brew command was successful or failed for some reason...
you needs to do an AES operation on the irk and one half of the MAC, and part of the output should match the other half of the MAC
byte ordering easy to screw up, and i think one of the esp32 libs put the MAC in a different order to what we are used to
the python version of the check is here: https://github.com/Bluetooth-Devices/bluetooth-data-tools/blob/main/src/bluetooth_data_tools/privacy.py
I'll see if I can plug something together with this and the espresense code
the HA code does a lot of stuff to minimize AES costs
like negative caching false matches, so you don't have to check them every time there is a broadcast
if your esp code has access to it (we don't in HA yet) there is a flag that says whether its a classic static MAC address or whether its a random one
you can ignore a lot of broadcasts by filtering out the static addresses
yeah nimble allows that
Given we don't yet have a coffee machine entity type I'd look into the event entity for that
It would let people create their own automations (like a notification to their device of choice), integrate with the log book, let you see in the UI when a brew last finished
Given its a point in time event, rather than a state of being on or off, event is just a much better fit than sensor
I think in your case notify is definitely reasonable, as long as you are only doing it when a brew is in progress
Currently that is what I do. Create the handler when sending the brew command and close it once I have the response. I'll take a look at the event entities. Thanks!
Yep, thats their version. I believe that function is available from another project under a less restrictive licence if that is a concern for your use.
it'll live in my garage, acting as garage door opener
So you would recommend the homeassistant server to connect to the device and fetch data when needed? Can you share examples where data is stored in advertisement frame? Thanks!
Depends on the type of device, but yes.
Xiaomi_ble, govee_ble, inkbird_ble
I think oral b?
Pretty sure there are others
(late to the party, but...) If you are looking to implement something, I would heartily suggest using the bthome protocol, which lets you pack all sorts of things into advertisement packets, supports encryption if your application would benefit from it, and will JustWork* in HA by magically showing up as a device without having to write an integration for it. https://bthome.io/
Thanks a lot! I'll definitely have a look at it. I'm running my sensors with a nrf51 so I doubt they'll be plug and play but that's a starting point
Oh cool. I have some nrf51 modules I've been playing with (haven't touched them in a few months, but they're still on my desk!) that I plan to build bthome remote control buttons with. Actually... I am 99% sure I got to the point where I could flash one and have it publish bogus data via bthome. I'll dig it out and throw it up on github if that might be useful for you. I'm pretty sure it's un-encrypted payload though (because lazy/daft) and not sure if it's using bthome v1 or v2. But between that and then looking at the code for pvvx's thermometers (which does v1 encryption) it might give you a decent head-start.
@carmine bone I found it - have thrown it up at https://github.com/agittins/nRF51-BTHome - please excuse my inability to write sensible c code! 😅 But at least it shows the bare minimum required to send BLE packets from an nRF51822.
Oh god... I last touched that back in January - more than "a few months"!
I'm looking at adding IRK support at some point to my Bermuda integration (https://github.com/agittins/bermuda/issues/44). I haven't done my own proper searching yet (and frankly I can't remember if I asked you already, sorry), but just off the top of your head, is there an API to your integration that I could leverage to get easier support? I feel like it might be smarter to use your integration to identify any known IRK devices rather than duplicating those things in mine (and not benefiting from future work you put in it).
(doh, sorry for the @)
So you have some nrf51 devices too?! It would be amazing to integrate that, can you confirm it's working for you or is it still a work in progress? Still many thanks mate!
So what's there did build and load on a real nRF51822 (well, I assume it's real!) and it broadcasts valid BTHome packets, which homeassistant picked up with discovery and added to my devices. The sensor values themselves are bogus, but it does "work" in the most basic sense. Code is as pretty as a bucket of smashed crabs, but it worked at least once.
Depends what you need from the API. It’s been a while since I had time to play but from what I recall there’s a coordinator.py that’s a singleton and lets you subscribe to updates by irk. There isn’t a public api to track all devices my integration is tracking though.
That's amazing! Why do you call data bogus?
I think I can help on the openocd part, actually I program my nrf51 with a Raspberry via gpio pins
Ok, sounds promising then. I'm basically "tracking" everything, but by (naughtily) copying data out of the bluetooth advertisement storage, so I'd probably want to throw every "new" MAC address at some IRK resolver (like your integration) and see if it belongs to a "known" key, in which case I'd add it to my list of devices I create sensors for. If I use your integration I wouldn't have to provide a means for the user to enter keys etc, since they would set up their devices once in your private_ble_device and I would include those in the devices I track area and distance for, and keyed against the private address.
Bogus in that the name is hard-coded (to AJGBLETest) and the "temperature" sensor just sends a forever incrementing value, rather than an actual temperature from somewhere.
Ok, now I understand what that bitwise operation was😂
Lots of days are just like that in Oz, though.
You’ll need to fish the irks out of my config entries to be able to use my API iirc
You register an irk to track rather than ask it about a mac
It tries to be clever about not doing AES ops on every packet - so caching negative resolves, tracking current irk->mac relationships, and busting those caches at the right times.
You might be able to read out of those internal caches
I’d be interested in seeing if we could work something out so that you could just get what you need from the device tracker entities that were Bluetooth based.
Like Ibeacon resolves random addresses to a known beacon too in some cases I think?
So users could set up the boring ble trackers, beacon trackers, and private ble trackers, and you just attach to device trackers of type Bluetooth, and they expose their current Bluetooth address. And hopefully very little extra configuration?
Awesome, thanks. Yeah iBeacons is another thing I need to add support for, but I think for those one just matches on the UUID in the advert, so no crypto stuff required.
You should get an event from the state machine then when the ble address changes, regardless of the underlying implementation.
Ooh, that might be all I'd need, actually.
That might work today for private ble device because the current address is an extra attribute on the device tracker entity
And i cribbed from ibeacon so might get that for free as might has same extra attribute
The way I'm currently doing things is I internally track every observed advertiser, and in my config flow the user can select which devices (by MAC address) that they'd like to have Area, Distance and device_tracker entities created. But since I only track by observed MAC, ibeacons and private addresses are... suboptimal user experiences 🙂
The reason I track all devices is because my pipedream is to approximate a solution for every advertiser and proxy in 2d space - so more data = more garbage = more output, as is my understanding.
Hmm. I haven't felt a lot of love for how ibeacon does its matching/ident of devices, but that's probably (as usual) due to my lack of understanding of the nuances rather than some fault of the integration 🙂
From a ux perspective my proposal would mean the user could pick by device tracker entities. And it would be reasonable to enable those macs by default.
Under the hood you could still track everything of course
And if there were other Bluetooth trackers, as long as they expose the current MAC address you don’t have to do any extra work
Eg I’d dearly like to figure out how to track my AirPods - I don’t think they use irks
Yeah that sounds like a pretty good strategy. So I'd listen to events announcing the change of address for any known beacons/pBLE's and just track those associations.
I’m hoping to find bandwidth to tidy up the main ble tracker, as it has lots of low hanging fruit. Like ignoring random addresses.
So could all use that scheme eventually maybe.
I wouldn't be surprised if they used the FindMy method of rotating their address.
No worries - thanks for your help - I'm not sure when I'll get to this feature but I'll save the notes! 🙂
Has someone worked with bluetooth mesh and has a good example that shows how to connect to a network and so on?
There’s nothing in core or esphome for Bluetooth mesh, and there’s no integration in HA with bluezs flavour of Bt mesh. And afaik no one is working on getting anything like that into core.
What kind of mesh are you talking about? hass_plejd/pyplejd connects to the Plejd mesh using BLE. I don’t know if that is a useful example for you though
hello everyone, is there anyway to load custom firmware in HAOS? I have a fairly new NUC bluetooth that's not supported out of the box, I have the firmware - I just need to figure out how to load it in HAOS.
Update- I got it figured, just needed to restart it once custom firmware was loaded.
What kind of mesh are you talking about
I'm interested in adding additional support for Thermopro devices. It seems like the real magic happens in the thermopro_ble library. What is the recommended way to setup my dev environment so that the devcontainer will use my own version of thermopro_ble instead of the public one?
Hi, I am developing a new integration for my new christmas light chain I bought. I have reverse engineered it so now all that is left is the development of integration. However, I am seeing a weird behaviour where command from HA is not reflected on state of chain - chain does not turn off. What am I doing wrong?
@wild igloo I converted your message into a file since it's above 15 lines :+1:
The HA logs also contain the last "None" log I forgot to include it. It looks like both the service and characteristic is the same, but for some reason the command is not respected when issued by HA. Both script and HA run on Mac M2.
It does detect characteristics etc flawlessly, so it must be connecting properly...
At this point I am trying to just run one command on __init__.py to test it
I needed to change this:
await client.write_gatt_char(writeCharacteristic, command, True)
Now it works!
It turned out to be a lot more to work than I expected. I've finally got the scanners uncoupled from hass in https://github.com/home-assistant/core/pull/105523 see https://github.com/bluetooth-devices/habluetooth
@frosty plinth That's great! So with these changes, what would the process look like to set up a local dev environment for using a BT proxy with Bleak outside of HA?
Nothing yet. That’s a few more steps down the line. Maybe by the end of the year if I don’t hit any more roadblocks
Great, I will be eagerly awaiting the results 🙂
If anyone is able, I could use some help reverse engineering the advertisements for this thermopro tempspike:
AdvertisementData(local_name='TP970R', manufacturer_data={13824: b'\x00\x05\x0b6\x00'}, service_uuids=['72fbb631-6f6b-d1ba-db55-2ee6fdd942bd'], rssi=-29)
It should be giving me two temperatures (the probe, and ambient), but I can't make sense of it so far.
@mystic mural I find it helpful to capture a series of advertisement packets over a period of time as the temperature reading changes. That way you can rule out the bytes that don't change, and the ones that do change are probably what you're looking for.
it appears first and last bytes are always 0
AdvertisementData(local_name='TP970R', manufacturer_data={14336: b'\x00\xfd\n6\x00'}, service_uuids=['72fbb631-6f6b-d1ba-db55-2ee6fdd942bd'], rssi=-32)
AdvertisementData(local_name='TP970R', manufacturer_data={14848: b'\x00\xfd\n6\x00'}, service_uuids=['72fbb631-6f6b-d1ba-db55-2ee6fdd942bd'], rssi=-36)
AdvertisementData(local_name='TP970R', manufacturer_data={15104: b'\x00\xfb\n6\x00'}, service_uuids=['72fbb631-6f6b-d1ba-db55-2ee6fdd942bd'], rssi=-39)
AdvertisementData(local_name='TP970R', manufacturer_data={15360: b'\x00\xfa\n6\x00'}, service_uuids=['72fbb631-6f6b-d1ba-db55-2ee6fdd942bd'], rssi=-38)
AdvertisementData(local_name='TP970R', manufacturer_data={15616: b'\x00\xfa\n6\x00'}, service_uuids=['72fbb631-6f6b-d1ba-db55-2ee6fdd942bd'], rssi=-38)
AdvertisementData(local_name='TP970R', manufacturer_data={15360: b'\x00\xfb\n<\x00'}, service_uuids=['72fbb631-6f6b-d1ba-db55-2ee6fdd942bd'], rssi=-37)
AdvertisementData(local_name='TP970R', manufacturer_data={15360: b'\x00\xf8\n<\x00'}, service_uuids=['72fbb631-6f6b-d1ba-db55-2ee6fdd942bd'], rssi=-33)
AdvertisementData(local_name='TP970R', manufacturer_data={15104: b'\x00\xf8\n=\x00'}, service_uuids=['72fbb631-6f6b-d1ba-db55-2ee6fdd942bd'], rssi=-37)
AdvertisementData(local_name='TP970R', manufacturer_data={15104: b'\x00\xf8\n=\x00'}, service_uuids=['72fbb631-6f6b-d1ba-db55-2ee6fdd942bd'], rssi=-38)
AdvertisementData(local_name='TP970R', manufacturer_data={14848: b'\x00\xfb\n>\x00'}, service_uuids=['72fbb631-6f6b-d1ba-db55-2ee6fdd942bd'], rssi=-33)```
A bit more of a sample
I'm wondering if they are splitting the middle 3 bytes somehow
@mystic mural Is this a ThermoPro TP970?
It's called TempSpike Plus, but TP970 is the model listed on the device
Yes ThermoPro
What is the name of the mobile app that connects to it?
@mystic mural It's possible the temperature reading is not in the advertisement data. Maybe the app needs to make an active connection to the device and subscribe to a notification characteristic to get the data. I looked at the android app a bit and it seems that may be what's happening.
If you want to try decompiling the android app (version 2.20) yourself to look at the parsing code for the notification data, it seems to be located in class a1.b, and I think j is the method that is used for this device model
oh ok, I was afraid it might be something like that
Thanks for taking a look
I didn't see anything useful when I looked at the services and characteristics
But I've never done any bluetooth stuff before
'0b11111011'
>>> bin(b'\x00\xfb\n>\x00'[2])
'0b1010'
Usually I put the device in the freezer for a bit and than put it some place warm and compare the bits
It should now be usable in a dev env outside of HA with just ESPHome after https://github.com/home-assistant/core/pull/105611 but you'll have to connect it manually and there isn't any helpers to do that ...yet
Awesome, I'll definitely try it out once there are some instructions or sample code available.
Hi all, I'm a newbie who is seeking to integrate a custom BLE device. I hope to find code for a similar device to learn on. I studied the code for RuuviTag but it seems that only works for data in advertisement, not for devices that needs a connection to get notifications from characteristic uuids
@bronze dagger What kind of device is it?
https://github.com/home-assistant/core/pull/105747. It’s getting closer. Probably 5-6 more turns before it’s easy to use outside of HA
@young forge https://renpho.com/collections/smart-food-scale/products/smart-food-scale-2
It's this device. I currently wrote Python code using the bleak package and is able to get notifications via the client.start_notify function. But that's on my laptop. Thx
After https://github.com/home-assistant/core/pull/105908 it should be possible to connect it all up with nearly the same code HA is using. I’ll probably do a few more breaking changes on the habluetooth lib though before the next Home Assistant release and than start versioning it properly
@frosty plinth I studied RuuviTag integration which I believe was done by you. But I believe that device has all its data in the advertisement right?
It does, but I did not do that integration
You want SwitchBot or ledble for something that uses an active connection
Maybe ld2410 for a sensor that needs an active connection
I'd be careful with that one as I think there is an issue in the lib were it retries forever. otherwise its likely fine
Thanks
@frosty plinth I found a few other integrations that uses active connection, idasen_desk, yalexs, medcom_ble, and airthings_ble. Are you aware of any issues with them? Thanks
I maintain yalexs_ble and I’m not aware of any issues. I can’t say about the others as I don’t have history with them
The Yale locks have lots of quirks though
SwitchBot is a much more strait-forward integration
Aha. home_assistant_bluetooth.models has been removed. That's it!
So... I'm connecting to a mesh of bluetooth devices. I.e. they are meshing between themselves, and I only need to connect to one to controll all of them.
For a traditional setup of a single bluetooth host, finding the best connection is easy. Just keep a list of all discovered devices, and when you need to send a command you connect to the one with the best RSSI.
With a bunch of proxies though... things get odd.
Does anyone have any ideas about a good way to guarantee a good connection to a system like this?
Are there any heuristics other than rssi for best mesh nodes to connect to?
Do you need a persistent connection to the mesh?
My instinct would either be to make user choose which proxy to use, then pick the best signal to any mesh node. Or to have heuristics to pick the best mesh nodes (are there mains powered nodes? Is it like thread where there are routers and sleepy end devices?) and then pick the best proxy for the best entry node. Or id just roll with it and pick the best signal overall, but make it sticky to avoid flappy connections. But not too sticky in case of proxy or mesh node failure.
If you can easily filter out which devices are mesh nodes, then you should be able to maintain a list of mesh nodes and the best signal strength that ha sees for them just using the existing APIs (assuming they broadcast normal advertisements)
Then start at the top and try and connect to them until you get a connection (in case a single proxy has 2 many active connections etc).
So it doesn’t sound too awful to just totally lean into the existing Bt/proxy machinery?
It’d be more annoying if you had to subscribe to each mesh nodes MAC address manually
Could you also bypass the mesh in some cases and just talk to the device directly if there is a proxy in range? Proxies do render the mesh somewhat moot
It requires an active connection which stays open to get status updates.
For now I keep a list of the devices and their RSSI as they are discovered, and then try connecting to one at a time based on that order as you say.
The issue is that, say proxy A reports an high RSSI for a device on discovery, but when it's time to connect proxy A is bussy. Then proxy B will make the connection instead, but that may be far away and would make a better connection with a totally different device.
How could you let the user choose the proxy?
If you used the Bt machinery you’d end up with a list that said device a and proxy 1 have the best connection, and device b and proxy 3 have the second best connection
It wouldn’t use device a and proxy 3 when device b and proxy 3 were a better choice
Ah, I see what you mean. That might be true at “discovery” time, but at connection time the bt manager might pick a “better” proxy.
But is that actually what happens? I thought the proxy to use was encoded in the BLEDevice?
Ah no I am wrong (_async_get_best_available_backend_and_device)
So I thought you could directly query a scanner instance, make sure your BLEDevice had the right source and then that would be the proxy that was used. But ^ means you’d need to extend ha’s BleakClientWrapper to do that (call _async_get_backend_for_ble_device on your ble device, then only try to connect to that).
Without adding a connect wrapper to BleakClientWrapper that only tries the source on your BLEDevice, none of my ideas work. And I don’t see how you could avoid the edge case you said either.
But if you had such a wrapper this would work
And so would this
So I’d probably try and add this wrapper and then not have the user choose anything ?
I'm trying to incorporate a cheap, chinese BLE body scale. The scale works with the OKOK Android app. The scale does not work with the OpenScale app. The scale only sends Advertisement packets. These packets only contain a manufacturer_data section and do not include things like manufacturer_id, local_name, service_data, service_uuids, etc. Below is a DEBUG of a received advertisement packet:
2023-12-30 16:23:51.897 DEBUG (MainThread) [homeassistant.components.bluetooth.manager] hci0 (00:E0:43:80:E4:03) [connectable]: 50:FB:19:EE:E7:15 AdvertisementData(manufacturer_data={1472: b'\x00\x00\x00\x00\n\x01$P\xfb\x19\xee\xe7\x15', 19904: b'\x1f\x95\x17p\n\x01%P\xfb\x19\xee\xe7\x15'}, rssi=-80) match: set()
The weight is encoded in the first two bytes of the second "element". So \x1f\x95\ = 1F95 = 8085 decimal = 80.85 kilograms, and then they append the MAC address at the end of that same second element. I've tried using jdeath's renpho integration at https://github.com/jdeath/renpho but the manifest.json needs to see manufacturer_id, local_name, or some other common/standard field which is omitted in the packets broadcast by this scale. I'm no coder so I apologize for any incorrect terminology, but the two "section headers" shown of 1472 and 19904 are not constant and change with each weighing. SO, I'm in search of any help on how I can parse the weight from these Advertisement packets and put them into HA. Let me know if you need more DEBUGs or additional info. Many thanks in advance.
Make sure you turn off passive scanning on your Bluetooth dongles/proxies if it’s on. Active scanning can sometimes elicit more detail.
Check if the scale has a pairing mode and try entering that if it does.
Likewise try resetting it if it’s paired to your phone.
Sometimes they use these fields as real values and blindly push all the data into the manufacturer data section
Thanks @wicked prawn and @frosty plinth . Passive scanning is off. The scale does not have a pairing mode. I believe it truly only spits out Advertisement packets, nothing more. I looked into the BLE chip and it's a Chipsea CST92P23B. From their website: "CST92P23B is a low-power, low-cost, high-integration RF wireless transmitter chip with integrated transmitter, GFSK modem, RF baseband, etc. The chip adopts the SOP8 package, which can realize unidirectional broadcast signal transmission." So from that description it fits that it's a transmit-only device and can't be paired/connected. The OKOK app lists the MAC address of the scale so I'm thinking the first time you use the scale that the app sees the advertisement packet with a Chipsea MAC address, puts that MAC address in a whitelist and marks which "secret sauce" to use to parse the weight from the manufacturer_data.
So, is there a way for me to do the same thing - filter by MAC and parse the first two bytes of the second "section" of the manufacturer_data? TIA!
In order to make it get discovered automatically, not now. You’d have to expand the core matchers code to add matching on the first bits of the address then you could include it in your manifest.json. It might be there’s a reason that’s a bad idea though. Some of that discovery code is highly optimised because Bluetooth is a bit of a firehose
But you could implement async_step_user and list all addresses and do that filtering yourself
Thanks, @wicked prawn . After reading your reply I realized I was in over my head as I'm not much of a coder. Purely for posterity info should someone run into this same scale or a similar circumstance, allow me to share what I tried as a last-chance "for giggles" effort which happened to work!
I found https://github.com/custom-components/ble_monitor, installed it, added the device via MAC address, stepped on the scale and by some glorious magic the device appeared as Manufacturer = MaxxMee, Model = QJ-J, and Firmware = Xiaogui. And it populated three sensor entities (impedance, non-stablized weight, and weight) of which the weight entity was correct. So I'm set!
Thanks again for your time, suggestions, and the support you provide to the HA community.
are there directions anywhere on how to test a ble integration within the devcontainer?
Esphome proxy maybe?
Can't directly use the BT of the host device?
for reference, I'm working on a PR to add some features to the switchbot integration to detect opening vs. closing (right now the integration just hard codes any movement = opening which is confusing). @frosty plinth suggested the change should really be in pySwitchbot, not HA. So I started making the changes in the library which I think works (works when I do it in comand line and added a bunch of unit tests). However of course I want to test in HA. I could override the pip install on my actual HA device, but would be much easier to test and debug on the devcontainer
Is the host Linux?
no, Windows
If it’s something like Debian then in theory you just need to bind mount the dbus socket
but it means it should be using WSL
But it needs a dbus socket
Unless you can get it a dbus socket and that dbus bus has bluez running on it and that bluez can see your Bluetooth dongle, no, you can’t
hmm ok
Install SwitchBot as a custom component. Remove the requirements line from manifest.json, and manually install the package in the container
Yeah but the container can’t seem to see my Bluetooth adapter. So I’ll have to do this on my actual HA I suppose. Not a big deal was just wondering since the dev container gives me debugger access
Use an esphome Bluetooth proxy
Can you have one proxy tied to 2 HA instances or will I need to temporarily repurpose one?
You’ll have to temporarily repurpose one, as there’s just not enough processing power to reliably update two instances at once
Let's say I am interested in buying a bluetooth enabled home appliance, how likely is it going to be programmed to be able to work with Home Assistant easily? It isn't listed in any integration at the moment. Not even the brand.
Then unlikely, unless it’s HomeKit enabled
Bluetooth LE doesn’t provide much in the way of standards for building IoT appliances, so every vendor makes their own protocol. They are all varying shades of naff.
It has something called GATT as a building block. To put it in terms of web development, it’s like it had a web (http) server but no APIs implemented
So we have to make an integration for every vendor
Homekit is an exception because Apple defined a bunch of standard IoT types on top of GATT. So we can support many devices with one integration.
There are other exceptions where one vendors stuff is reused by other vendors (so there’s actually a few non Xiaomi things that use the Xiaomi protocol) and similar for really cheap imported led lights
So the end result is you are going to have to reverse engineer whatever they built on top of GATT
Either by Bluetooth sniffing or decompiling the Android app
I don't think it is HomeKit enabled. It even has their own app. How easy would it be to reverse engineer the Bluetooth protocol they use?
Looks like their app interacts with a Bluetooth "gateway" that is a plug and it connects to the appliance
Over wifi
I would like to cut out that middle man if possible
Not sure if their app also do direct connection to the appliance
Hard to know. If you can’t decompile the app for clues you’ll need to sniff the GATT traffic and hope it’s not encrypted
How secure is unencrypted GATT? Can someone spoof the traffic and make my appliance to do some stuff?
Replay attack etc
Also, what is the feasibility of re-flashing the firmware to something open source instead?
Most of the Bluetooth IoT stuff I’ve dealt with (apart from homekit) has little security.
Like, not even pairing
Xiaomi has an encryption key for their sensors broadcast, but you can just issue another one over GATT
Can’t really answer that
Some Xiaomi sensors got a replacement firmware that is way better than the original
They even figured out how to turn it from a Bluetooth sensor to a zigbee sensor
Would say it’s the exception rather than the rule
If it’s powered by as esp32 your chances go up
I'm looking to add several additional sensor types to bluemaestro. I'm starting by updating and issuing a PR against the python library. Once I have that, is the PR for HA just an update of the dependency version?
Yes unless you need to add new mappings for additional sensor types. Than you’ll have to do one to bump the lib in Ha and one to add the new mapping
Thanks for confirming
I ported the library from bleparser to its own package https://pypi.org/project/xiaogui-ble/ Just needs a cut and paste HA integration
It turned out that the leaone app/xiaogui format works for a lot more devices so I made an integration https://github.com/home-assistant/core/pull/108617
I'm looking into improving my Pinecil BLE integration, is there an example integration which features HA autodiscovery via service UUIDs so the user doesn't need to manually find the MAC of the BLE device? I'm finding the BLE HA docs a little all over the place 😦
There’s a lot of examples you can git grep the manifest files for service_uuid in the core repo to find them
govee_ble and yalexs-ble likely have some good examples
What's the right way to point a checkout of ha-core to use a local in-devleopment copy of a BLE library?
can I just update the dependency somewhere?
You can run pip install --upgrade . from the checked out library when the venv is activated and than restart
Make sure the version matches so ha doesn’t downgrade the library
Or temporarily remove it from the manifest.json
Anyone here familiar with the Idasen desk integration? I wrote a custom integration based on it, but I have some questions. Thanks
@half stag
👀
@half stag I need to connect to multiple BLE scales (different MAC address, same product) that sends weight data via a characteristic uuid, much like the height for the Idasen desk. I implemented my custom HA integration for the HA yellow by mimicking the Idasen desk. I got it to kinda work but it's having issues connecting and reconnecting to the scales. The scales shut off after a period of inactivity and turn back on when there is activity. Previously I implemented this on my PC using the bleak package in Python and it was able to handle multiple devices and arbitrary connects and disconnects almost instantaneously. But the HA version cannot reliably reconnect. I sometimes get a lot of timeout errors when doing multiple connection attempts. But I'm not able to pinpoint the issue as it's not repeatable, ie, sometimes it can reconnect quickly after the 1st try. Another type of error I saw in the logs is "no backend with an available slot..."
@half stag I hope you or someone more well versed in HA and Bleak can advise. Granted there is a hardware difference (Windows PC vs HA Yellow). I wonder if that can explain some of the issues
Another thing I can think of is that in my PC implementation I use a set to keep track of connected MAC addresses and when a device disconnect it is removed from the set and the next time it turns on, a new Bleak client object is created. I'm not sure if this is the case for the HA implementation
Thanks
What Bluetooth hardware is your yellow using?
The error you saw about connection slots typically indicates either a range issue or a Bluetooth hardware issue
The 3rd cause is that some dongles can only handle 2 connections at once , so if you have lots of devices with semi permanent connections you’ll have trouble
If you are using this api - https://developers.home-assistant.io/docs/core/bluetooth/api/#subscribing-to-bluetooth-discoveries - then you should get a notification as soon as the device is located. HA is always scanning in the background.
You should also be using https://developers.home-assistant.io/docs/core/bluetooth/api/#fetching-the-bleak-bledevice-from-the-address to get a BLEDevice to use when starting up a BleakClient
If neither of those are working (eg if you get None instead of a BLEDevice but the device is active) it strongly points to a hardware or range issue
Have you tried using esphome Bluetooth proxies? I found that it works much, much more reliably than using built-in Bluetooth. There are some issues in github around that
Removed
Please ask in #bluetooth-archived @charred lantern
Sorry overlooked that channel. Will remove and repost there. Thanks!
Thanks. I'll look into it. But FYI the scales don't require pairing, just need to connect. Not sure if the issues you've seen with the built-in Bluetooth are only for pairing...
Thanks for the reply. I will have to wait till Monday to know what Bluetooth hardware the HA Yellow has. The range I was playing with was less than 10 meters. I did log the type of the object passed into the bleakclient constructor and it was a BLEDevice as opposed to just a MAC address.
10m might be a long distance for some devices, and eg for built in pi Bluetooth we’ve seen the effective range be 2m. Heck we’ve seen it be 30cm for some combinations.
And for Realtek usb based Bluetooth, even if you have an antenna and it’s near, the chip crashes that often that it spends more time offline than online. (HA has a watchdog to try and reset such chips, but they can crash again after a few minutes).
The Bluetooth hardware is Silicon Labs MGM210P Mighty Gecko Module. I moved the scales right next to the HA Yellow and didn't notice much improvement. Still had plenty of time out errors
I haven't yet. One thing I noticed is that if I start HA and both scales are off, in the init.py it'll still create a Bleakclient object and attempt to connect. Is there a way to make it so that it only attempts to connect to discoverable (on) devices? I tried to do await bleakscanner.find_device_by_address() to get a list of discoverable devices and it won't run, and didn't throw any exceptions. When I tried bleakscanner.discover(), it was "discovering" devices that are off for some reason. The reason I tried this is because I want to see if having a new Bleakclient each time would help with the connection reliability. Thanks
well, from experience I would say the esphome bt proxy has more chances of helping 😄
I had really weird issues when using the internal BT
Depends on the chipset a lot, which is why I asked
Realtek chipset crashes every couple of minutes
Intel pretty spotty
Internal Pi also seems to be pretty bad for some
You shouldn’t be using bleakscanner inside HA
See the stuff I linked to up there
And then grep for integrations using them
There’s a couple that use those callbacks to only connect when a device is seen
Thanks. I'll give it a try tomorrow. Seems like I just need to add the async_register_callback() to the asyn_setup_entry() in init.py and match by address. And then wrap the rest of the setup (creating the coordinator, etc) in a callback function. The asyn_connect() of the coordinator already uses async_ble_device_from_address.
I am using a Raspberry Pi 4 with Home Assistant 12.0.
I want to use the onboard bluetooth to controll some BT devices. I see that a Bluetooth integration came with the installation of HAOS. But when I try to add a entry I just get a message as of "No unconfigured Bluetooth adapters found. There are 0 ignored adapters.".
What could be wrong?
This channel is for development related questions. #bluetooth-archived for support.
Thank you for clarification. Ill head over to the correct section.
Can this error message be related to my Bluetooth integration?
ERROR (MainThread) [bellows.uart] Lost serial connection: ConnectionResetError('Remote server closed connection')
It seems bellows is for Zigwee but I get that message in my logs, and always after a 2nd device attempt to connect
Did you use home assistant yellow too?
No. My laptop and also a raspberry pi. But the issues are not radio-specific I think
In order to test whether the Bluetooth connection issues are due to hardware, one option is to use the ESPHome Bluetooth proxy as abmantis said. For something quicker, do you think I can try running HA on my windows PC (via the tutorial). That way it still uses the same underlying hardware as when I ran my non-HA code on my PC right?
Do you mean on WSL?
Pretty sure that doesn’t work
Full virtualisation might, but it’s a common reason I end up doing support in #bluetooth-archived - usb passthrough is a joke
What about on an Ubuntu machine or MacBook?
I think the issue is due to the raspberry pi built in Bluetooth. In the HA terminal I used bluetoothctl and it showed a MAC address corresponding to Pi. I tried connects and disconnects and found out when one is connected, the other will take a long time to connect. But if I connect to one individually it's fast. So it looks to be a hardware issue huh?
Seems like one is limited to 3 simultaneous connections with the ESPHome proxy right? I can also try a Bluetooth USB adapter right? I think I pinned the problem down to the Pi adapter. (thru playing around with bluetoothctl)
afaik the problem is not the rpi adapter and an usb adapter will have the same issues. the problem seems to be on bluez (or HA<->bluez)
Thx. By problem do you mean the unreliable connection with multiple connections (I am only doing 2 devices now) or the max number of connections?
the connection issues
but you can try another adapter. maybe you get lucky
Raspberry pi internal Bluetooth is bad for what you are doing
It is highly susceptible to interference
We see lots of cases where the chip itself hangs and can only be recovered by removing the power from the pi completely
Lots of cheap Bluetooth dongles use Realtek chips that are also rubbish.
In the worst case they crash every few minutes. At least some of them (but not all!) can be recovered by HA by simulating USB replugs.
As for simultaneous connections - it does vary by adaptor (2 or 3). It’s mostly quite a low number. But there are some that can manage 5 iirc.
If you read the documentation for the Bluetooth integration it will tell you which ones are best in this regard.
Of course the ones that support more devices are slower to connect.
ESPHome proxies work well, but there are still things you need to keep in mind.
Eg wired is better than wireless - esp chips have one raid that switches between Bluetooth and WiFi as quickly as possible. But that means it’s not doing Bluetooth whenever it’s doing WiFi. You will miss packets because of this.
And you need to be mindful of the antennae.
Olimex wired poe boards with external antenna are popular. The GL-s10 is popular.
Hope that helps @bronze dagger
Why is OTA not working when ESPHome updates Proxy server I get this error "ERROR Connecting to 192.168.1.104:3232 failed: [Errno 113] No route to host"
We decided to try an USB Bluetooth adapter first as it's an easier option now than ESPHome BT proxy. We ordered a "high performance" one and I can already see it's better than the built-in one thru using bluetoothctl. How do I choose which adapter my integration should use? Is it as simple as disabling the built-in one in Bluetooth integration? Or do I need to modify the configuration.yaml by specifying the MAC address of the adapter under "Bluetooth"? Thx
No changes to config yaml
You should have a Bluetooth integration for each dongle
Delete the one you aren’t using
When it is “discovered” again you can ignore it in the ui
Should I set the adapter to passive scanning or no? Thx
Already doing it.
All mine are set to active fwiw
So far the issues I have are all connection related. What about devices that don't require an action? Such as the RuuviTag that has data in its advertisement. Would the built-in Bluetooth fare better?
hi everyone, I've been trying to understand the switchbot integration as an example, but i am having trouble figuring out where its doing things like choosing the service or characteristic uuids, might just be an issue with me not being familliar with home assistant integrations or python.
my goal is to create an integration for the power watchdog that doesn't require an esp32 as a bluetooth relay, i have a c# test script that gets the data just fine, but i can't seem to understand how to use what i learned from it to make a python based integration. if anybody knows of an integration simpler than switchbot please let me know.
here is a pastebin of my c# program (its a single-source-file .net8 program, probably would work in .net7 as well) https://pastebin.com/pdkjwpi4
Reading and writing to characteristics in HA is done with bleak. Our version is a little more complicated because we support multiple adapters at once and roaming between them. But looking at bleak and porting your c# to work with bleak outside of HA would probably be useful.
https://github.com/Danielhiversen/pySwitchbot/blob/master/switchbot/devices/device.py is where the reading and writing happens though
If you can solve a problem just by listening to advertisements, definitely do that - it has near-zero cost compared to making connections which brings in all sorts of complexities (as you've found!)
Yes, thanks. We found a Bluetooth scale that contains all the data in the advertisement. I'm looking at the RuuviTag BLE integration to base it off that. Do you have any recommendations for any easier/straight forward existing integration(s) that parse data from advertisement?
The bthome integration does exactly that, I'd also search for passivebluetoothdata in the components to find more that are likely (going by memory, I'm out currently)
Leaone
Not sure if this belongs in devs_core but being bluetooth related... I am trying to get my tests working in a custom component. I've made some progress and I think I am starting to grasp a few pylint basics. I'm running into a problem where now it errors trying to load the bluetooth dependency (my component depends on bluetooth_adaptors, which in turn depends on bluetooth). In my pytest run I get:
INFO homeassistant.setup:setup.py:366 Setting up usb
INFO homeassistant.setup:setup.py:366 Setting up bluetooth
ERROR bluetooth_adapters.systems.linux_hci:linux_hci.py:102 Unexpected error while getting HCI devices: A test tried to use socket.socket.
Traceback (most recent call last):
File "/home/vscode/.local/lib/python3.12/site-packages/bluetooth_adapters/systems/linux_hci.py", line 83, in get_adapters_from_hci
sock = socket.socket(AF_BLUETOOTH, socket.SOCK_RAW, BTPROTO_HCI)
Is there something simple/obvious I'm missing that I need to set up in my testing or will I need to put my full logs and config up somewhere so someone can dig at it properly? I'm using the pytest_homeassistant_custom_component plugin.
Most Bluetooth integrations have a fixture enabled in there conftest.py that should prevent that. Mobile right now so I can’t check what it is but should be easy enough to find as all of them should have it
I wrote a custom integration for a BLE scale that contains weight data in the advertisements, by emulating the RuuviTag BLE integration. I basically put the files in the custom integration folder. Good news is that I was able to get it to work. Bad news is that I get strange errors in the log shown below that I have no clue about. I don't even think my code uses those modules, but somehow it's expecting to import those .py files.
diagnostics.py, recorder.py, system_health.py, logbook.py, media_source.py, etc
@bronze dagger I converted your message into a file since it's above 15 lines :+1:
But the integration seems to run (I get data in the homepage) with no problem
Yes the advertisement works a lot smoother than active connection
_async_process_single_integration_platform_component no longer exists in 2024.4.x. Are you running an old version?
Its actually been gone since 2024.3.x via https://github.com/home-assistant/core/pull/110795
Yes I believe I'm running an older version of Home Assistant. I see notification telling me to update. I will do that Monday
Thanks
Ah, of course! Thank you, I'm another step further along now...
I've just bought some Graywind BLE roller blinds... I'm trying to reverse engineer the protocol so I can control it from HA. I used HCI snoop log and can see some packets that seem to correspond to up/down/stop but when I try sending them from bluetoothctl it doesn't work. It also isn't showing the service UUID, but just a handle (0x0015) and so I have to guess which service UUID to send the packets to. I also notice that when I run 'connect XXX' in bluetoothctl the pairing LED on the blind keeps blinking whereas when I pair the app on the phone it stops blinking. Any ideas?
Any idea how to filter out certain discovered bluetooth devices? I have a custom integration with service_uuid and manufacturer_id, but it seems like my Samsung television uses the same. Manifest.json is here: https://github.com/lkempf/casambi-bt-hass/blob/main/custom_components/casambi_bt/manifest.json
The television and light are discovered with this advertisement data:
2023-12-04 20:15:50.851 DEBUG (MainThread) [custom_components.casambi_bt.config_flow] Discovery: [C8:12:0B:09:81:7D] Television from e8:9f:6d:08:ad:74.Advertisement: AdvertisementData(local_name='Television', manufacturer_data={117: b'\x02\x18\x14\xa1AZ\x88b\xe0\xf9F\x19\xeb\xe9\x00ng\x83', 963: b'm*\xb2c\xd8\xb0\n', 224: b'\x00\x93\xcaX\x93\x08'}, service_data={'0000fe9f-0000-1000-8000-00805f9b34fb': b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'}, service_uuids=['0000fe4d-0000-1000-8000-00805f9b34fb', '0000fe9f-0000-1000-8000-00805f9b34fb', '00000601-0000-1000-8000-00805f9b34fb'], tx_power=-127, rssi=-70).
2023-12-04 20:15:50.852 DEBUG (MainThread) [custom_components.casambi_bt.config_flow] Discovery: [6D:2A:B2:63:D8:B0] CBU-PWM4 RGBW from e8:9f:6d:08:ad:74.Advertisement: AdvertisementData(local_name='CBU-PWM4 RGBW', manufacturer_data={963: b'm*\xb2c\xd8\xb0\n'}, service_uuids=['0000fe4d-0000-1000-8000-00805f9b34fb'], tx_power=-127, rssi=-80).
2024-04-07 13:30:20.026 DEBUG (MainThread) [custom_components.casambi_bt.config_flow] Discovery: [C8:12:0B:09:81:7D] Television from E8:9F:6D:08:AD:74. Advertisement: AdvertisementData(local_name='Television', manufacturer_data={117: b'\x02\x184\xa1^\x91Z(\xfbd\x96\x1d\x94\xc3L\xce\xfa`', 963: b'_\xef5B\xb0I\x0f\xbb\x00)\x00\x00m*\xb2c\xd8\xb0\x02\n\x00\x00\xf2', 224: b'\x00h\xcaX\x93\x08'}, service_data={'0000fe9f-0000-1000-8000-00805f9b34fb': b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'}, service_uuids=['0000fe4d-0000-1000-8000-00805f9b34fb', '0000fe9f-0000-1000-8000-00805f9b34fb'], tx_power=-127, rssi=-71).
Hi Ryan, I found your integration for nespresso and I try to update it for DV6 and newer HA. Do you have a discord where we could discuss if you still support your code ?
I have some issue with BT.
Also Hi guys, I made some modification to Ryan integration, but I have issues with the authentication with nespresso machine. If any of you have any ideas on why I cannot get it to connect it would be great :
https://github.com/nxor/ha_nespresso_integration/tree/feature/supportForDV6
2024-04-06 10:47:38.074 ERROR (MainThread) [custom_components.nespresso.nespresso] Onboarding not permitted. Already paired?
2024-04-06 10:47:41.076 ERROR (MainThread) [custom_components.nespresso.nespresso] Couldn't read onboarding status of device. Probably BT Dongle incompatible?
The device is : Vertuo_DV6_80646F4D3454 (not real mac)
do you know how to get the auth_key ? I can get it to pair with my phone, but not with HA...
Either narrow the matching in the manifest.json to only match the direct, or change the config flow to abort righ away when its the wrong device
Hello My Friends, I am very interrested in the LIDL PARKSIDE Smart Watering Timer. The newone have Bluetooth only support, the older Version have Zigbee support. A Integration for Home Assistent is very amazing Project for our community. https://www.lidl.de/p/parkside-bewaesserungscomputer-pbb-a1-mit-bluetooth/p100348186
Hi @shell wolf, feel free to contribute such integration.
Hi, I'm working on a bluetooth mower integration (I actually wrote the mower platform) and am running into a small issue where I'm getting object has no attribute 'last_update_success' on async add entities. This is on a coordinator which has an activeBluetoothDataCoordinator which of course inherits from passive which has this attribute which is why I'm so confused.
got around it for now by setting last_update_success but I don't see it used anywhere else, though the only other active bluetooth integration is switchbot from what I can see, which isn't helpful. Is there a better way to set the poll interval other than the poll_debouncer?
Only the processor coordinators and DataUpdateCoordinator have that method.
Does the device send advertisments that should trigger a poll ? https://developers.home-assistant.io/docs/core/bluetooth/bluetooth_fetching_data/#choosing-a-method-to-fetch-data
No it does not, it requires an active connection
I send protobuf messages to the device and it responds
Ooooh I should just be using DataUpdateCoordinator
@elder idol
Advertisements have nothing in the for this device. I need to periodically connect and get data
Thanks @frosty plinth totally had misunderstood that documentation when I originally read it
With bluetooth proxies they don't connect directly to devices as in GATT notifications can they?
ESPHome proxies support GATT.
Generally BLE connections are short lived (homekit devices forcefully close if they are idle for 30s for example) and there are a limited number of active devices that can be sustained at once. Even for the best usb dongle that’s 7. But for esp32s it’s like 2 or 3 from what I remember.
So there’s an argument that it’s better to poll some devices that waste one of those precious slots.
But i would expect notifications to work on esphome provides if they were needed
Right, with the integration I'm writing, I poll a device about once a minute, only needs to be connected for about 30s then can disconnect, just not seeing any activity on the esp32, I probably haven't flashed it correctly. Fwiw it's a lawn mower. Considering I got confused with the active ble description for coordinators (using data update coordinator now) figured it didn't hurt to ask.
Yeah at least for the ble tracker needed to flash locally
ok so it connects but its not proxying the commands from HA to said device. Is this due to the interface number with bleak?
the proxy connects but it drops the connection straight away. Its actually preventing HA from communicating with the device.
resolved issue
I've been reviewing/testing the Husqvarna automower Bluetooth integration using ESPHome bluetooth proxy. I've noticed that when I have 1 proxy everything "works", but if I add a second proxy to HA, it no longer connects to the mower. Removing the second proxy, everything starts working again.
I suspect the author is missing some method. Any pointers would be very helpful!
https://github.com/home-assistant/core/pull/108326
I posted this in the non-devs channel: how was a dev supposed to know that PassiveBluetoothDataProcessor changed the number of arguments it needed? PassiveBluetoothDataProcessor[Optional[Union[float, int]]] needs to change to PassiveBluetoothDataProcessor[str | int | None, SensorUpdate] . Only found it by seing this change made in the oral-b integration (which I based my integration on) years ago. Did not see a notice about it in the "Backward-incompatible changes" section of change log. Thanks..
Is there a specific commit you are referencing? That looks like a typing only change and not a run-time change.
I think you are referencing https://github.com/home-assistant/core/pull/117157. That is typing only. You can choose to add typing or ignore it. It should have no impact on runtime
Moving from 2024.5 to 2024.6 caused my custom integration written with 1 argument to not load/fail. It threw an error at that line about number of arguments. I made the change and it loaded fine. I think commit #117157 shows someone made that number of arguments change to a bunch of core components. Just took an hour or so for me to figure out why something broke after being stable for over a year. Error if run it the old way: Unexpected exception importing platform custom_components.renpho_ble.sensor File "/config/custom_components/renpho_ble/sensor.py", line 129, in <module> PassiveBluetoothDataProcessor[Optional[Union[float, int]]] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/typing.py", line 384, in inner return func(*args, **kwds) ^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/typing.py", line 1066, in _generic_class_getitem _check_generic(cls, params, len(cls.__parameters__)) File "/usr/local/lib/python3.12/site-packages/typing_extensions.py", line 2947, in _check_generic raise TypeError(f"Too {'many' if alen > elen else 'few'} arguments" TypeError: Too few arguments for <class 'homeassistant.components.bluetooth.passive_update_processor.PassiveBluetoothDataProcessor'>; actual 1, expected at least 2
Please open an issue. I don’t think the op intended that to be a breaking change
done. #119150
Hi o/ I'm currently working on an integration for a bluetooth device and ran into some weird behaviour. When the device is connected through the bluetooth adapter of my pc or the on-board bluetooth of the raspberry pi all works fine, but when the device is connected through an esp32-based bluetooth proxy for some of the characteristics i get the errorbleak.exc.BleakCharacteristicNotFoundError: Characteristic f6d7ffff-5a10-4eba-aa55-33e27f9bc533 was not found!
are there some known limitations with the amount of characteristics? or should i report a bug?
https://twitter.com/XenoKovah/status/1801570782285369459 potentially interesting for some
Those “zigbee” dongles have a TI chip supported by Sniffle https://t.co/8xCdA8vHxK, the current best Bluetooth sniffer by Sultan Qasim Khan, so I’ll be using them for Bluetooth not Zigbee
Hi everybody. I developed a custom component that works with fitness equipment that implements Bluetooth Fitness Machine Service. I have an elliptical trainer, which strangely presents itself as an exercise bike. 😄 I would like to announce and invite users who have fitness equipment at home. Where is the best place to write about this? Thank you.
Thanks!
How can I make ESPHome to announce BTHome event of a "button pressed" ?
ESPhome is normally used with WiFi, but you’d be better asking this in the ESPhome discord
Hi All, I have a BLE device I'd like to support that requires pairing/bonding before you can write/notify the relevant gatt characteristics. Is it possible to perform this paring in the config flow of a home assistant integration? I cant seem to find any existing components in core that do this. Even the bleak doco is pretty patchy on this as pairing seems to be delegated to an OS function.
Eq3smart
Thanks for the tip, I'll look at that. I found this statement on the integration page confusing "Pairing is only required with firmware versions above 120 and when not using ESPHome Bluetooth proxies." Surely pairing is required by the device, so is this actually meaning to say that the device is not supported by ESPHome bluetooth proxies? (i.e. requires a local adapter)?
I think the ESP home implementation will automatically pair