Calculation of lux value improved

This commit is contained in:
Kai Lauterbach 2022-05-05 10:21:36 +02:00
parent d83182ddf5
commit f25b6dfa8e

View file

@ -59,12 +59,25 @@ sensor:
type: BLUE
name: "APDS9960_blue_channel"
id: apds9960_blue
# TODO fix calculation to get lux instead of a percentual value
#
# Code from Adafruit_APDS9960 lib:
# illuminance = (-0.32466F * r) + (1.57837F * g) + (-0.73191F * b);
#
# Code from: https://esphome.io/api/apds9960_8cpp_source.html
# 180: float red_perc = (uint_red / float(UINT16_MAX)) * 100.0f;
# 181: float green_perc = (uint_green / float(UINT16_MAX)) * 100.0f;
# 182: float blue_perc = (uint_blue / float(UINT16_MAX)) * 100.0f;
- platform: template
name: "light"
lambda: |-
# TODO fix calculation to get lux instead of a percentual value
return (-0.32466F * id(apds9960_red).raw_state) + (1.57837F * id(apds9960_green).raw_state) + (-0.73191F * id(apds9960_blue).raw_state);
const float perc_to_raw = 65535.0 / 100.0;
const float red_to_lux = -0.32466;
const float green_to_lux = -1.57837;
const float blue_to_lux = -0.73191;
return ((red_to_lux * id(apds9960_red).raw_state) + (green_to_lux * id(apds9960_green).raw_state) + (blue_to_lux * id(apds9960_blue).raw_state)) * perc_to_raw;
update_interval: 300s
accuracy_decimals: 2
unit_of_measurement: 'lux'
#################### bme280 sensor i2c