ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
tsl2591.h
Go to the documentation of this file.
1#pragma once
2
6
7#include <cinttypes>
8
9namespace esphome::tsl2591 {
10
24
37
44 TSL2591_GAIN_LOW = 0b00 << 4, // 1x
45 TSL2591_GAIN_MED = 0b01 << 4, // 25x
46 TSL2591_GAIN_HIGH = 0b10 << 4, // 400x
47 TSL2591_GAIN_MAX = 0b11 << 4, // 9500x
48};
49
59
66class TSL2591Component final : public PollingComponent, public i2c::I2CDevice {
67 public:
100
115
120 void set_name(const char *name) { this->name_ = name; }
121
144 void set_device_and_glass_attenuation_factors(float device_factor, float glass_attenuation_factor);
145
151 float get_calculated_lux(uint16_t full_spectrum, uint16_t infrared);
152
162
176 uint16_t get_illuminance(TSL2591SensorChannel channel);
177
188 uint16_t get_illuminance(TSL2591SensorChannel channel, uint32_t combined_illuminance);
189
201 bool is_adc_valid();
202
208 void enable();
215 void disable();
216
221 void automatic_gain_update(uint16_t full_spectrum);
222
227 float get_actual_gain();
228
229 // ========== INTERNAL METHODS ==========
230 // (In most use cases you won't need these. They're for ESPHome integration use.)
232 SUB_SENSOR(full_spectrum)
234 SUB_SENSOR(actual_gain)
236 SUB_SENSOR(infrared)
238 SUB_SENSOR(visible)
240 SUB_SENSOR(calculated_lux)
242 void set_integration_time(TSL2591IntegrationTime integration_time);
246 void setup() override;
248 void dump_config() override;
250 void update() override;
251
252 protected:
253 const char *name_;
263 void process_update_();
265};
266
267} // namespace esphome::tsl2591
This class simplifies creating components that periodically check a state.
Definition component.h:532
This Class provides the methods to read/write bytes from/to an i2c device.
Definition i2c.h:144
This class includes support for the TSL2591 i2c ambient light sensor.
Definition tsl2591.h:66
TSL2591IntegrationTime integration_time_
Definition tsl2591.h:254
void dump_config() override
Used by ESPHome framework.
Definition tsl2591.cpp:73
TSL2591ComponentGain component_gain_
Definition tsl2591.h:255
void automatic_gain_update(uint16_t full_spectrum)
Updates the gain setting based on the most recent full spectrum reading.
Definition tsl2591.cpp:371
bool is_adc_valid()
Are the device ADC values valid?
Definition tsl2591.cpp:204
float get_calculated_lux(uint16_t full_spectrum, uint16_t infrared)
Calculates and returns a lux value based on the ADC readings.
Definition tsl2591.cpp:307
void set_device_and_glass_attenuation_factors(float device_factor, float glass_attenuation_factor)
Sets the device and glass attenuation factors.
Definition tsl2591.cpp:182
uint32_t get_combined_illuminance()
Get the combined illuminance value.
Definition tsl2591.cpp:213
void set_name(const char *name)
Sets the name for this instance of the device.
Definition tsl2591.h:120
SUB_SENSOR(full_spectrum) SUB_SENSOR(actual_gain) SUB_SENSOR(infrared) SUB_SENSOR(visible) SUB_SENSOR(calculated_lux) void set_integration_time(TSL2591IntegrationTime integration_time)
Used by ESPHome framework.
void set_gain(TSL2591ComponentGain gain)
Used by ESPHome framework.
Definition tsl2591.h:244
void enable()
Powers on the TSL2591 device and enables its sensors.
Definition tsl2591.cpp:28
void update() override
Used by ESPHome framework.
Definition tsl2591.cpp:161
void set_integration_time_and_gain(TSL2591IntegrationTime integration_time, TSL2591Gain gain)
Set device integration time and gain.
Definition tsl2591.cpp:187
void disable()
Powers off the TSL2591 device.
Definition tsl2591.cpp:35
float get_actual_gain()
Reads the actual gain used.
Definition tsl2591.cpp:416
uint16_t get_illuminance(TSL2591SensorChannel channel)
Get an individual sensor channel reading.
Definition tsl2591.cpp:270
void setup() override
Used by ESPHome framework.
Definition tsl2591.cpp:47
void set_power_save_mode(bool enable)
Should the device be powered down between readings?
Definition tsl2591.h:114
AlsGain501 gain
IntegrationTime501 integration_time
TSL2591Gain
Enum listing all gain settings for the TSL2591.
Definition tsl2591.h:43
TSL2591ComponentGain
Enum listing all gain settings for the TSL2591 component.
Definition tsl2591.h:30
TSL2591IntegrationTime
Enum listing all conversion/integration time settings for the TSL2591.
Definition tsl2591.h:16
@ TSL2591_INTEGRATION_TIME_500MS
Definition tsl2591.h:21
@ TSL2591_INTEGRATION_TIME_600MS
Definition tsl2591.h:22
@ TSL2591_INTEGRATION_TIME_100MS
Definition tsl2591.h:17
@ TSL2591_INTEGRATION_TIME_200MS
Definition tsl2591.h:18
@ TSL2591_INTEGRATION_TIME_300MS
Definition tsl2591.h:19
@ TSL2591_INTEGRATION_TIME_400MS
Definition tsl2591.h:20
TSL2591SensorChannel
Enum listing sensor channels.
Definition tsl2591.h:54
@ TSL2591_SENSOR_CHANNEL_INFRARED
Definition tsl2591.h:56
@ TSL2591_SENSOR_CHANNEL_VISIBLE
Definition tsl2591.h:55
@ TSL2591_SENSOR_CHANNEL_FULL_SPECTRUM
Definition tsl2591.h:57
static void uint32_t