Skip to content

Commit d394186

Browse files
authored
Update AQI breakpoints (#76)
* Switch API calls to use https * Update AQI breakpoint to 2024 EPA numbers * Update config version
1 parent ab9e05e commit d394186

File tree

6 files changed

+60
-72
lines changed

6 files changed

+60
-72
lines changed

packages/sensor_pms5003.yaml

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,29 +60,27 @@ sensor:
6060
filters:
6161
- skip_initial: 1 # Need valid data from PM 2.5 sensor before able to calculate
6262
lambda: |-
63+
// 2024 update from EPA https://www.epa.gov/system/files/documents/2024-02/pm-naaqs-air-quality-index-fact-sheet.pdf
6364
// https://en.wikipedia.org/wiki/Air_quality_index#Computing_the_AQI
6465
// Borrowed from https://github.com/kylemanna/sniffer/blob/master/esphome/sniffer_common.yaml
65-
if (id(pm_2_5).state <= 12.0) {
66+
if (id(pm_2_5).state <= 9.0) {
6667
// good
67-
return((50.0 - 0.0) / (12.0 - 0.0) * (id(pm_2_5).state - 0.0) + 0.0);
68+
return((50.0 - 0.0) / (9.0 - 0.0) * (id(pm_2_5).state - 0.0) + 0.0);
6869
} else if (id(pm_2_5).state <= 35.4) {
6970
// moderate
70-
return((100.0 - 51.0) / (35.4 - 12.1) * (id(pm_2_5).state - 12.1) + 51.0);
71+
return((100.0 - 51.0) / (35.4 - 9.1) * (id(pm_2_5).state - 9.1) + 51.0);
7172
} else if (id(pm_2_5).state <= 55.4) {
7273
// usg
7374
return((150.0 - 101.0) / (55.4 - 35.5) * (id(pm_2_5).state - 35.5) + 101.0);
74-
} else if (id(pm_2_5).state <= 150.4) {
75+
} else if (id(pm_2_5).state <= 125.4) {
7576
// unhealthy
76-
return((200.0 - 151.0) / (150.4 - 55.5) * (id(pm_2_5).state - 55.5) + 151.0);
77-
} else if (id(pm_2_5).state <= 250.4) {
77+
return((200.0 - 151.0) / (125.4 - 55.5) * (id(pm_2_5).state - 55.5) + 151.0);
78+
} else if (id(pm_2_5).state <= 225.4) {
7879
// very unhealthy
79-
return((300.0 - 201.0) / (250.4 - 150.5) * (id(pm_2_5).state - 150.5) + 201.0);
80-
} else if (id(pm_2_5).state <= 350.4) {
80+
return((300.0 - 201.0) / (225.4 - 125.5) * (id(pm_2_5).state - 125.5) + 201.0);
81+
} else if (id(pm_2_5).state <= 325.4) {
8182
// hazardous
82-
return((400.0 - 301.0) / (350.4 - 250.5) * (id(pm_2_5).state - 250.5) + 301.0);
83-
} else if (id(pm_2_5).state <= 500.4) {
84-
// hazardous 2
85-
return((500.0 - 401.0) / (500.4 - 350.5) * (id(pm_2_5).state - 350.5) + 401.0);
83+
return((500.0 - 301.0) / (325.4 - 225.5) * (id(pm_2_5).state - 225.5) + 301.0);
8684
} else {
8785
return(500);
8886
}

packages/sensor_pms5003_extended_life.yaml

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,29 +56,27 @@ sensor:
5656
filters:
5757
- skip_initial: 1 # Need valid data from PM 2.5 sensor before able to calculate
5858
lambda: |-
59+
// 2024 update from EPA https://www.epa.gov/system/files/documents/2024-02/pm-naaqs-air-quality-index-fact-sheet.pdf
5960
// https://en.wikipedia.org/wiki/Air_quality_index#Computing_the_AQI
6061
// Borrowed from https://github.com/kylemanna/sniffer/blob/master/esphome/sniffer_common.yaml
61-
if (id(pm_2_5).state <= 12.0) {
62+
if (id(pm_2_5).state <= 9.0) {
6263
// good
63-
return((50.0 - 0.0) / (12.0 - 0.0) * (id(pm_2_5).state - 0.0) + 0.0);
64+
return((50.0 - 0.0) / (9.0 - 0.0) * (id(pm_2_5).state - 0.0) + 0.0);
6465
} else if (id(pm_2_5).state <= 35.4) {
6566
// moderate
66-
return((100.0 - 51.0) / (35.4 - 12.1) * (id(pm_2_5).state - 12.1) + 51.0);
67+
return((100.0 - 51.0) / (35.4 - 9.1) * (id(pm_2_5).state - 9.1) + 51.0);
6768
} else if (id(pm_2_5).state <= 55.4) {
6869
// usg
6970
return((150.0 - 101.0) / (55.4 - 35.5) * (id(pm_2_5).state - 35.5) + 101.0);
70-
} else if (id(pm_2_5).state <= 150.4) {
71+
} else if (id(pm_2_5).state <= 125.4) {
7172
// unhealthy
72-
return((200.0 - 151.0) / (150.4 - 55.5) * (id(pm_2_5).state - 55.5) + 151.0);
73-
} else if (id(pm_2_5).state <= 250.4) {
73+
return((200.0 - 151.0) / (125.4 - 55.5) * (id(pm_2_5).state - 55.5) + 151.0);
74+
} else if (id(pm_2_5).state <= 225.4) {
7475
// very unhealthy
75-
return((300.0 - 201.0) / (250.4 - 150.5) * (id(pm_2_5).state - 150.5) + 201.0);
76-
} else if (id(pm_2_5).state <= 350.4) {
76+
return((300.0 - 201.0) / (225.4 - 125.5) * (id(pm_2_5).state - 125.5) + 201.0);
77+
} else if (id(pm_2_5).state <= 325.4) {
7778
// hazardous
78-
return((400.0 - 301.0) / (350.4 - 250.5) * (id(pm_2_5).state - 250.5) + 301.0);
79-
} else if (id(pm_2_5).state <= 500.4) {
80-
// hazardous 2
81-
return((500.0 - 401.0) / (500.4 - 350.5) * (id(pm_2_5).state - 350.5) + 401.0);
79+
return((500.0 - 301.0) / (325.4 - 225.5) * (id(pm_2_5).state - 225.5) + 301.0);
8280
} else {
8381
return(500);
8482
}

packages/sensor_pms5003_uncorrected.yaml

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,29 +36,27 @@ sensor:
3636
filters:
3737
- skip_initial: 1 # Need valid data from PM 2.5 sensor before able to calculate
3838
lambda: |-
39+
// 2024 update from EPA https://www.epa.gov/system/files/documents/2024-02/pm-naaqs-air-quality-index-fact-sheet.pdf
3940
// https://en.wikipedia.org/wiki/Air_quality_index#Computing_the_AQI
4041
// Borrowed from https://github.com/kylemanna/sniffer/blob/master/esphome/sniffer_common.yaml
41-
if (id(pm_2_5).state <= 12.0) {
42+
if (id(pm_2_5).state <= 9.0) {
4243
// good
43-
return((50.0 - 0.0) / (12.0 - 0.0) * (id(pm_2_5).state - 0.0) + 0.0);
44+
return((50.0 - 0.0) / (9.0 - 0.0) * (id(pm_2_5).state - 0.0) + 0.0);
4445
} else if (id(pm_2_5).state <= 35.4) {
4546
// moderate
46-
return((100.0 - 51.0) / (35.4 - 12.1) * (id(pm_2_5).state - 12.1) + 51.0);
47+
return((100.0 - 51.0) / (35.4 - 9.1) * (id(pm_2_5).state - 9.1) + 51.0);
4748
} else if (id(pm_2_5).state <= 55.4) {
4849
// usg
4950
return((150.0 - 101.0) / (55.4 - 35.5) * (id(pm_2_5).state - 35.5) + 101.0);
50-
} else if (id(pm_2_5).state <= 150.4) {
51+
} else if (id(pm_2_5).state <= 125.4) {
5152
// unhealthy
52-
return((200.0 - 151.0) / (150.4 - 55.5) * (id(pm_2_5).state - 55.5) + 151.0);
53-
} else if (id(pm_2_5).state <= 250.4) {
53+
return((200.0 - 151.0) / (125.4 - 55.5) * (id(pm_2_5).state - 55.5) + 151.0);
54+
} else if (id(pm_2_5).state <= 225.4) {
5455
// very unhealthy
55-
return((300.0 - 201.0) / (250.4 - 150.5) * (id(pm_2_5).state - 150.5) + 201.0);
56-
} else if (id(pm_2_5).state <= 350.4) {
56+
return((300.0 - 201.0) / (225.4 - 125.5) * (id(pm_2_5).state - 125.5) + 201.0);
57+
} else if (id(pm_2_5).state <= 325.4) {
5758
// hazardous
58-
return((400.0 - 301.0) / (350.4 - 250.5) * (id(pm_2_5).state - 250.5) + 301.0);
59-
} else if (id(pm_2_5).state <= 500.4) {
60-
// hazardous 2
61-
return((500.0 - 401.0) / (500.4 - 350.5) * (id(pm_2_5).state - 350.5) + 401.0);
59+
return((500.0 - 301.0) / (325.4 - 225.5) * (id(pm_2_5).state - 225.5) + 301.0);
6260
} else {
6361
return(500);
6462
}

packages/sensor_pms5003t.yaml

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,29 +98,27 @@ sensor:
9898
filters:
9999
- skip_initial: 1 # Need valid data from PM 2.5 sensor before able to calculate
100100
lambda: |-
101+
// 2024 update from EPA https://www.epa.gov/system/files/documents/2024-02/pm-naaqs-air-quality-index-fact-sheet.pdf
101102
// https://en.wikipedia.org/wiki/Air_quality_index#Computing_the_AQI
102103
// Borrowed from https://github.com/kylemanna/sniffer/blob/master/esphome/sniffer_common.yaml
103-
if (id(pm_2_5).state <= 12.0) {
104+
if (id(pm_2_5).state <= 9.0) {
104105
// good
105-
return((50.0 - 0.0) / (12.0 - 0.0) * (id(pm_2_5).state - 0.0) + 0.0);
106+
return((50.0 - 0.0) / (9.0 - 0.0) * (id(pm_2_5).state - 0.0) + 0.0);
106107
} else if (id(pm_2_5).state <= 35.4) {
107108
// moderate
108-
return((100.0 - 51.0) / (35.4 - 12.1) * (id(pm_2_5).state - 12.1) + 51.0);
109+
return((100.0 - 51.0) / (35.4 - 9.1) * (id(pm_2_5).state - 9.1) + 51.0);
109110
} else if (id(pm_2_5).state <= 55.4) {
110111
// usg
111112
return((150.0 - 101.0) / (55.4 - 35.5) * (id(pm_2_5).state - 35.5) + 101.0);
112-
} else if (id(pm_2_5).state <= 150.4) {
113+
} else if (id(pm_2_5).state <= 125.4) {
113114
// unhealthy
114-
return((200.0 - 151.0) / (150.4 - 55.5) * (id(pm_2_5).state - 55.5) + 151.0);
115-
} else if (id(pm_2_5).state <= 250.4) {
115+
return((200.0 - 151.0) / (125.4 - 55.5) * (id(pm_2_5).state - 55.5) + 151.0);
116+
} else if (id(pm_2_5).state <= 225.4) {
116117
// very unhealthy
117-
return((300.0 - 201.0) / (250.4 - 150.5) * (id(pm_2_5).state - 150.5) + 201.0);
118-
} else if (id(pm_2_5).state <= 350.4) {
118+
return((300.0 - 201.0) / (225.4 - 125.5) * (id(pm_2_5).state - 125.5) + 201.0);
119+
} else if (id(pm_2_5).state <= 325.4) {
119120
// hazardous
120-
return((400.0 - 301.0) / (350.4 - 250.5) * (id(pm_2_5).state - 250.5) + 301.0);
121-
} else if (id(pm_2_5).state <= 500.4) {
122-
// hazardous 2
123-
return((500.0 - 401.0) / (500.4 - 350.5) * (id(pm_2_5).state - 350.5) + 401.0);
121+
return((500.0 - 301.0) / (325.4 - 225.5) * (id(pm_2_5).state - 225.5) + 301.0);
124122
} else {
125123
return(500);
126124
}

packages/sensor_pms5003t_extended_life.yaml

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,29 +103,27 @@ sensor:
103103
filters:
104104
- skip_initial: 1 # Need valid data from PM 2.5 sensor before able to calculate
105105
lambda: |-
106+
// 2024 update from EPA https://www.epa.gov/system/files/documents/2024-02/pm-naaqs-air-quality-index-fact-sheet.pdf
106107
// https://en.wikipedia.org/wiki/Air_quality_index#Computing_the_AQI
107108
// Borrowed from https://github.com/kylemanna/sniffer/blob/master/esphome/sniffer_common.yaml
108-
if (id(pm_2_5).state <= 12.0) {
109+
if (id(pm_2_5).state <= 9.0) {
109110
// good
110-
return((50.0 - 0.0) / (12.0 - 0.0) * (id(pm_2_5).state - 0.0) + 0.0);
111+
return((50.0 - 0.0) / (9.0 - 0.0) * (id(pm_2_5).state - 0.0) + 0.0);
111112
} else if (id(pm_2_5).state <= 35.4) {
112113
// moderate
113-
return((100.0 - 51.0) / (35.4 - 12.1) * (id(pm_2_5).state - 12.1) + 51.0);
114+
return((100.0 - 51.0) / (35.4 - 9.1) * (id(pm_2_5).state - 9.1) + 51.0);
114115
} else if (id(pm_2_5).state <= 55.4) {
115116
// usg
116117
return((150.0 - 101.0) / (55.4 - 35.5) * (id(pm_2_5).state - 35.5) + 101.0);
117-
} else if (id(pm_2_5).state <= 150.4) {
118+
} else if (id(pm_2_5).state <= 125.4) {
118119
// unhealthy
119-
return((200.0 - 151.0) / (150.4 - 55.5) * (id(pm_2_5).state - 55.5) + 151.0);
120-
} else if (id(pm_2_5).state <= 250.4) {
120+
return((200.0 - 151.0) / (125.4 - 55.5) * (id(pm_2_5).state - 55.5) + 151.0);
121+
} else if (id(pm_2_5).state <= 225.4) {
121122
// very unhealthy
122-
return((300.0 - 201.0) / (250.4 - 150.5) * (id(pm_2_5).state - 150.5) + 201.0);
123-
} else if (id(pm_2_5).state <= 350.4) {
123+
return((300.0 - 201.0) / (225.4 - 125.5) * (id(pm_2_5).state - 125.5) + 201.0);
124+
} else if (id(pm_2_5).state <= 325.4) {
124125
// hazardous
125-
return((400.0 - 301.0) / (350.4 - 250.5) * (id(pm_2_5).state - 250.5) + 301.0);
126-
} else if (id(pm_2_5).state <= 500.4) {
127-
// hazardous 2
128-
return((500.0 - 401.0) / (500.4 - 350.5) * (id(pm_2_5).state - 350.5) + 401.0);
126+
return((500.0 - 301.0) / (325.4 - 225.5) * (id(pm_2_5).state - 225.5) + 301.0);
129127
} else {
130128
return(500);
131129
}

packages/sensor_pms5003t_uncorrected.yaml

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,29 +65,27 @@ sensor:
6565
filters:
6666
- skip_initial: 1 # Need valid data from PM 2.5 sensor before able to calculate
6767
lambda: |-
68+
// 2024 update from EPA https://www.epa.gov/system/files/documents/2024-02/pm-naaqs-air-quality-index-fact-sheet.pdf
6869
// https://en.wikipedia.org/wiki/Air_quality_index#Computing_the_AQI
6970
// Borrowed from https://github.com/kylemanna/sniffer/blob/master/esphome/sniffer_common.yaml
70-
if (id(pm_2_5).state <= 12.0) {
71+
if (id(pm_2_5).state <= 9.0) {
7172
// good
72-
return((50.0 - 0.0) / (12.0 - 0.0) * (id(pm_2_5).state - 0.0) + 0.0);
73+
return((50.0 - 0.0) / (9.0 - 0.0) * (id(pm_2_5).state - 0.0) + 0.0);
7374
} else if (id(pm_2_5).state <= 35.4) {
7475
// moderate
75-
return((100.0 - 51.0) / (35.4 - 12.1) * (id(pm_2_5).state - 12.1) + 51.0);
76+
return((100.0 - 51.0) / (35.4 - 9.1) * (id(pm_2_5).state - 9.1) + 51.0);
7677
} else if (id(pm_2_5).state <= 55.4) {
7778
// usg
7879
return((150.0 - 101.0) / (55.4 - 35.5) * (id(pm_2_5).state - 35.5) + 101.0);
79-
} else if (id(pm_2_5).state <= 150.4) {
80+
} else if (id(pm_2_5).state <= 125.4) {
8081
// unhealthy
81-
return((200.0 - 151.0) / (150.4 - 55.5) * (id(pm_2_5).state - 55.5) + 151.0);
82-
} else if (id(pm_2_5).state <= 250.4) {
82+
return((200.0 - 151.0) / (125.4 - 55.5) * (id(pm_2_5).state - 55.5) + 151.0);
83+
} else if (id(pm_2_5).state <= 225.4) {
8384
// very unhealthy
84-
return((300.0 - 201.0) / (250.4 - 150.5) * (id(pm_2_5).state - 150.5) + 201.0);
85-
} else if (id(pm_2_5).state <= 350.4) {
85+
return((300.0 - 201.0) / (225.4 - 125.5) * (id(pm_2_5).state - 125.5) + 201.0);
86+
} else if (id(pm_2_5).state <= 325.4) {
8687
// hazardous
87-
return((400.0 - 301.0) / (350.4 - 250.5) * (id(pm_2_5).state - 250.5) + 301.0);
88-
} else if (id(pm_2_5).state <= 500.4) {
89-
// hazardous 2
90-
return((500.0 - 401.0) / (500.4 - 350.5) * (id(pm_2_5).state - 350.5) + 401.0);
88+
return((500.0 - 301.0) / (325.4 - 225.5) * (id(pm_2_5).state - 225.5) + 301.0);
9189
} else {
9290
return(500);
9391
}

0 commit comments

Comments
 (0)