|
|
|
#include "esphome.h"
|
|
|
|
#include <Wire.h>
|
|
|
|
#include "Adafruit_VEML6075.h"
|
|
|
|
|
|
|
|
class VEML6075CustomSensor : public PollingComponent {
|
|
|
|
public:
|
|
|
|
Adafruit_VEML6075 uv = Adafruit_VEML6075();
|
|
|
|
|
|
|
|
Sensor *uva_sensor = new Sensor();
|
|
|
|
Sensor *uvb_sensor = new Sensor();
|
|
|
|
Sensor *uvi_sensor = new Sensor();
|
|
|
|
|
|
|
|
VEML6075CustomSensor() : PollingComponent(15000) {}
|
|
|
|
|
|
|
|
float get_setup_priority() const override { return esphome::setup_priority::HARDWARE; }
|
|
|
|
|
|
|
|
void setup() override {
|
|
|
|
//Wire.begin(21, 22);
|
|
|
|
if (!uv.begin()) {
|
|
|
|
ESP_LOGE("custom", "VEML6075 init failed");
|
|
|
|
this->mark_failed();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
uv.setIntegrationTime(VEML6075_100MS);
|
|
|
|
//uv.setHighDynamic(true);
|
|
|
|
|
|
|
|
// Set the calibration coefficients
|
|
|
|
uv.setCoefficients(2.22, 1.33, // UVA_A and UVA_B coefficients
|
|
|
|
2.95, 1.74, // UVB_C and UVB_D coefficients
|
|
|
|
0.001461, 0.002591); // UVA and UVB responses
|
|
|
|
}
|
|
|
|
|
|
|
|
void update() override {
|
|
|
|
float uva = uv.readUVA();
|
|
|
|
float uvb = uv.readUVB();
|
|
|
|
float uvi = uv.readUVI();
|
|
|
|
ESP_LOGD("custom", "The value of sensor uva is: %.0f", uva);
|
|
|
|
ESP_LOGD("custom", "The value of sensor uvb is: %.0f", uvb);
|
|
|
|
uva_sensor->publish_state(uva);
|
|
|
|
uvb_sensor->publish_state(uvb);
|
|
|
|
uvi_sensor->publish_state(uvi);
|
|
|
|
}
|
|
|
|
};
|