Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 5 additions & 33 deletions packages/sensor_pms5003.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,38 +75,10 @@ sensor:
return result;
}

- platform: template
# Depends on another sensor providing an ID of pm_2_5 such as a pms5003
- platform: aqi
# https://esphome.io/components/sensor/aqi/
name: "PM 2.5 AQI"
id: pm_2_5_aqi
update_interval: 5 min
device_class: aqi
icon: "mdi:air-filter"
accuracy_decimals: 0
filters:
- skip_initial: 1 # Need valid data from PM 2.5 sensor before able to calculate
lambda: |-
// 2024 update from EPA https://www.epa.gov/system/files/documents/2024-02/pm-naaqs-air-quality-index-fact-sheet.pdf
// https://en.wikipedia.org/wiki/Air_quality_index#Computing_the_AQI
// Borrowed from https://github.com/kylemanna/sniffer/blob/master/esphome/sniffer_common.yaml
if (id(pm_2_5).state <= 9.0) {
// good
return((50.0 - 0.0) / (9.0 - 0.0) * (id(pm_2_5).state - 0.0) + 0.0);
} else if (id(pm_2_5).state <= 35.4) {
// moderate
return((100.0 - 51.0) / (35.4 - 9.1) * (id(pm_2_5).state - 9.1) + 51.0);
} else if (id(pm_2_5).state <= 55.4) {
// usg
return((150.0 - 101.0) / (55.4 - 35.5) * (id(pm_2_5).state - 35.5) + 101.0);
} else if (id(pm_2_5).state <= 125.4) {
// unhealthy
return((200.0 - 151.0) / (125.4 - 55.5) * (id(pm_2_5).state - 55.5) + 151.0);
} else if (id(pm_2_5).state <= 225.4) {
// very unhealthy
return((300.0 - 201.0) / (225.4 - 125.5) * (id(pm_2_5).state - 125.5) + 201.0);
} else if (id(pm_2_5).state <= 325.4) {
// hazardous
return((500.0 - 301.0) / (325.4 - 225.5) * (id(pm_2_5).state - 225.5) + 301.0);
} else {
return(500);
}
pm_2_5: pm_2_5
pm_10_0: pm_10_0
calculation_type: AQI