Skip to content

Instantly share code, notes, and snippets.

@joeypiccola
Created January 29, 2026 22:53
Show Gist options
  • Select an option

  • Save joeypiccola/f6606e806b2439203dbabd6e03aca681 to your computer and use it in GitHub Desktop.

Select an option

Save joeypiccola/f6606e806b2439203dbabd6e03aca681 to your computer and use it in GitHub Desktop.
esphome:
name: aqi-a-esp
friendly_name: aqi-a-esp
esp8266:
board: d1_mini
# Enable Home Assistant API
api:
encryption:
key: "...="
ota:
- platform: esphome
password: "..."
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
manual_ip:
static_ip: ...
gateway: ...
subnet: ...
logger:
baud_rate: 0
uart:
tx_pin: GPIO3
rx_pin: GPIO1
baud_rate: 9600
binary_sensor:
- platform: template
name: "Warmed Up"
id: warmed_up
filters:
- delayed_on: 30s
on_press:
- delay: 10s
- switch.turn_off: measuring
sensor:
- platform: aqi
name: "Air Quality Index"
pm_2_5: pms_25
pm_10_0: pms_100
calculation_type: AQI
- platform: pmsx003
type: PMSX003
pm_1_0:
name: "Particulate Matter <1.0µm Concentration"
id: pms_10
accuracy_decimals: 1
filters:
- lambda: |-
if (id(warmed_up).state) {
return x;
} else {
return {};
}
- sliding_window_moving_average:
window_size: 10
send_every: 1
send_first_at: 1
- debounce: 3s
pm_2_5:
name: "Particulate Matter <2.5µm Concentration"
id: pms_25
accuracy_decimals: 1
filters:
- lambda: |-
if (id(warmed_up).state) {
return x;
} else {
return {};
}
- sliding_window_moving_average:
window_size: 10
send_every: 1
send_first_at: 1
- debounce: 3s
pm_10_0:
name: "Particulate Matter <10.0µm Concentration"
id: pms_100
accuracy_decimals: 1
filters:
- lambda: |-
if (id(warmed_up).state) {
return x;
} else {
return {};
}
- sliding_window_moving_average:
window_size: 10
send_first_at: 1
send_every: 1
- debounce: 3s
switch:
- platform: gpio
name: "Measuring"
id: measuring
pin:
number: D1
restore_mode: ALWAYS_OFF
on_turn_on:
- binary_sensor.template.publish:
id: warmed_up
state: ON
on_turn_off:
- binary_sensor.template.publish:
id: warmed_up
state: OFF
- platform: restart
name: "Restart"
# runs PMS5003 sensor every 300s to extend sensor life.
interval:
- interval: 300s
then:
- wait_until:
condition:
api.connected: # Can use api.connected if using HA API instead
- switch.turn_on: measuring # Will turn itself off later
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment