custom-components / ble_monitor

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

Support home brew DIY sensors #548

Closed Ernst79 closed 2 years ago

Ernst79 commented 2 years ago

Request by @scrambledleek to create support for home brew BLE sensors. BLE monitor should:

Excellent work on this HA integration! Earlier in the year I had a go at putting together an ESP32 pulse counter to monitor my 'dumb' electricity and gas meters. I decided I'd like to send the data back to HA using bluetooth rather than WiFi (ESPHome could have done it via WiFi with a lot less effort I think!), so thought I'd try and do it via advertisements and the ble_monitor integration.

When adding my pulse counter I thought it might be nice to make something flexible so people could create 'homebrew' devices that might be advertising anything, e.g. some temperatures, humidities, pulse counts, etc. all from one device & in one advertisement.

All I've actually implemented is a 3x pulse counter device, so I've not added the data types for anything other than a 32-bit count.

My implementation doesn't fit perfectly into the ble_monitor though - I couldn't see a nice way to receive multiple sensors of the same data type in a single advertisement/from a single device, so my current hack is to append my counter sensors sequentially to the sensors list...which only works for the counters I'm using, and would not be flexible at all if you had multiple temperatures coming in, or multiples of other different sensor types.

If you would like to take a look I've put what I have on github here, but it's definitely not something you'd want to merge as it is! https://github.com/scrambledleek/ha_hacs_ble_monitor/tree/homebrew-devel

Perhaps you'd have an idea of a good way to support multiple sensors of the same type coming from a device without a big rework...

Ernst79 commented 2 years ago

@pvvx It took a while, but I have release a beta, 8.0.1-beta, which supports automatically adding of sensors in HA, based on the sensor types it receives (only for HA BLE).

In the future, I probably am going to move the other sensors to the same system (other sensors are now added based on a predefined sensor list per sensortype), but that's for later. There are a few TODO's, but it seems to be working.

pvvx commented 2 years ago

Check how ATC sensors work when sending in mixed advertisement mode

Transmission with auto-switching in 3 formats at once (atc1441, pvvx, mijia) is only in the old version. Starting with version 3.7, the "All" mode has been replaced by "HA-BLE". Those. one of 4 formats is used without encryption or with encryption enabled. Additional options such as "counter", "switch", "open/close" are fully demonstrated in the "HA-BLE" protocol, and in others - by capabilities. format switch open/close counter
ha-ble ha-ble ha-ble opened + counter ha-ble counter
atc1441 none ha-ble opened + counter ha-ble counter
pvxx pvxx ha-ble opened + counter ha-ble counter
mijia none mijia-DoorSensor-1019 mijia-20e1*

*mijia-20e1 - Vendor-defined attributes 0x20E1, size 4, uint32

Ernst79 commented 2 years ago

The new HA BLE format has been released as final now (8.1.0), so I'm closing this issue. I will create a new issue for the restore state functionality, that isn't working yet for HA BLE sensors.

@pvvx Many thanks for you tips to improve the format, much appreciated.