Wetterstation v2
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.3 KiB

3 years ago
#include "esphome.h"
#include <Wire.h>
3 years ago
#include "Adafruit_VEML6075.h"
class VEML6075CustomSensor : public PollingComponent {
3 years ago
public:
Adafruit_VEML6075 uv = Adafruit_VEML6075();
Sensor *uva_sensor = new Sensor();
Sensor *uvb_sensor = new Sensor();
Sensor *uvi_sensor = new Sensor();
3 years ago
VEML6075CustomSensor() : PollingComponent(15000) {}
float get_setup_priority() const override { return esphome::setup_priority::HARDWARE; }
3 years ago
void setup() override {
3 years ago
//Wire.begin(21, 22);
if (!uv.begin()) {
ESP_LOGE("custom", "VEML6075 init failed");
this->mark_failed();
return;
}
3 years ago
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
3 years ago
}
void update() override {
float uva = uv.readUVA();
float uvb = uv.readUVB();
float uvi = uv.readUVI();
3 years ago
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);
3 years ago
}
};