Skip to content

ESPHome firmware #11

@LukeMondy

Description

@LukeMondy

Hello

I was messing around yesterday and got ESPHome working barebones (CO2 sensor + LED working).

I'm just posting in-case anyone else was interested:

esphome:
  name: esphome-web-1d237a
  friendly_name: CO2 sensor
  min_version: 2025.5.0
  name_add_mac_suffix: false

esp8266:
  board: esp01_1m

# Enable logging
logger:

# Enable Home Assistant API
api:
  actions:
    - action: calibrate_co2_value
      variables:
        co2_ppm: int
      then:
      - scd4x.perform_forced_calibration:
          value: !lambda 'return co2_ppm;'
          id: my_scd41

# Allow Over-The-Air updates
ota:
- platform: esphome

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "co2 Fallback Hotspot"
    password: "xxx"

switch:
  - platform: gpio
    pin: 14  # this is fake
    name: LED tracks CO2
    id: led_on
    restore_mode: ALWAYS_OFF

light:
  - platform: neopixelbus
    type: GRB
    variant: 800KBPS
    pin: GPIO12
    num_leds: 1
    name: "Light"
    id: led

i2c:
  sda: GPIO0
  scl: GPIO2
  scan: true

sensor:
  - platform: scd4x
    id: my_scd41
    address: 0x62
    co2:
      name: "CO2"
      on_value: 
        then:
        - if:
            condition:
              lambda: 'return id(led_on).state;'
            then:
              - light.turn_on: 
                  id: led
                  red: !lambda |-
                    if (x > 1000.0) { return 1.0; } else { return 0.0; }
                  green: !lambda |-
                    if (x < 2000.0) { return 1.0; } else { return 0.0; }
                  blue: 0.0
            else:
              - light.turn_off: led
    temperature:
      name: "Temperature"
    temperature_offset: 7.3
    humidity:
      name: "Humidity"
    update_interval: 7s
    altitude_compensation: 235m

It ends up showing up like this:

Image

Which means you can tell the LED to track the CO2 or not (going either green, yellow, or red, depending on the value of CO2). Nice if you want to sleep in the same room as the sensor.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions