BTHome.Objects (BTHome v0.1.0)
View SourceBTHome v2 object definitions and metadata.
This module centralizes all sensor type definitions according to the BTHome v2 specification and provides fast lookups. It includes metadata for each sensor type including units, scaling factors, data sizes, and signedness.
Sensor Categories
Environmental Sensors (0x01-0x0F)
- Battery level, temperature, humidity, pressure, illuminance
- Mass measurements, dewpoint, energy, power, voltage
- Air quality sensors (PM2.5, PM10)
Binary Sensors (0x10-0x2D)
- Motion, door/window, occupancy, presence detection
- Safety sensors (smoke, CO, gas, tamper)
- Device state sensors (battery low, charging, connectivity)
Performance Optimizations
This module uses compile-time optimizations to provide O(1) lookups:
@type_to_id_map
- Fast type-to-ID resolution@binary_sensor_types
- Set-based binary sensor detection@supported_types_map
- Efficient type validation
Examples
# Get definition by object ID
iex> BTHome.Objects.get_definition(0x02)
%{name: :temperature, unit: "°C", factor: 0.01, signed: true, size: 2}
# Find by measurement type
iex> BTHome.Objects.find_by_type(:temperature)
{2, %{name: :temperature, unit: "°C", factor: 0.01, signed: true, size: 2}}
# Check if binary sensor
iex> BTHome.Objects.binary_sensor?(:motion)
true
Summary
Functions
Checks if a measurement type is a binary sensor (O(1) lookup).
Finds object ID and definition by measurement type (O(1) lookup).
Returns all object definitions as a map.
Gets object definition by BTHome object ID.
Returns all supported measurement types.
Functions
Checks if a measurement type is a binary sensor (O(1) lookup).
Binary sensors have empty units and 1-byte size, representing boolean states.
Examples
iex> BTHome.Objects.binary_sensor?(:motion)
true
iex> BTHome.Objects.binary_sensor?(:temperature)
false
Finds object ID and definition by measurement type (O(1) lookup).
Returns a tuple of {object_id, definition} or nil if not found.
Examples
iex> BTHome.Objects.find_by_type(:temperature)
{2, %{name: :temperature, unit: "°C", factor: 0.01, signed: true, size: 2}}
iex> BTHome.Objects.find_by_type(:invalid)
nil
@spec get_all_definitions() :: map()
Returns all object definitions as a map.
Examples
iex> definitions = BTHome.Objects.get_all_definitions()
iex> Map.has_key?(definitions, 0x02)
true
Gets object definition by BTHome object ID.
Returns the complete definition including name, unit, factor, signedness, and size.
Examples
iex> BTHome.Objects.get_definition(0x02)
%{name: :temperature, unit: "°C", factor: 0.01, signed: true, size: 2}
iex> BTHome.Objects.get_definition(0xFF)
nil
@spec get_supported_types() :: [atom()]
Returns all supported measurement types.
Examples
iex> types = BTHome.Objects.get_supported_types()
iex> :temperature in types
true