diff --git a/airgradient-open-air-o-1pst.yaml b/airgradient-open-air-o-1pst.yaml index d7a6e0b..e97faee 100644 --- a/airgradient-open-air-o-1pst.yaml +++ b/airgradient-open-air-o-1pst.yaml @@ -5,7 +5,7 @@ substitutions: name: "ag-open-air-o-1pst" friendly_name: "AG Open Air O-1PST" - config_version: 2.0.0 + config_version: 2.0.1 name_add_mac_suffix: "false" # Must have quotes around value # Enable Home Assistant API diff --git a/packages/sensor_pms5003t.yaml b/packages/sensor_pms5003t.yaml index a5d0c26..361b386 100644 --- a/packages/sensor_pms5003t.yaml +++ b/packages/sensor_pms5003t.yaml @@ -7,7 +7,7 @@ sensor: pm_2_5: name: "PM 2.5" id: pm_2_5 - device_class: pm25 # Added to report properly to HomeKit + device_class: pm25 # Added to report properly to Homekit filters: - sliding_window_moving_average: window_size: 30 @@ -15,7 +15,7 @@ sensor: pm_1_0: name: "PM 1.0" id: pm_1_0 - device_class: pm1 # Added to report properly to HomeKit + device_class: pm1 # Added to report properly to Homekit filters: - sliding_window_moving_average: window_size: 30 @@ -23,7 +23,7 @@ sensor: pm_10_0: name: "PM 10.0" id: pm_10_0 - device_class: pm10 # Added to report properly to HomeKit + device_class: pm10 # Added to report properly to Homekit filters: - sliding_window_moving_average: window_size: 30 @@ -39,6 +39,14 @@ sensor: name: "Temperature" id: temp filters: + # https://www.airgradient.com/blog/slr-temperature-example/ + # - lambda: return (x - 4.55) / 0.83; # Once the negative number issue fix is merged in https://github.com/esphome/issues/issues/3814 + - lambda: !lambda |- + // Fix negative values for now + if (x > 6000) { + return (x - 6553.6 - 4.55) / 0.83; + } + return (x - 4.55) / 0.83; - sliding_window_moving_average: window_size: 30 send_every: 30 @@ -46,6 +54,10 @@ sensor: name: "Humidity" id: humidity filters: + # https://www.airgradient.com/blog/linear-regression-improves-sensor-accuracy/ + # - lambda: return x * 1.500574 - 4.76; + # https://forum.airgradient.com/t/open-air-outdoor-air-quality-monitor-humidity-readings-are-off/1171/2 + - lambda: return x * 1.3921 - 1.0245; - sliding_window_moving_average: window_size: 30 send_every: 30 @@ -60,7 +72,7 @@ sensor: icon: "mdi:air-filter" accuracy_decimals: 0 filters: - - skip_initial: 10 # Need valid data from PM 2.5 sensor before able to calculate + - skip_initial: 1 # Need valid data from PM 2.5 sensor before able to calculate lambda: |- // https://en.wikipedia.org/wiki/Air_quality_index#Computing_the_AQI // Borrowed from https://github.com/kylemanna/sniffer/blob/master/esphome/sniffer_common.yaml diff --git a/packages/sensor_pms5003t_extended_life.yaml b/packages/sensor_pms5003t_extended_life.yaml index 25db83b..6472809 100644 --- a/packages/sensor_pms5003t_extended_life.yaml +++ b/packages/sensor_pms5003t_extended_life.yaml @@ -7,24 +7,38 @@ sensor: pm_2_5: name: "PM 2.5" id: pm_2_5 - device_class: pm25 # Added to report properly to HomeKit + device_class: pm25 # Added to report properly to Homekit pm_1_0: name: "PM 1.0" id: pm_1_0 - device_class: pm1 # Added to report properly to HomeKit + device_class: pm1 # Added to report properly to Homekit pm_10_0: name: "PM 10.0" id: pm_10_0 - device_class: pm10 # Added to report properly to HomeKit + device_class: pm10 # Added to report properly to Homekit pm_0_3um: name: "PM 0.3" id: pm_0_3um temperature: name: "Temperature" id: temp + filters: + # https://www.airgradient.com/blog/slr-temperature-example/ + # - lambda: return (x - 4.55) / 0.83; # Once the negative number issue fix is merged in https://github.com/esphome/issues/issues/3814 + - lambda: !lambda |- + // Fix negative values for now + if (x > 6000) { + return (x - 6553.6 - 4.55) / 0.83; + } + return (x - 4.55) / 0.83; humidity: name: "Humidity" id: humidity + filters: + # https://www.airgradient.com/blog/linear-regression-improves-sensor-accuracy/ + # - lambda: return x * 1.500574 - 4.76; + # https://forum.airgradient.com/t/open-air-outdoor-air-quality-monitor-humidity-readings-are-off/1171/2 + - lambda: return x * 1.3921 - 1.0245; update_interval: 2min @@ -37,7 +51,7 @@ sensor: icon: "mdi:air-filter" accuracy_decimals: 0 filters: - - skip_initial: 10 # Need valid data from PM 2.5 sensor before able to calculate + - skip_initial: 1 # Need valid data from PM 2.5 sensor before able to calculate lambda: |- // https://en.wikipedia.org/wiki/Air_quality_index#Computing_the_AQI // Borrowed from https://github.com/kylemanna/sniffer/blob/master/esphome/sniffer_common.yaml diff --git a/packages/sensor_pms5003t_uncorrected.yaml b/packages/sensor_pms5003t_uncorrected.yaml new file mode 100644 index 0000000..d30b094 --- /dev/null +++ b/packages/sensor_pms5003t_uncorrected.yaml @@ -0,0 +1,90 @@ +sensor: + - platform: pmsx003 + # Default interval of updating every second, but using an average over the last 30 seconds/readings + # PMS5003T with temperature and humidity https://esphome.io/components/sensor/pmsx003.html + type: PMS5003T + uart_id: pms5003_uart + pm_2_5: + name: "PM 2.5" + id: pm_2_5 + device_class: pm25 # Added to report properly to Homekit + filters: + - sliding_window_moving_average: + window_size: 30 + send_every: 30 + pm_1_0: + name: "PM 1.0" + id: pm_1_0 + device_class: pm1 # Added to report properly to Homekit + filters: + - sliding_window_moving_average: + window_size: 30 + send_every: 30 + pm_10_0: + name: "PM 10.0" + id: pm_10_0 + device_class: pm10 # Added to report properly to Homekit + filters: + - sliding_window_moving_average: + window_size: 30 + send_every: 30 + pm_0_3um: + name: "PM 0.3" + id: pm_0_3um + filters: + - sliding_window_moving_average: + window_size: 30 + send_every: 30 + temperature: + name: "Temperature" + id: temp + filters: + - sliding_window_moving_average: + window_size: 30 + send_every: 30 + humidity: + name: "Humidity" + id: humidity + filters: + - sliding_window_moving_average: + window_size: 30 + send_every: 30 + + + - platform: template + # Depends on another sensor providing an ID of pm_2_5 such as a pms5003 + name: "PM 2.5 AQI" + id: pm_2_5_aqi + update_interval: 5 min + unit_of_measurement: "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: |- + // 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 <= 12.0) { + // good + return((50.0 - 0.0) / (12.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 - 12.1) * (id(pm_2_5).state - 12.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 <= 150.4) { + // unhealthy + return((200.0 - 151.0) / (150.4 - 55.5) * (id(pm_2_5).state - 55.5) + 151.0); + } else if (id(pm_2_5).state <= 250.4) { + // very unhealthy + return((300.0 - 201.0) / (250.4 - 150.5) * (id(pm_2_5).state - 150.5) + 201.0); + } else if (id(pm_2_5).state <= 350.4) { + // hazardous + return((400.0 - 301.0) / (350.4 - 250.5) * (id(pm_2_5).state - 250.5) + 301.0); + } else if (id(pm_2_5).state <= 500.4) { + // hazardous 2 + return((500.0 - 401.0) / (500.4 - 350.5) * (id(pm_2_5).state - 350.5) + 401.0); + } else { + return(500); + }