Skip to content

Instantly share code, notes, and snippets.

@NateEaton
Last active April 6, 2024 02:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NateEaton/995b6e497352345f679dfda1beb2a2da to your computer and use it in GitHub Desktop.
Save NateEaton/995b6e497352345f679dfda1beb2a2da to your computer and use it in GitHub Desktop.
Data Collection Components for Total Solar Eclipse using ESPHOME and Home Assistant
esphome:
name: light-measurement
friendly_name: light-measurement
esp32:
board: esp32dev
framework:
type: arduino
# Enable logging
logger:
level: DEBUG
# Enable Home Assistant API
api:
encryption:
key: "[private]"
ota:
password: "[private]"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Light-Measurement"
password: "[private]"
captive_portal:
time:
- platform: homeassistant
id: homeassistant_time
i2c:
# I2C Bus A configuration for AS7341
- id: bus_a
sda: 21
scl: 22
scan: true
# I2C Bus B configuration for TSL2591
- id: bus_b
sda: 18
scl: 19
scan: true
sensor:
# AS7341 sensor definition
- platform: as7341
id: as7341_spectrum
i2c_id: bus_a
update_interval: never
gain: X8
astep: 599
atime: 29
f1:
name: "415nm"
f2:
name: "445nm"
f3:
name: "480nm"
f4:
name: "515nm"
f5:
name: "555nm"
f6:
name: "590nm"
f7:
name: "630nm"
f8:
name: "680nm"
clear:
name: "Clear"
nir:
name: "NIR"
# TSL2591 sensor definition
- platform: tsl2591
id: tsl2591_light_level
i2c_id: bus_b
address: 0x29
update_interval: never
gain: auto
device_factor: 53
glass_attenuation_factor: 14.4
visible:
name: "Visible Light"
id: visible_light
infrared:
name: "Infrared Light"
id: infrared_light
full_spectrum:
name: "Full Spectrum Light"
id: full_spectrum_light
calculated_lux:
name: "Lux"
id: i_lux
actual_gain:
name: "Actual Gain"
id: actual_gain
- platform: wifi_signal # Reports the WiFi signal strength/RSSI in dB
name: "WiFi Signal dB"
id: wifi_signal_db
update_interval: 60s
entity_category: "diagnostic"
- platform: copy # Reports the WiFi signal strength in %
name: "WiFi Signal Percent"
source_id: wifi_signal_db
filters:
- lambda: return min(max(2 * (x + 100.0), 0.0), 100.0);
unit_of_measurement: "Signal %"
entity_category: "diagnostic"
- platform: uptime
name: "Uptime"
update_interval: 60s
entity_category: "diagnostic"
binary_sensor:
- platform: template
name: "High Speed Update"
id: high_speed_update
lambda: |-
return id(high_speed_update).state;
- platform: status
name: "Connectivity Status"
id: connectivity_status
device_class: connectivity
switch:
- platform: template
name: "High Speed Update Switch"
restore_mode: ALWAYS_OFF
lambda: |-
return id(high_speed_update).state;
turn_on_action:
- binary_sensor.template.publish:
id: high_speed_update
state: ON
- logger.log: High Speed Update Switched On
turn_off_action:
- binary_sensor.template.publish:
id: high_speed_update
state: OFF
- logger.log: High Speed Update Switched Off
interval:
- interval: 1min
then:
- if:
condition:
lambda: 'return not id(high_speed_update).state;'
then:
- component.update: tsl2591_light_level
#- delay: 50ms
- component.update: as7341_spectrum
- interval: 1sec
then:
- if:
condition:
lambda: 'return id(high_speed_update).state;'
then:
- component.update: tsl2591_light_level
#- delay: 50ms
- component.update: as7341_spectrum
text_sensor:
- platform: version
name: "Version"
icon: mdi:cube-outline
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment