What do you need before you start?
- A CO2 sensor in Home Assistant: any NDIR sensor that reports parts per million (ppm) as a numeric sensor entity, such as an Aranet4, Airthings, Qingping or an ESPHome build with an SCD40. Our guide to the best indoor air quality monitors covers which ones suit Home Assistant.
- Something to act on: a smart plug or relay on an extractor fan, a smart-controlled ventilation unit, or simply your phone with the Companion app for notifications.
- Home Assistant 2024.10 or later for the current
triggers:andactions:YAML syntax used below. - Your entity IDs: find them in Settings, Devices & services, Entities. The examples use
sensor.living_room_co2andswitch.living_room_fan; swap in your own.
What CO2 level should trigger ventilation?
For most UK homes, treat readings under about 800 ppm as good, 800 to 1,500 ppm as stale, and above 1,500 ppm as poorly ventilated. The 1,500 ppm line comes from the HSE's CO2 monitor guidance, which says consistently higher readings in an occupied room point to poor ventilation. The 800 ppm band is used in UK Government and Welsh Government guidance for schools.
These numbers are a broad guide to ventilation, not a safety limit, and the HSE says as much. If a sensor never drops much below 800 ppm even after the windows have been open for 20 minutes, it is more likely out of calibration than your house being unusually airtight.
Step 1: Check the sensor is reporting properly
Open Developer tools, States, and search for your CO2 entity. The state should be a plain number and the unit should be ppm. If the state is unavailable or unknown after a restart, fix that first, because a numeric trigger cannot fire on a non-number.
Place the sensor where people actually breathe: at head height in a bedroom or living room, away from windows and, per HSE advice, more than 50 cm from anyone, since exhaled breath next to the sensor inflates the reading. Let it run for a day before trusting the pattern, as many sensors self-calibrate over the first few days.
Step 2: Create a helper to switch the automation on and off
Go to Settings, Devices & services, Helpers, Create helper, Toggle, and name it CO2 ventilation enabled. This gives you a dashboard switch to pause the automation, for example when you are cooking with the windows already open or running a deliberate overnight setback.
It is optional, but it is far easier than editing YAML to disable the automation, and it will show as input_boolean.co2_ventilation_enabled.
Step 3: Build the notification automation (800 ppm)
The gentle tier tells you to open a window once the room has been stale for a while. Use a numeric state trigger with a for duration so a brief spike, such as someone walking in, does not send a message.
alias: CO2 stale air nudge
description: Notify when living room CO2 stays above 1,000 ppm
mode: single
triggers:
- trigger: numeric_state
entity_id: sensor.living_room_co2
above: 1000
for: "00:10:00"
conditions:
- condition: state
entity_id: input_boolean.co2_ventilation_enabled
state: "on"
actions:
- action: notify.mobile_app_your_phone
data:
title: "Stale air in the living room"
message: "CO2 has been above 1,000 ppm for 10 minutes. Open a window for a few minutes."
The trigger fires once when the value crosses 1,000 ppm and has stayed there for ten minutes. It does not repeat while the level remains high; it only fires again after the reading has dropped below the threshold and crossed it again. Replace notify.mobile_app_your_phone with your own service name, which you can find under Developer tools, Actions. Our notifications guide covers actionable and critical notifications if you want a button on the alert.
I used 1,000 ppm rather than 800 here deliberately. Many homes sit between 800 and 1,000 for hours when occupied with the windows shut, and an alert at 800 trains you to ignore it. Start at 1,000 and lower it if you want a more insistent system.
Step 4: Build the fan automation with a gap between on and off
The firm tier switches a fan or ventilation unit on at 1,500 ppm and off again once the air has genuinely cleared. Two separate triggers with different thresholds provide the gap, which is called hysteresis, and stop the fan chattering around a single value.
alias: CO2 ventilation fan
description: Fan on above 1,500 ppm, off below 900 ppm
mode: single
triggers:
- trigger: numeric_state
entity_id: sensor.living_room_co2
above: 1500
for: "00:03:00"
id: "high"
- trigger: numeric_state
entity_id: sensor.living_room_co2
below: 900
for: "00:05:00"
id: "clear"
conditions:
- condition: state
entity_id: input_boolean.co2_ventilation_enabled
state: "on"
actions:
- choose:
- conditions:
- condition: trigger
id: "high"
sequence:
- action: switch.turn_on
target:
entity_id: switch.living_room_fan
- conditions:
- condition: trigger
id: "clear"
sequence:
- action: switch.turn_off
target:
entity_id: switch.living_room_fan
The 600 ppm gap between 1,500 and 900 matters more than the exact numbers. If your fan can only pull the room down to 1,100 ppm, the "clear" trigger will never fire, so check how low your setup actually gets and set the lower threshold a little above that floor.
If the fan is a bathroom or kitchen extractor on a fused spur, do not switch it with a cheap smart plug. Use a properly rated relay or a ventilation unit with its own smart control, and read the load rating first. Our extractor fan automation guide covers humidity-based control for the same kind of hardware.
Step 5: Add a night rule so the fan does not wake you
A fan that roars at 03:00 defeats the point of ventilating a bedroom. Add a time condition to the fan automation so it only runs at night if you want it to, or switch to a quieter alternative by sending a notification instead.
conditions:
- condition: state
entity_id: input_boolean.co2_ventilation_enabled
state: "on"
- condition: time
after: "07:00:00"
before: "22:30:00"
Bedrooms are where this matters most, because CO2 climbs steadily overnight with the door and window shut. If you have a low-speed or trickle mode on your ventilation unit, use that overnight rather than disabling the automation entirely. A cracked window or a trickle vent is usually the cheapest fix and needs no automation at all.
Step 6: Pause when a window is already open
If a window sensor reports open, the fan is fighting the draught and the alert is redundant. Add a condition so the automation stands down.
- condition: state
entity_id: binary_sensor.living_room_window
state: "off"
This relies on a contact sensor reporting off when closed, which is the usual convention in Home Assistant. If you have not set up window sensors yet, see our window open rain alert guide for the same sensor pattern.
Step 7: Test it without waiting for the air to go stale
Open Developer tools, States, pick your CO2 sensor and edit the state to 1600, then press Set state. This only changes the value inside Home Assistant until the sensor next reports, so it is a safe way to test. Wait out the for delay and confirm the fan switches on, then set it to 800 and confirm it switches off.
Afterwards, open the automation and check its Traces tab. Each run shows which trigger fired, which conditions passed and which action ran, which is the quickest way to find out why something did or did not happen.
Why isn't my CO2 automation firing?
The sensor state is not a number: a state of unavailable or unknown never crosses a threshold. Check the device is online and the entity is not disabled.
It only fires once: a numeric state trigger fires on crossing the threshold, not while the value stays above it. If the level is already above 1,500 when you save the automation, nothing happens until it falls below and rises again.
The fan flaps on and off: your on and off thresholds are too close together, or the for delay is too short. Widen the gap and lengthen the delay.
It runs but the room never clears: the fan is too weak or recirculating air. CO2 only drops when fresh air comes in, so an extractor with no air inlet (a trickle vent or an ajar window) will struggle.
The numbers look wrong: low-cost sensors drift. Take the sensor outside for 20 minutes and run the manufacturer's calibration routine if the reading looks far too high.
What should you build next?
Once CO2 control works, pair it with humidity: a damp, stuffy room is the combination that feeds mould. Our mould risk alert and dehumidifier automation guides build on the same sensor-and-threshold approach, and you can combine all three into a single "air quality" dashboard card.







