Open rradar opened 5 years ago
I second this request :)
thx
Aggreed I'd like to see this sensor supported too
Yes, it is cheap and popular.
Yes please. Cheap and popular to create meteo stations!
@rradar - Did you figure out any workaround using a Custom I2C component? Custom I2C ?
As a workaround you can use the Custom Sensor component. It works well with other i2c components on the same bus. I only tested the code with an ESP8266.
File: veml6070_custom_sensor.h
#include "esphome.h"
#include "Adafruit_VEML6070.h"
class VEML6070CustomSensor : public PollingComponent, public Sensor {
public:
Adafruit_VEML6070 uv = Adafruit_VEML6070();
VEML6070CustomSensor() : PollingComponent(15000) {}
void setup() override {
Wire.begin();
uv.begin(VEML6070_1_T);
}
void update() override {
uint16_t cur_uv = uv.readUV();
ESP_LOGD("custom", "The value of sensor is: %i", cur_uv);
publish_state(cur_uv);
}
};
Espconfig:
esphome:
name: wetterstation
platform: ESP8266
board: esp01_1m
includes:
- veml6070_custom_sensor.h
libraries:
- "https://github.com/adafruit/Adafruit_VEML6070"
...
i2c:
sda: GPIO5
scl: GPIO4
...
sensor:
- platform: custom
lambda: |-
auto veml6070 = new VEML6070CustomSensor();
App.register_component(veml6070);
return {veml6070};
sensors:
name: "VEML6070 Custom Sensor"
Awesome, thanks! I know this isn't a support forum so I'll try to keep to the topic. I don't think this is the preferred way of integrating new sensors should be integrated into ESPhome? - The ease of customizing ESP's with YAML is why ESPhome is gaining so much traction from any other ESP/Arduino project. Fail rate of similar implementations are just very much higher than "standard" YAML.
I tried the example above and failed as my sensor is reading the value "65535" every single reading.
I have a 7700 (lux sensor). Tried this code and get 65535.
[18:08:42][D][wifi:272]: Starting scan...
[18:08:43][D][custom:015]: The value of sensor is: 65535
[18:08:43][D][sensor:092]: 'VEML6070 Custom Sensor': Sending state 65535.00000 with 0 decimals of accuracy
Don't know if this supposed to work with all the VEML sensors...
I see now it's not. I'll try to adapt it myself and create a new thread.
As a workaround you can use the Custom Sensor component. It works well with other i2c components on the same bus. I only tested the code with an ESP8266.
File: veml6070_custom_sensor.h
#include "esphome.h" #include "Adafruit_VEML6070.h" class VEML6070CustomSensor : public PollingComponent, public Sensor { public: Adafruit_VEML6070 uv = Adafruit_VEML6070(); VEML6070CustomSensor() : PollingComponent(15000) {} void setup() override { Wire.begin(); uv.begin(VEML6070_1_T); } void update() override { uint16_t cur_uv = uv.readUV(); ESP_LOGD("custom", "The value of sensor is: %i", cur_uv); publish_state(cur_uv); } };
Espconfig:
esphome: name: wetterstation platform: ESP8266 board: esp01_1m includes: - veml6070_custom_sensor.h libraries: - "https://github.com/adafruit/Adafruit_VEML6070" ... i2c: sda: GPIO5 scl: GPIO4 ... sensor: - platform: custom lambda: |- auto veml6070 = new VEML6070CustomSensor(); App.register_component(veml6070); return {veml6070}; sensors: name: "VEML6070 Custom Sensor"
What about the VEML6075 will this work around work for this sensor
I have VEML6075 and applied your code, but I also always 65535 but thanks for your sharing and I wish can be applied someday.. ^^
For ESP32:
#include "esphome.h"
#include "Adafruit_VEML6070.h"
#define I2C_SDAa 16
#define I2C_SCLa 33
// you don't need port b
#define I2C_SDAb 21
#define I2C_SCLb 22
TwoWire I2Ca = TwoWire(1);
TwoWire I2Cb = TwoWire(0); // not needed
class VEML6070CustomSensor : public PollingComponent, public Sensor {
public:
Adafruit_VEML6070 uv = Adafruit_VEML6070();
VEML6070CustomSensor() : PollingComponent(15000) {}
void setup() override {
I2Ca.begin(I2C_SDAa,I2C_SCLa,50000);
I2Cb.begin(I2C_SDAb,I2C_SCLb,50000); //not needed
uv.begin(VEML6070_1_T, &I2Ca);
}
void update() override {
uint16_t cur_uv = uv.readUV();
ESP_LOGD("custom", "The value of sensor is: %i", cur_uv);
publish_state(cur_uv);
}
};
- platform: custom
lambda: |-
auto veml6070 = new VEML6070CustomSensor();
App.register_component(veml6070);
return {veml6070};
sensors:
name: "UV"
unit_of_measurement: "mW/m²"
accuracy_decimals: 2
filters:
- delta: 10
- multiply: 0.03
- filter_out: 65535
- lambda: |-
if (x > 600) {
return 0;
} else {
return x;
}
For ESP32:
#include "esphome.h" #include "Adafruit_VEML6070.h" #define I2C_SDAa 16 #define I2C_SCLa 33 #define I2C_SDAb 21 #define I2C_SCLb 22 TwoWire I2Cb = TwoWire(0); TwoWire I2Ca = TwoWire(1); class VEML6070CustomSensor : public PollingComponent, public Sensor { public: Adafruit_VEML6070 uv = Adafruit_VEML6070(); VEML6070CustomSensor() : PollingComponent(15000) {} void setup() override { I2Ca.begin(I2C_SDAa,I2C_SCLa,50000); I2Cb.begin(I2C_SDAb,I2C_SCLb,50000); uv.begin(VEML6070_1_T, &I2Ca); } void update() override { uint16_t cur_uv = uv.readUV(); ESP_LOGD("custom", "The value of sensor is: %i", cur_uv); publish_state(cur_uv); } };
- platform: custom lambda: |- auto veml6070 = new VEML6070CustomSensor(); App.register_component(veml6070); return {veml6070}; sensors: name: "UV" unit_of_measurement: "mW/m²" accuracy_decimals: 2 filters: - delta: 10 - multiply: 0.03 - filter_out: 65535 - lambda: |- if (x > 600) { return 0; } else { return x; }
Why you have
TwoWire I2Cb = TwoWire(0); TwoWire I2Ca = TwoWire(1);
?
You defined two I2C ports ? if yes why ?
Oh I have two I2C devices and I was too lazy to use them on the same I2C port. Wiring was eaysier this way. Of course you need only one.
Oh I have two I2C devices and I was too lazy to use them on the same I2C port. Wiring was eaysier this way. Of course you need only one.
another question
correspond to which GPIO ? GPIO 16 & 33
define SDA on pin GPIO16 und SCL on pin GPIO 33.
define I2C_SDAa 16
define I2C_SCLa 33
define SDA on pin GPIO16 und SCL on pin GPIO 33.
Ok it's working fine now :)
Thanks for sharing
Did anybody ever get this working with the 6075 ? as this is the github library https://github.com/adafruit/Adafruit_VEML6075 and not the one posted above
yes, the VEML6075 works fine. Change the name of the library to github repo and slighly modify the code to read the measurement data.
As VEML6075 can read both of UVA and UVB values, you can publish them as a separate sensor. This is my example using the library SparkFun_VEML6075_Arduino_Library.h
#include "esphome.h"
#include "SparkFun_VEML6075_Arduino_Library.h"
class VEML6075CustomSensor : public PollingComponent, public Sensor {
public:
VEML6075 uv = VEML6075();
Sensor *uva_sensor = new Sensor();
Sensor *uvb_sensor = new Sensor();
VEML6075CustomSensor() : PollingComponent(15000) {}
void setup() override {
Wire.begin();
uv.begin();
uv.setIntegrationTime(VEML6075::IT_100MS);
}
void update() override {
float uva = uv.rawUva();
float uvb = uv.rawUvb();
ESP_LOGD("custom", "The value of sensor uva is: %.0f", uva);
ESP_LOGD("custom", "The value of sensor uvb is: %.0f", uvb);
publish_state(uva);
uva_sensor->publish_state(uva);
uvb_sensor->publish_state(uvb);
}
};
Thanks for this, what is your config in esphome is it the same as posted above ?
espconfig.yaml:
sensor:
- platform: custom
lambda: |-
auto veml6075 = new VEML6075CustomSensor();
App.register_component(veml6075);
return {veml6075->uva_sensor, veml6075->uvb_sensor};
sensors:
- name: "UVA"
id: zelva_uva
unit_of_measurement: "µW/cm²"
accuracy_decimals: 0
- name: "UVB"
id: zelva_uvb
unit_of_measurement: "µW/cm²"
accuracy_decimals: 0
Thanks for that think my sensor is broken as it just keeps on throwing [20:50:35][D][custom:021]: The value of sensor uva is: 65532 [20:50:35][D][custom:022]: The value of sensor uvb is: 65532
Please Mr jirisrba, Would you please also include you head of your ESPhome YAML definition? I'm battling with the includes and libraries part. Currently mine are looking like this:
name: mains_power_meter
platform: ESP8266
board: nodemcuv2
includes:
- customfiles/VEML6075_Arduino_Library.h
libraries:
- "https://github.com/adafruit/Adafruit_VEML6075"
Which is giving me a build error:
In file included from src/VEML6075_Arduino_Library.h:3:0,
from src/main.cpp:22:
.piolibdeps/Adafruit VEML6075 Library/Adafruit_VEML6075.h:22:32: fatal error: Adafruit_I2CDevice.h: No such file or directory
****************************************************************************
* Looking for Adafruit_I2CDevice.h dependency? Check our library registry!
*
* CLI > platformio lib search "header:Adafruit_I2CDevice.h"
* Web > https://platformio.org/lib/search?query=header:Adafruit_I2CDevice.h
*
****************************************************************************
#include <Adafruit_I2CDevice.h>
^
compilation terminated.
*** [.pioenvs/mains_power_meter/src/main.cpp.o] Error 1
I tested two VEML6075 libraries
Both of them works fine. My example above was from SparkFun.
This is my full configuration and Custom Sensor class prepared on D1 Wemos from Adafruit_VEML6075 repo:
veml6075_custom_sensor.h:
#include "esphome.h"
#include "Adafruit_VEML6075.h"
class VEML6075CustomSensor : public PollingComponent, public Sensor {
public:
Adafruit_VEML6075 uv = Adafruit_VEML6075();
Sensor *uva_sensor = new Sensor();
Sensor *uvb_sensor = new Sensor();
VEML6075CustomSensor() : PollingComponent(15000) {}
void setup() override {
Wire.begin();
uv.begin();
uv.setIntegrationTime(VEML6075_100MS);
}
void update() override {
float uva = uv.readUVA();
float uvb = uv.readUVB();
ESP_LOGD("custom", "The value of sensor uva is: %.0f", uva);
ESP_LOGD("custom", "The value of sensor uvb is: %.0f", uvb);
publish_state(uva);
uva_sensor->publish_state(uva);
uvb_sensor->publish_state(uvb);
}
};
espconfig.yaml:
esphome:
name: ${esphome_name}
platform: ESP8266
board: d1_mini
includes:
- veml6075_custom_sensor.h
libraries:
- "https://github.com/adafruit/Adafruit_VEML6075"
i2c:
- sda: D2
scl: D1
scan: True
sensor:
- platform: custom
lambda: |-
auto veml6075 = new VEML6075CustomSensor();
App.register_component(veml6075);
return {veml6075->uva_sensor, veml6075->uvb_sensor};
sensors:
- name: "zelva UVA"
id: zelva_uva
unit_of_measurement: "mW/cm²"
accuracy_decimals: 0
- name: "zelva UVB"
id: zelva_uvb
unit_of_measurement: "mW/cm²"
accuracy_decimals: 0
Note that I'm not sure about the units of UVA and UVB measurements .. maybe I am wrong.
Anybody managed to tweak this sensor to be waterproof ?
libraries:
I was lucky with your config @jirisrba so thank you very much! However, I had to make a little tweak to your YAML definition:
includes:
- VEML6075_Arduino_Library.h
libraries:
- "https://github.com/adafruit/Adafruit_VEML6075"
- "https://github.com/adafruit/Adafruit_BusIO"
Observe the last library added! I tried both in the ESPhome container as well as desktop (Mac OS) without success but working on both with that last library added!
@SeByDocKy: I just melted a lot of hotglue on to it... I'm waiting for some light to show readings and see if this actually works!
I used some sillicone on a VEML6070..... unfortunatly the sensor died after the first rain..... the mems sensor didn't like :( ... I iordered e VEML6075 now thanks to your work :)
libraries:
I was lucky with your config @jirisrba so thank you very much! However, I had to make a little tweak to your YAML definition:
includes: - VEML6075_Arduino_Library.h libraries: - "https://github.com/adafruit/Adafruit_VEML6075" - "https://github.com/adafruit/Adafruit_BusIO"
Observe the last library added! I tried both in the ESPhome container as well as desktop (Mac OS) without success but working on both with that last library added!
@SeByDocKy: I just melted a lot of hotglue on to it... I'm waiting for some light to show readings and see if this actually works!
Thanks this works with @jirisrba config combined it is showing readings
@Nornode Did u get the correct readings ? As mine just shows 440 mW/cm² or over 1000 mW/cm² not the uv rating as shown in this link https://learn.adafruit.com/adafruit-veml6075-uva-uvb-uv-index-sensor/arduino-test not shure if we have to add something else i see this is the arduino code, unfortunately i dont know anything about coding so im not sure at what i am looking at
* @file veml6075_fulltest.ino
*
* A complete test of the library API with various settings available
*
* Designed specifically to work with the VEML6075 sensor from Adafruit
* ----> https://www.adafruit.com/products/3964
*
* These sensors use I2C to communicate, 2 pins (SCL+SDA) are required
* to interface with the breakout.
*
* Adafruit invests time and resources providing this open source code,
* please support Adafruit and open-source hardware by purchasing
* products from Adafruit!
*
* Written by Limor Fried/Ladyada for Adafruit Industries.
*
* MIT license, all text here must be included in any redistribution.
*
*/
#include <Wire.h>
#include "Adafruit_VEML6075.h"
Adafruit_VEML6075 uv = Adafruit_VEML6075();
// Set the integration constant
uv.setIntegrationTime(VEML6075_100MS);
// Get the integration constant and print it!
Serial.print("Integration time set to ");
switch (uv.getIntegrationTime()) {
case VEML6075_50MS: Serial.print("50"); break;
case VEML6075_100MS: Serial.print("100"); break;
case VEML6075_200MS: Serial.print("200"); break;
case VEML6075_400MS: Serial.print("400"); break;
case VEML6075_800MS: Serial.print("800"); break;
}
Serial.println("ms");
// Set the high dynamic mode
uv.setHighDynamic(true);
// Get the mode
if (uv.getHighDynamic()) {
Serial.println("High dynamic reading mode");
} else {
Serial.println("Normal dynamic reading mode");
}
// Set the mode
uv.setForcedMode(false);
// Get the mode
if (uv.getForcedMode()) {
Serial.println("Forced reading mode");
} else {
Serial.println("Continuous reading mode");
}
// 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 loop() {
Serial.print("Raw UVA reading: "); Serial.println(uv.readUVA());
Serial.print("Raw UVB reading: "); Serial.println(uv.readUVB());
Serial.print("UV Index reading: "); Serial.println(uv.readUVI());
delay(1000)```
Yeah, looking at the sensor values it spits out now, it's not really looking correct. It might just be me, don't knowing UAx readings, but how can it be negative?
This is my Grafana output: Image link (UVA & UVB seems to be identical)
@jirisrba Where are you located and do you have similar readings?
@Nornode the VEML6075 sensor is located inside the terrarium close to the UVB lamp. The measurement generates a positive numbers between 100 and 500.
@Nornode the VEML6075 sensor is located inside the terrarium close to the UVB lamp. The measurement generates a positive numbers between 100 and 500.
Just out of curiosity what UVB lamp do you have and what is your readings? Thanks!
Just out of curiosity what UVB lamp do you have and what is your readings? Thanks!
I got mine outside... Values depend on the weather and the position of the sensor. It tops put at approximately 8000 mw/cm2.
Just out of curiosity what UVB lamp do you have and what is your readings? Thanks!
I got mine outside... Values depend on the weather and the position of the sensor. It tops put at approximately 8000 mw/cm2.
how you waterproofed it ?
Just out of curiosity what UVB lamp do you have and what is your readings? Thanks!
I got mine outside... Values depend on the weather and the position of the sensor. It tops put at approximately 8000 mw/cm2.
OMG despite i've quoted the right guy above, now i noticed it didn't pinned the right name. 😆 @jirisrba
@Nornode Thanks but the problem is for me that my VEML6075's readings look overall ok but according to my testing with UV lamp (with known specs) at least UVB part doesn't correspond. Readings from outside is kinda useless to determine whether it measures ok, no offense.
@Shamshala
Readings from outside is kinda useless to determine whether it measures ok, no offense.
No need to point that out. Everyone's use is as good as any. I'm not using it for exact values anyway.
Trying to compile for ESP8266 with ESPHome 2022.04 and results in error:
Compiling /data/sensors-padlas/.pioenvs/sensors-padlas/lib8b5/Adafruit VEML6070 Library/Adafruit_VEML6070.cpp.o
/data/sensors-padlas/.piolibdeps/sensors-padlas/Adafruit VEML6070 Library/Adafruit_VEML6070.cpp:36:10: fatal error: Wire.h: No such file or directory
**************************************************************
* Looking for Wire.h dependency? Check our library registry!
*
* CLI > platformio lib search "header:Wire.h"
* Web > https://registry.platformio.org/search?q=header:Wire.h
*
**************************************************************
36 | #include "Wire.h"
| ^~~~~~~~
compilation terminated.
*** [/data/sensors-padlas/.pioenvs/sensors-padlas/lib8b5/Adafruit VEML6070 Library/Adafruit_VEML6070.cpp.o] Error 1
========================= [FAILED] Took 53.48 seconds =========================
Tried adding:
libraries:
- "https://github.com/adafruit/Adafruit_VEML6070"
- "https://github.com/adafruit/Adafruit_BusIO"
- "https://github.com/esp8266/Arduino"
No successs.
OK found the problem, it's caused by https://github.com/esphome/esphome/pull/2608. For ESP8266 the currently correct configuration needs this, in order to compile:
libraries:
- Wire
- "https://github.com/adafruit/Adafruit_VEML6070"
Anybody managed to tweak this sensor to be waterproof ?
Boxed together with a BH1750 in a car side light fixture.
It's up on the roof for more than 2 years now.
Anybody managed to tweak this sensor to be waterproof ?
Boxed together with a BH1750 in a car side light fixture.
It's up on the roof for more than 2 years now.
![]()
![]()
![]()
![]()
![]()
Very interesting packaging.... I was sure that UV would be block by the transparent covert.... but seems not the case
Well I'm sure it affects the measurement a bit (I think less than 1%), but certainly doesn't block it. Usually UV blocking transparent parts are specially designed to do that and usually cost more. If you choose the cheapest product, that will 99.9% NOT blocking UV.
Here's my working config on a Wemos D1 with a lambda to filter out sudden value decreases due to clouds passing by within 30 minutes. Also text sensors providing level and warning.
sensor:
- platform: template
name: last_good_value
id: last_good_value
icon: "mdi:memory"
entity_category: diagnostic
state_class: measurement
disabled_by_default: true
- platform: template
name: counter
id: counter
icon: "mdi:memory"
entity_category: diagnostic
state_class: measurement
disabled_by_default: true
- platform: custom
lambda: |-
auto veml6070 = new VEML6070CustomSensor();
App.register_component(veml6070);
return {veml6070};
sensors:
name: "UV Index"
icon: "mdi:sun-wireless-outline"
id: uvindex
accuracy_decimals: 1
state_class: "measurement"
filters:
- filter_out: 65535
- heartbeat: 60s
- multiply: 0.0102 # based on trial and error, result compared to official meteorology institute public values
- lambda: |- # filter out sudden value decreases due to clouds passing by within 30 minutes
if (id(counter).state < 30 && id(last_good_value).state != 0 && (id(last_good_value).state - x) >= 0.6) {
id(counter).publish_state(id(counter).state + 1);
return {};
}
id(last_good_value).publish_state(x);
id(counter).publish_state(0);
return x;
on_value:
then:
- if:
condition:
lambda: 'return ( (x < 0.1) );'
then:
- text_sensor.template.publish:
id: text_uv_level
state: "None"
- text_sensor.template.publish:
id: text_uv_warn
state: "No measurable value"
- if:
condition:
lambda: 'return ( (x >= 0.1) && (x <= 2.9) );' # "Low" = sun->fun
then:
- text_sensor.template.publish:
id: text_uv_level
state: "Low"
- text_sensor.template.publish:
id: text_uv_warn
state: "Not dangerous"
- if:
condition:
lambda: 'return ( (x >= 3.0) && (x <= 4.9) );' # "Mid" = sun->glases advised
then:
- text_sensor.template.publish:
id: text_uv_level
state: "Mid"
- text_sensor.template.publish:
id: text_uv_warn
state: "Sunglasses recommended"
- if:
condition:
lambda: 'return ( (x >= 5.0) && (x <= 6.9) );' # "High" = sun->glases a must
then:
- text_sensor.template.publish:
id: text_uv_level
state: "High"
- text_sensor.template.publish:
id: text_uv_warn
state: "Sunglasses needed, skin protection recommended"
- if:
condition:
lambda: 'return ( (x >= 7.0) && (x <= 7.9) );' # "Danger" = sun->skin burns Level 1
then:
- text_sensor.template.publish:
id: text_uv_level
state: "Very high"
- text_sensor.template.publish:
id: text_uv_warn
state: "Skin burn 1 degree"
- if:
condition:
lambda: 'return ( (x >= 8.0) && (x <= 25.0) );' # "BurnL1/2" = sun->skin burns level 1..2
then:
- text_sensor.template.publish:
id: text_uv_level
state: "Danger!"
- text_sensor.template.publish:
id: text_uv_warn
state: "Skin burn 2-3 degree"
- if:
condition:
lambda: 'return ( (x > 25) );' # "OoR" = out of range or unknown
then:
- text_sensor.template.publish:
id: text_uv_level
state: "Error"
- text_sensor.template.publish:
id: text_uv_warn
state: "Sensor error, or outer space"
text_sensor:
- platform: template
name: "UV Level"
icon: "mdi:weather-sunny-alert"
id: text_uv_level
- platform: template
name: "UV Warning"
icon: "mdi:weather-sunny-alert"
id: text_uv_warn
- multiply: 0.03
Hello. Based on what data do you apply the multiplication by 0.03?
https://github.com/adafruit/Adafruit_VEML6075/blob/master/Adafruit_VEML6075.h
I would use VEML7700 for ambient light. The range is from 0 - 120 lux. The resolution is 0.0036 lx/ct (Lux per count) I would use ML8511 for differenciation between UVA and UVB. There is a multifunctional sensor 5 in one from Adafruit, which is doing it: https://www.dfrobot.com/product-2522.html It will work with UART or I2C and gives you the values in mW/m2 for UVA and UVB
Describe the problem you have/What new integration you would like
VEML6075 and VEML6070 Support. The VEML6075 is preferred as it's the successor of the 6070 version
Please describe your use case for this integration and alternatives you've tried:
Measure UVA & UVB
Additional context
https://github.com/adafruit/Adafruit_VEML6075
https://www.adafruit.com/product/3964
https://github.com/adafruit/Adafruit_VEML6070
https://www.adafruit.com/products/2899