Skip to content

Instantly share code, notes, and snippets.

@seanlinmt
Created December 29, 2020 02:22
Show Gist options
  • Select an option

  • Save seanlinmt/e3d0650dde335d47f5c6e4750bf1f622 to your computer and use it in GitHub Desktop.

Select an option

Save seanlinmt/e3d0650dde335d47f5c6e4750bf1f622 to your computer and use it in GitHub Desktop.

Revisions

  1. seanlinmt created this gist Dec 29, 2020.
    170 changes: 170 additions & 0 deletions livingroom.yaml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,170 @@
    esphome:
    name: livingroom
    platform: ESP32
    board: esp-wrover-kit
    platformio_options:
    board_build.partitions: min_spiffs.csv

    i2c:
    sda: 21
    scl: 22
    scan: True

    uart:
    rx_pin: 3
    baud_rate: 9600

    globals:
    - id: iaq_index
    type: int
    restore_value: no
    initial_value: '0'

    sensor:
    - platform: pmsx003
    type: PMSX003
    pm_1_0:
    name: "Livingroom PM1.0"
    pm_2_5:
    name: "Livingroom PM2.5"
    pm_10_0:
    name: "Livingroom PM10.0"
    - platform: bme280
    temperature:
    name: "Livingroom Temperature"
    id: temp
    oversampling: 16x
    pressure:
    name: "Livingroom Pressure"
    id: pressure
    humidity:
    name: "Livingroom Humidity"
    id: humi
    address: 0x76
    update_interval: 60s
    - platform: ccs811
    eco2:
    name: "Livingroom eCO2"
    id: eco2
    tvoc:
    name: "Livingroom TVOC"
    id: tvoc
    address: 0x5A
    temperature: temp
    humidity: humi
    update_interval: 60s

    text_sensor:
    - platform: template
    name: "Livingroom IAQ"
    icon: "mdi:air-filter"
    lambda: |-
    id(iaq_index) = 0;
    /*
    * Transform indoor humidity values to IAQ points according to Indoor Air Quality UK:
    * http://www.iaquk.org.uk/
    */
    if (id(humi).state < 10 or id(humi).state > 90) {
    id(iaq_index) += 1;
    }
    else if (id(humi).state < 20 or id(humi).state > 80) {
    id(iaq_index) += 2;
    }
    else if (id(humi).state < 30 or id(humi).state > 70) {
    id(iaq_index) += 3;
    }
    else if (id(humi).state < 40 or id(humi).state > 60) {
    id(iaq_index) += 4;
    }
    else if (id(humi).state >= 40 and id(humi).state <= 60) {
    id(iaq_index) += 5;
    }
    /*
    * Transform eCO2 values to IAQ points according to Indoor Air Quality UK:
    * http://www.iaquk.org.uk/
    */
    if (id(eco2).state <= 600) {
    id(iaq_index) += 5;
    }
    else if (id(eco2).state <= 800) {
    id(iaq_index) += 4;
    }
    else if (id(eco2).state <= 1500) {
    id(iaq_index) += 3;
    }
    else if (id(eco2).state <= 1800) {
    id(iaq_index) += 2;
    }
    else if (id(eco2).state > 1800) {
    id(iaq_index) += 1;
    }
    /*
    * Transform TVOC values to IAQ points according to German environmental guidelines:
    * https://www.repcomsrl.com/wp-content/uploads/2017/06/Environmental_Sensing_VOC_Product_Brochure_EN.pdf
    */
    if (id(tvoc).state <= 65) {
    id(iaq_index) += 5;
    }
    else if (id(tvoc).state <= 220) {
    id(iaq_index) += 4;
    }
    else if (id(tvoc).state <= 660) {
    id(iaq_index) += 3;
    }
    else if (id(tvoc).state <= 2200) {
    id(iaq_index) += 2;
    }
    else if (id(tvoc).state > 2200) {
    id(iaq_index) += 1;
    }
    /*
    * Transform IAQ index to human readable text according to Indoor Air Quality UK:
    * http://www.iaquk.org.uk/
    */
    ESP_LOGD("main", "Current IAQ index %d", id(iaq_index));
    if (id(iaq_index) <= 6) {
    return {"Unhealty"};
    }
    else if (id(iaq_index) <= 9) {
    return {"Poor"};
    }
    else if (id(iaq_index) <= 12) {
    return {"Moderate"};
    }
    else if (id(iaq_index) <= 14) {
    return {"Good"};
    }
    else if (id(iaq_index) > 14) {
    return {"Excellent"};
    }
    return {};
    update_interval: 60s

    wifi:
    ssid: "SSID"
    password: "PASSWORD"

    #manual_ip:
    # static_ip: 192.168.1.21
    # gateway: 192.168.1.1
    # subnet: 255.255.255.0

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

    captive_portal:

    # Enable logging
    logger:

    # Enable Home Assistant API
    api:

    ota: