Update configuration from SuperSensor changes
This commit is contained in:
116
microenv.yaml
116
microenv.yaml
@@ -27,10 +27,10 @@ esphome:
|
|||||||
project:
|
project:
|
||||||
name: "Joshua Boniface.microenv"
|
name: "Joshua Boniface.microenv"
|
||||||
version: "1.0"
|
version: "1.0"
|
||||||
min_version: 2025.5.0
|
min_version: 2025.11.0
|
||||||
|
|
||||||
dashboard_import:
|
dashboard_import:
|
||||||
package_import_url: github://joshuaboniface/microenv/microenv.yaml
|
package_import_url: github://joshuaboniface/microenv/microenv.yaml@v1.x
|
||||||
|
|
||||||
esp32:
|
esp32:
|
||||||
board: esp32-c3-devkitm-1
|
board: esp32-c3-devkitm-1
|
||||||
@@ -42,11 +42,10 @@ preferences:
|
|||||||
flash_write_interval: 15sec
|
flash_write_interval: 15sec
|
||||||
|
|
||||||
globals:
|
globals:
|
||||||
# Defaults to -5 due to heating from the ESP
|
|
||||||
- id: temperature_offset
|
- id: temperature_offset
|
||||||
type: float
|
type: float
|
||||||
restore_value: true
|
restore_value: true
|
||||||
initial_value: "-5.0"
|
initial_value: "0.0"
|
||||||
|
|
||||||
- id: humidity_offset
|
- id: humidity_offset
|
||||||
type: float
|
type: float
|
||||||
@@ -86,29 +85,29 @@ i2c:
|
|||||||
|
|
||||||
sensor:
|
sensor:
|
||||||
- platform: sgp4x
|
- platform: sgp4x
|
||||||
voc:
|
voc:
|
||||||
name: "SGP41 VOC Index"
|
name: "SGP41 VOC Index"
|
||||||
id: sgp41_voc_index
|
id: sgp41_voc_index
|
||||||
accuracy_decimals: 0
|
accuracy_decimals: 0
|
||||||
icon: mdi:waves-arrow-up
|
icon: mdi:waves-arrow-up
|
||||||
filters:
|
filters:
|
||||||
- sliding_window_moving_average: # We take a reading every 15 seconds, but calculate the sliding
|
- sliding_window_moving_average: # We take a reading every 5 seconds, but calculate the sliding
|
||||||
window_size: 20 # average over 20 readings i.e. 300 seconds/5 minutes to normalize
|
window_size: 12 # average over 12 readings i.e. 60 seconds/1 minute to normalize
|
||||||
send_every: 4 # brief spikes while still sending a value every 60 seconds.
|
send_every: 3 # brief spikes while still sending a value every 15 seconds.
|
||||||
nox:
|
nox:
|
||||||
name: "SGP41 NOx Index"
|
name: "SGP41 NOx Index"
|
||||||
id: sgp41_nox_index
|
id: sgp41_nox_index
|
||||||
accuracy_decimals: 0
|
accuracy_decimals: 0
|
||||||
icon: mdi:waves-arrow-up
|
icon: mdi:waves-arrow-up
|
||||||
filters:
|
filters:
|
||||||
- sliding_window_moving_average:
|
- sliding_window_moving_average:
|
||||||
window_size: 20
|
window_size: 12
|
||||||
send_every: 4
|
send_every: 3
|
||||||
compensation:
|
compensation:
|
||||||
temperature_source: sht45_temperature
|
temperature_source: sht45_temperature
|
||||||
humidity_source: sht45_humidity
|
humidity_source: sht45_humidity
|
||||||
store_baseline: true
|
store_baseline: true
|
||||||
update_interval: 15s
|
update_interval: 5s
|
||||||
|
|
||||||
- platform: template
|
- platform: template
|
||||||
name: "SGP41 TVOC (µg/m³)"
|
name: "SGP41 TVOC (µg/m³)"
|
||||||
@@ -163,6 +162,20 @@ sensor:
|
|||||||
id: sht45_humidity
|
id: sht45_humidity
|
||||||
accuracy_decimals: 1
|
accuracy_decimals: 1
|
||||||
filters:
|
filters:
|
||||||
|
- lambda: |-
|
||||||
|
// Grab measured and corrected temperatures
|
||||||
|
float t_meas = id(sht45_temperature).state - id(temperature_offset);
|
||||||
|
float t_corr = id(sht45_temperature).state;
|
||||||
|
float rh_meas = x;
|
||||||
|
|
||||||
|
// Compute saturation vapor pressures (Magnus formula)
|
||||||
|
auto es = [](float T) { return 6.112 * exp((17.62 * T) / (243.12 + T)); };
|
||||||
|
float rh_corr = rh_meas * es(t_meas) / es(t_corr);
|
||||||
|
|
||||||
|
// Clamp to 0–100 %
|
||||||
|
if (rh_corr < 0) rh_corr = 0;
|
||||||
|
if (rh_corr > 100) rh_corr = 100;
|
||||||
|
return rh_corr;
|
||||||
- offset: !lambda return id(humidity_offset);
|
- offset: !lambda return id(humidity_offset);
|
||||||
- sliding_window_moving_average:
|
- sliding_window_moving_average:
|
||||||
window_size: 4
|
window_size: 4
|
||||||
@@ -196,30 +209,61 @@ sensor:
|
|||||||
unit_of_measurement: "%"
|
unit_of_measurement: "%"
|
||||||
icon: mdi:home-heart
|
icon: mdi:home-heart
|
||||||
lambda: |-
|
lambda: |-
|
||||||
float voc_index = id(sgp41_voc_index).state;
|
float voc = id(sgp41_tvoc_ppb).state;
|
||||||
|
if (isnan(voc) || voc < 1) voc = 1;
|
||||||
float temp = id(sht45_temperature).state;
|
float temp = id(sht45_temperature).state;
|
||||||
float humidity = id(sht45_humidity).state;
|
float humidity = id(sht45_humidity).state;
|
||||||
|
|
||||||
// VOC Score (0–100)
|
float temp_min = id(room_health_temperature_min);
|
||||||
float voc_score = 0;
|
float temp_max = id(room_health_temperature_max);
|
||||||
if (voc_index <= 100) voc_score = 100;
|
float temp_penalty = id(room_health_temperature_penalty);
|
||||||
else if (voc_index <= 200) voc_score = 80;
|
float humid_min = id(room_health_humidity_min);
|
||||||
else if (voc_index <= 300) voc_score = 60;
|
float humid_max = id(room_health_humidity_max);
|
||||||
else if (voc_index <= 400) voc_score = 40;
|
float humid_penalty = id(room_health_humidity_penalty);
|
||||||
else if (voc_index <= 500) voc_score = 50;
|
float voc_weight = id(room_health_voc_weight);
|
||||||
else voc_score = 0;
|
float temp_weight = id(room_health_temperature_weight);
|
||||||
|
float humid_weight = id(room_health_humidity_weight);
|
||||||
// Temperature Score (0–100)
|
|
||||||
float temp_score = 100.0 - abs(temp - 23.0) * 10.0;
|
// VOC score (0–100) mapped to categories from Chemical Pollution levels below
|
||||||
|
float voc_score;
|
||||||
|
if (voc <= 200) {
|
||||||
|
voc_score = 100.0;
|
||||||
|
} else if (voc <= 400) {
|
||||||
|
// 200–400: 100 → 90
|
||||||
|
voc_score = 100.0 - (voc - 200) * (10.0 / 200.0);
|
||||||
|
} else if (voc <= 600) {
|
||||||
|
// 400–600: 90 → 70
|
||||||
|
voc_score = 90.0 - (voc - 400) * (20.0 / 200.0);
|
||||||
|
} else if (voc <= 1500) {
|
||||||
|
// 600–1500: 70 → 40
|
||||||
|
voc_score = 70.0 - (voc - 600) * (30.0 / 900.0);
|
||||||
|
} else if (voc <= 3000) {
|
||||||
|
// 1500–3000: 40 → 0
|
||||||
|
voc_score = 40.0 - (voc - 1500) * (40.0 / 1500.0);
|
||||||
|
} else {
|
||||||
|
voc_score = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Temperature score
|
||||||
|
float temp_score = 100;
|
||||||
|
if (temp < temp_min) temp_score = 100 - (temp_min - temp) * temp_penalty;
|
||||||
|
else if (temp > temp_max) temp_score = 100 - (temp - temp_max) * temp_penalty;
|
||||||
if (temp_score < 0) temp_score = 0;
|
if (temp_score < 0) temp_score = 0;
|
||||||
|
|
||||||
// Humidity Score (0–100), ideal range 35–55%
|
// Humidity score
|
||||||
float humidity_score = 100.0 - abs(humidity - 50.0) * 3.0;
|
float humidity_score = 100;
|
||||||
|
if (humidity < humid_min) humidity_score = 100 - (humid_min - humidity) * humid_penalty;
|
||||||
|
else if (humidity > humid_max) humidity_score = 100 - (humidity - humid_max) * humid_penalty;
|
||||||
if (humidity_score < 0) humidity_score = 0;
|
if (humidity_score < 0) humidity_score = 0;
|
||||||
|
|
||||||
// Weighted average
|
// Weighted average
|
||||||
float overall_score = (voc_score * 0.5 + temp_score * 0.25 + humidity_score * 0.25);
|
float total_weights = voc_weight + temp_weight + humid_weight;
|
||||||
|
if (total_weights <= 0) total_weights = 1.0;
|
||||||
|
voc_weight /= total_weights;
|
||||||
|
temp_weight /= total_weights;
|
||||||
|
humid_weight /= total_weights;
|
||||||
|
float overall_score = (voc_score * voc_weight + temp_score * temp_weight + humidity_score * humid_weight);
|
||||||
|
|
||||||
return (int) round(overall_score);
|
return (int) round(overall_score);
|
||||||
update_interval: 15s
|
update_interval: 15s
|
||||||
|
|
||||||
@@ -261,7 +305,7 @@ button:
|
|||||||
|
|
||||||
number:
|
number:
|
||||||
# Temperature offset:
|
# Temperature offset:
|
||||||
# A calibration from -30 to +5 for the temperature sensor
|
# A calibration from -30 to +10 for the temperature sensor
|
||||||
- platform: template
|
- platform: template
|
||||||
name: "Temperature Offset"
|
name: "Temperature Offset"
|
||||||
id: temperature_offset_setter
|
id: temperature_offset_setter
|
||||||
@@ -277,12 +321,12 @@ number:
|
|||||||
value: !lambda 'return float(x);'
|
value: !lambda 'return float(x);'
|
||||||
|
|
||||||
# Humidity offset:
|
# Humidity offset:
|
||||||
# A calibration from -20 to +20 for the humidity sensor
|
# A calibration from -50 to +50 for the humidity sensor
|
||||||
- platform: template
|
- platform: template
|
||||||
name: "Humidity Offset"
|
name: "Humidity Offset"
|
||||||
id: humidity_offset_setter
|
id: humidity_offset_setter
|
||||||
min_value: -20
|
min_value: -50
|
||||||
max_value: 20
|
max_value: 50
|
||||||
step: 0.1
|
step: 0.1
|
||||||
lambda: |-
|
lambda: |-
|
||||||
return id(humidity_offset);
|
return id(humidity_offset);
|
||||||
|
|||||||
Reference in New Issue
Block a user