Skip to content

Latest commit

History

66 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

BTHomeV2-Arduino

arduino-library-badge

BTHome is an open standard for broadcasting sensor data and button presses over Bluetooth LE

BTHome LogoHome Assistant LogoESP Home

BTHomeV2-Arduino can work with OR without ESPHome

In fact it can work without HomeAssistant entirely if you are wanting to roll your own parser.

The goal of this library is to easily develop devices that can send out BTHome events; More information on BTHome https://bthome.io/

Check the progress table below to see if your requested feature is available. Create an issue if you want to see something added.

BTHome makes it easier to add very low power sensing devices to your Home Network using standard Arduino devices such as any ESP32, or more specifically the ultra low power, battery driven devices such as the FireBeetle 2 ESP32-C6.

Home Assistant Display

Why use BTHome?

Power usage is the main consideration.

A BLE Advertisement, which is used by BTHome:

  • Works on any BLE capable board
  • requires no connection.
  • is fast to send, only taking a few milliseconds.
  • the wake, sense, send, sleep cycle can be less than a second
  • can be debugged using a BLE scanner on your phone

Wifi is

  • slow to connect,
  • requires handshakes and IP resolutions
  • uses MUCH more power

Zigbee / ZWave is also an alternative

  • Very cool technologies
  • Slightly heavier power usage than BLE
  • Requires being connected to a network
  • More suitable for "always on" deployments
  • Natively works on ESP32 C6 and H2 boards
  • Examples and libraries
  • Can't debug using a phone

Supported Platforms

Recommended boards

Seeed and DFRobot both make very good low power boards such as the DFRobot FireBeetle2.

Any purpose built low power boards should work but AVOID cheap clones. Cheap boards often use linear power regulators which eat batteries.

Home Assistant + esphome

BT Proxy for ESPHome

Connection through ESPHome requires the use of a permanently powered on ESP32 as a Bluetooth BLE Proxy. I recommend using the nodemcu32 for this as it just works! Get the ESP32-WROOM-32U with the external antenna for the best range. There is an example config for the BT proxy in the examples folder.

After installing the BTHome plugin, the devices should start showing up as discovered devices.

Home Assistant Only

Similar to above, but instead of ESPHome, install a Bluetooth plugin for Home Assistant. After installing the BTHome plugin, the devices should start showing up as discovered devices.

Development

Arduino IDE

Arduino IDE is supported by this library, and has the best board support for Arduino.

VSCode + PlatformIO

This code works with PlatformIO too, but it's secondary to the Arduino IDE. The reason is that the low power boards like the Firebeetle 2 ESP32 C6 are not supported by PlatformIO (at time of writing).

Example code and config

Refer to the directory ./examples for specific library implementations.

Usage

This provides a non encrypted client that can send non encrypted data. Encryption is also possible

// Short or long name sent based on packet size
BtHomeV2Device btHome("short_name", "My longer device name", false);
// Add humidity
btHome.addHumidityPercent_Resolution_0_01(50.55f);
// Add Temperature
btHome.addTemperature_neg127_to_127_Resolution_1(-22.0f);
// Set Battery State
btHome.setBatteryState(BATTERY_STATE_LOW);
// Set battery percentage 
btHome.addBatteryPercentage(22);
uint8_t advertisementData[MAX_ADVERTISEMENT_SIZE];
size_t size = btHome.getAdvertisementData(advertisementData);
// Set the advertisement data on BLEsendAdvertisement(advertisementData, size); // <- look in the example files for this method

Troubleshooting

If you are using the FireBeetle2 ESP-C6, or any other ESP32-C*, you may need to enable USB CDC to see the Serial output.

Arduino IDE CDC Enable

Credits

Thanks to @Chreece and @TheDigital1 + other contributors for providing a good base to work from.

Thanks to @Bluetooth-Devices for the docs

Implementation Progress

Encryption is supported!

Take a look at ./examples/NimBLE_Encryption/NimBLE_Encryption.ino

Data Types

Quite a few things to implement, but hopefully will get through them all.

TypeObject idPropertyProgressNotes
Sensor0x51accelerationDone
Sensor0x01batteryDone
Sensor0x60channelDone
Sensor0x12co2Done
Sensor0x56conductivityDone
Sensor0x09countDone
Sensor0x3DcountDone
Sensor0x3EcountDone
Sensor0x59countDoneNot showing in HA
Sensor0x5AcountDoneNot showing in HA
Sensor0x5BcountDoneNot showing in HA
Sensor0x43currentDone
Sensor0x5DcurrentDone
Sensor0x08dewpointDone
Sensor0x5EdirectionDone
Sensor0x40distance (mm)DoneShowing as metres in HA Bluetooth-Devices/bthome-ble#247
Sensor0x41distance (m)Done
Sensor0x42durationDone
Sensor0x4DenergyDone
Sensor0x0AenergyDone
Sensor0x4BgasDone
Sensor0x4CgasDone
Sensor0x52gyroscopeDone
Sensor0x03humidityDone
Sensor0x2EhumidityDone
Sensor0x05illuminanceDone
Sensor0x06mass (kg)Done
Sensor0x07mass (lb)Done
Sensor0x14moistureDone
Sensor0x2FmoistureDone
Sensor0x0Dpm2.5Done
Sensor0x0Epm10Done
Sensor0x0BpowerDone
Sensor0x5CpowerDone
Sensor0x5FprecipitationDone
Sensor0x04pressureDone
Sensor0x54rawDone
Sensor0x3FrotationDone
Sensor0x44speedDone
Sensor0x57temperatureDone
Sensor0x58temperatureDone
Sensor0x45temperatureDone
Sensor0x02temperatureDone
Sensor0x53textDone
Sensor0x50timestampDoneUses the epoch seconds. Use your own library for time management.
Sensor0x13tvocDone
Sensor0x0CvoltageDone
Sensor0x4AvoltageDone
Sensor0x4EvolumeDone
Sensor0x47volumeDone
Sensor0x48volumeDone
Sensor0x55volume storageDone
Sensor0x49volume flow rateDone
Sensor0x46UV indexDone
Sensor0x4FwaterDone
binary0x15battery (normal/low)Done
binary0x16battery chargingDone
binary0x17carbon monoxideDone
binary0x18coldDone
binary0x19connectivityDone
binary0x1AdoorDone
binary0x1Bgarage doorDone
binary0x1CgasDone
binary0x0Fgeneric booleanDone
binary0x1DheatDone
binary0x1ElightDone
binary0x1FlockDone
binary0x20moistureDone
binary0x21motionDone
binary0x22movingDone
binary0x23occupancyDone
binary0x11openingDone
binary0x24plugDone
binary0x10powerDone
binary0x25presenceDone
binary0x26problemDone
binary0x27runningDone
binary0x28safetyDone
binary0x29smokeDone
binary0x2AsoundDone
binary0x2BtamperDone
binary0x2CvibrationDone
binary0x2DwindowDone
button0x00NoneDoneButton state must transition from None to another State to register
button0x01pressDone
button0x02double_pressDone
button0x03triple_pressDone
button0x04long_pressDone
button0x05long_double_pressDone
button0x06long_triple_pressDone
button0x80hold_pressDone
dimmer0x00NoneDoneDimmer state must transition from None to another state to register
dimmer0x01rotate leftDone
dimmer0x02rotate rightDone
misc0x00packet idDonecredit @the78mole
device0xF0device type idDonecredit @the78mole
device0xF1firmware versionDonecredit @the78mole
device0xF2firmware versionDonecredit @the78mole

About

An Arduino implementation of the BTHome V2 Bluetooth Sensor Framework

Topics

Resources

Stars

9 stars

Watchers

1 watching

Forks

Releases

Contributors

Languages