Add VEML7700
This commit is contained in:
parent
860bd1a36d
commit
544a055df9
@ -28,6 +28,14 @@ esphome:
|
|||||||
name: supersensor
|
name: supersensor
|
||||||
name_add_mac_suffix: true
|
name_add_mac_suffix: true
|
||||||
friendly_name: "Supersensor"
|
friendly_name: "Supersensor"
|
||||||
|
includes:
|
||||||
|
- veml7700.h
|
||||||
|
libraries:
|
||||||
|
- "Wire"
|
||||||
|
- "Adafruit Unified Sensor"
|
||||||
|
- "SPI"
|
||||||
|
- "Adafruit BusIO"
|
||||||
|
- "Adafruit VEML7700 Library"
|
||||||
on_boot:
|
on_boot:
|
||||||
- priority: 600
|
- priority: 600
|
||||||
then:
|
then:
|
||||||
@ -52,17 +60,17 @@ esphome:
|
|||||||
|
|
||||||
esp32:
|
esp32:
|
||||||
board: esp32dev
|
board: esp32dev
|
||||||
framework:
|
# framework:
|
||||||
type: esp-idf
|
# type: esp-idf
|
||||||
sdkconfig_options:
|
# sdkconfig_options:
|
||||||
CONFIG_ESP32_DEFAULT_CPU_FREQ_240: "y"
|
# CONFIG_ESP32_DEFAULT_CPU_FREQ_240: "y"
|
||||||
CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ: "240"
|
# CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ: "240"
|
||||||
CONFIG_ESP32_DATA_CACHE_64KB: "y"
|
# CONFIG_ESP32_DATA_CACHE_64KB: "y"
|
||||||
CONFIG_ESP32_DATA_CACHE_LINE_64B: "y"
|
# CONFIG_ESP32_DATA_CACHE_LINE_64B: "y"
|
||||||
CONFIG_ESP32S3_DEFAULT_CPU_FREQ_240: "y"
|
# CONFIG_ESP32S3_DEFAULT_CPU_FREQ_240: "y"
|
||||||
CONFIG_ESP32S3_DEFAULT_CPU_FREQ_MHZ: "240"
|
# CONFIG_ESP32S3_DEFAULT_CPU_FREQ_MHZ: "240"
|
||||||
CONFIG_ESP32S3_DATA_CACHE_64KB: "y"
|
# CONFIG_ESP32S3_DATA_CACHE_64KB: "y"
|
||||||
CONFIG_ESP32S3_DATA_CACHE_LINE_64B: "y"
|
# CONFIG_ESP32S3_DATA_CACHE_LINE_64B: "y"
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- id: pir_handler
|
- id: pir_handler
|
||||||
@ -236,6 +244,7 @@ binary_sensor:
|
|||||||
internal: false
|
internal: false
|
||||||
device_class: motion
|
device_class: motion
|
||||||
on_press:
|
on_press:
|
||||||
|
- script.stop: pir_handler
|
||||||
- script.execute: pir_handler
|
- script.execute: pir_handler
|
||||||
|
|
||||||
- platform: template
|
- platform: template
|
||||||
@ -259,24 +268,36 @@ sensor:
|
|||||||
name: "BMP280 Temperature"
|
name: "BMP280 Temperature"
|
||||||
pressure:
|
pressure:
|
||||||
name: "BMP280 Pressure"
|
name: "BMP280 Pressure"
|
||||||
update_interval: 15s
|
update_interval: 5s
|
||||||
address: 0x76
|
address: 0x76
|
||||||
|
|
||||||
- platform: bh1750
|
- platform: custom
|
||||||
name: "BH1750 Illuminance"
|
lambda: |-
|
||||||
address: 0x23
|
auto veml7700 = new VEML7700CustomSensor();
|
||||||
update_interval: 15s
|
App.register_component(veml7700);
|
||||||
|
return {veml7700, veml7700->lux_sensor, veml7700->white_sensor, veml7700->als_sensor};
|
||||||
|
sensors:
|
||||||
|
- name: "VEML7700 Light" # Required dummy sensor
|
||||||
|
- name: "VEML7700 Lux"
|
||||||
|
unit_of_measurement: Lux
|
||||||
|
accuracy_decimals: 0
|
||||||
|
- name: "VEML7700 White"
|
||||||
|
unit_of_measurement: raw
|
||||||
|
accuracy_decimals: 0
|
||||||
|
- name: "VEML7700 ALS"
|
||||||
|
unit_of_measurement: raw
|
||||||
|
accuracy_decimals: 0
|
||||||
|
|
||||||
- platform: uptime
|
- platform: uptime
|
||||||
name: "ESP32 Uptime"
|
name: "ESP32 Uptime"
|
||||||
icon: mdi:clock-alert
|
icon: mdi:clock-alert
|
||||||
update_interval: 15s
|
update_interval: 5s
|
||||||
entity_category: "diagnostic"
|
entity_category: "diagnostic"
|
||||||
|
|
||||||
- platform: wifi_signal
|
- platform: wifi_signal
|
||||||
name: "ESP32 WiFi RSSI"
|
name: "ESP32 WiFi RSSI"
|
||||||
icon: mdi:wifi-strength-2
|
icon: mdi:wifi-strength-2
|
||||||
update_interval: 15s
|
update_interval: 5s
|
||||||
entity_category: "diagnostic"
|
entity_category: "diagnostic"
|
||||||
|
|
||||||
- platform: internal_temperature
|
- platform: internal_temperature
|
||||||
@ -284,7 +305,7 @@ sensor:
|
|||||||
icon: mdi:thermometer
|
icon: mdi:thermometer
|
||||||
unit_of_measurement: °C
|
unit_of_measurement: °C
|
||||||
device_class: TEMPERATURE
|
device_class: TEMPERATURE
|
||||||
update_interval: 15s
|
update_interval: 5s
|
||||||
entity_category: "diagnostic"
|
entity_category: "diagnostic"
|
||||||
|
|
||||||
- platform: template
|
- platform: template
|
||||||
@ -292,7 +313,7 @@ sensor:
|
|||||||
icon: mdi:cpu-32-bit
|
icon: mdi:cpu-32-bit
|
||||||
accuracy_decimals: 1
|
accuracy_decimals: 1
|
||||||
unit_of_measurement: MHz
|
unit_of_measurement: MHz
|
||||||
update_interval: 15s
|
update_interval: 5s
|
||||||
lambda: |-
|
lambda: |-
|
||||||
return ets_get_cpu_frequency();
|
return ets_get_cpu_frequency();
|
||||||
entity_category: "diagnostic"
|
entity_category: "diagnostic"
|
||||||
@ -302,7 +323,7 @@ sensor:
|
|||||||
icon: mdi:memory
|
icon: mdi:memory
|
||||||
unit_of_measurement: 'kB'
|
unit_of_measurement: 'kB'
|
||||||
state_class: measurement
|
state_class: measurement
|
||||||
update_interval: 15s
|
update_interval: 5s
|
||||||
lambda: |-
|
lambda: |-
|
||||||
return heap_caps_get_free_size(MALLOC_CAP_INTERNAL) / 1024;
|
return heap_caps_get_free_size(MALLOC_CAP_INTERNAL) / 1024;
|
||||||
entity_category: "diagnostic"
|
entity_category: "diagnostic"
|
||||||
|
39
veml7700.h
Normal file
39
veml7700.h
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
#include "esphome.h"
|
||||||
|
#include <Adafruit_VEML7700.h>
|
||||||
|
|
||||||
|
// Requires this lib installed: $ platformio lib --global install "Adafruit BusIO"
|
||||||
|
// based on https://github.com/adafruit/Adafruit_VEML7700/blob/master/examples/veml7700_test/veml7700_test.ino
|
||||||
|
|
||||||
|
class VEML7700CustomSensor : public PollingComponent, public Sensor {
|
||||||
|
public:
|
||||||
|
Adafruit_VEML7700 veml = Adafruit_VEML7700();
|
||||||
|
|
||||||
|
Sensor *lux_sensor = new Sensor();
|
||||||
|
Sensor *white_sensor = new Sensor();
|
||||||
|
Sensor *als_sensor = new Sensor();
|
||||||
|
|
||||||
|
VEML7700CustomSensor() : PollingComponent(15000) {}
|
||||||
|
void setup() override {
|
||||||
|
Wire.begin();
|
||||||
|
veml.begin();
|
||||||
|
veml.setGain(VEML7700_GAIN_1);
|
||||||
|
veml.setIntegrationTime(VEML7700_IT_800MS);
|
||||||
|
// veml.powerSaveEnable(true);
|
||||||
|
// veml.setPowerSaveMode(VEML7700_POWERSAVE_MODE4);
|
||||||
|
// veml.setLowThreshold(10000);
|
||||||
|
// veml.setHighThreshold(20000);
|
||||||
|
// veml.interruptEnable(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void update() override {
|
||||||
|
float lux = veml.readLux();
|
||||||
|
float white = veml.readWhite();
|
||||||
|
float als = veml.readALS();
|
||||||
|
ESP_LOGD("VEML7700", "The value of sensor lux is: %.0f", lux);
|
||||||
|
ESP_LOGD("VEML7700", "The value of sensor white is: %.0f", white);
|
||||||
|
ESP_LOGD("VEML7700", "The value of sensor ALS is: %.0f", als);
|
||||||
|
lux_sensor->publish_state(lux);
|
||||||
|
white_sensor->publish_state(white);
|
||||||
|
als_sensor->publish_state(als);
|
||||||
|
}
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user