Created
March 25, 2024 21:30
-
-
Save MrEbbinghaus/f3f764f2f3c90bfb37fa64a43fef79b7 to your computer and use it in GitHub Desktop.
APDS 9960 Lux calculation - ESPHome
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| substitutions: | |
| IRtoIL_red: 683.0 * 0.6 | |
| IRtoIL_green: 683.0 * 0.8 | |
| IRtoIL_blue: 683.0 * 0.075 | |
| sensor: | |
| - id: clearirradiance | |
| name: "Clear Irradiance" | |
| platform: apds9960 | |
| type: CLEAR | |
| device_class: irradiance | |
| unit_of_measurement: "W/m²" | |
| accuracy_decimals: 5 | |
| filters: | |
| - lambda: !lambda |- | |
| float counts = x / 100.0 * float(UINT16_MAX); | |
| return counts / 2360.0; | |
| - id: light_red | |
| platform: apds9960 | |
| type: RED | |
| name: "Red Channel" | |
| accuracy_decimals: 5 | |
| - id: light_green | |
| platform: apds9960 | |
| type: GREEN | |
| name: "Green Channel" | |
| accuracy_decimals: 5 | |
| - id: light_blue | |
| platform: apds9960 | |
| type: BLUE | |
| name: "Blue Channel" | |
| accuracy_decimals: 5 | |
| - id: corrected_counts_red | |
| platform: template | |
| name: "Red Counts Corrected" | |
| lambda: return id(light_red).state / 100.0 * float(UINT16_MAX); | |
| unit_of_measurement: "" | |
| state_class: measurement | |
| - id: corrected_counts_green | |
| platform: template | |
| name: "Green Counts Corrected" | |
| lambda: return id(light_green).state / 100.0 * float(UINT16_MAX); | |
| unit_of_measurement: "" | |
| state_class: measurement | |
| - id: corrected_counts_blue | |
| platform: template | |
| name: "Blue Counts Corrected" | |
| lambda: return id(light_blue).state / 100.0 * float(UINT16_MAX) * 2.0; | |
| unit_of_measurement: "" | |
| state_class: measurement | |
| - id: irToIl_overall | |
| platform: template | |
| name: "IRtoIL overall" | |
| state_class: measurement | |
| unit_of_measurement: "" | |
| lambda: !lambda |- | |
| float corrected_counts_red = 1.0 * id(light_red).state; | |
| float corrected_counts_green = 1.0 * id(light_green).state; | |
| float corrected_counts_blue = 2.0 * id(light_blue).state; | |
| float sum = corrected_counts_red + corrected_counts_green + corrected_counts_blue; | |
| return ${IRtoIL_red} * (corrected_counts_red / sum) + ${IRtoIL_green} * (corrected_counts_green / sum) + ${IRtoIL_blue} * (corrected_counts_blue / sum); | |
| - id: lux | |
| platform: template | |
| name: "Lux" | |
| device_class: illuminance | |
| state_class: measurement | |
| unit_of_measurement: lx | |
| update_interval: 10s | |
| lambda: !lambda |- | |
| float corrected_red = 1.0 * id(light_red).state; | |
| float corrected_green = 1.0 * id(light_green).state; | |
| float corrected_blue = 2.0 * id(light_blue).state; | |
| float sum = corrected_red + corrected_green + corrected_blue; | |
| float irToIl_overall = ${IRtoIL_red} * (corrected_red / sum) + ${IRtoIL_green} * (corrected_green / sum) + ${IRtoIL_blue} * (corrected_blue / sum); | |
| return irToIl_overall * id(clearirradiance).state; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment