BH1750 Ambient Light Sensor

The BH1750 sensor allows you to use your BH1750 i2c-enabled ambient light sensor with esphomelib (datasheet). It requires i2c to be setup to work.

Example Usage

// Basic
auto bh1750 = App.make_bh1750_sensor("BH1750 Illuminance");

// Advanced settings
// default resolution is 0.5 LX

See Application::make_bh1750_sensor().

API Reference

class BH1750Sensor : public sensor::PollingSensorComponent, public I2CDevice

This class implements support for the i2c-based BH1750 ambient light sensor.

Public Functions

BH1750Sensor(I2CComponent *parent, const std::string &name, uint8_t address = 0x23, uint32_t update_interval = 15000)
void set_resolution(BH1750Resolution resolution)

Set the resolution of this sensor.

Possible values are:

  • BH1750_RESOLUTION_0P5_LX (default)

  • resolution: The new resolution of the sensor.

void setup()

Where the component’s initialization should happen.

Analogous to Arduino’s setup(). This method is guaranteed to only be called once. Defaults to doing nothing.

void dump_config()
void update()
float get_setup_priority() const

priority of setup().

higher -> executed earlier

Defaults to 0.

The setup priority of this component

std::string unit_of_measurement()

Override this to set the Home Assistant unit of measurement for this sensor.

Return “” to disable this feature.

The icon of this sensor, for example “°C”.

std::string icon()

Override this to set the Home Assistant icon for this sensor.

Return “” to disable this feature.

The icon of this sensor, for example “mdi:battery”.

int8_t accuracy_decimals()

Return the accuracy in decimals for this sensor.

Protected Functions

void read_data_()

Protected Attributes

BH1750Resolution resolution_ = {BH1750_RESOLUTION_0P5_LX}
enum sensor::BH1750Resolution

Enum listing all resolutions that can be used with the BH1750.


BH1750_RESOLUTION_4P0_LX = 0b00100011
BH1750_RESOLUTION_1P0_LX = 0b00100000
BH1750_RESOLUTION_0P5_LX = 0b00100001