AQI Wolby

mail@pastecode.io avatar unknown
yaml
2 years ago
33 kB
164
Indexable
Never
esphome:
  name: aqi_esp32
  platform: ESP32
  board: nodemcu-32s

wifi:
  ssid: 
  password: 

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: 
    password: 

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

# Setting up the pressure mats
esp32_touch:
# Delete this after you are done with the setup process
   setup_mode: true


# For the SDS011
uart:
  rx_pin: GPIO16
  tx_pin: GPIO17
  baud_rate: 9600

# For the CCS811
i2c:
  sda: GPIO21
  scl: GPIO22
  #id: bus_a

#For th AIQ
globals:
  - id: iaq_index
    type: int
    restore_value: no
    initial_value: '0'
  - id: component_index
    type: int
    restore_value: no
    initial_value: '0'


sensor:

  - platform: dht
    pin: GPIO18
    model: dht11
    temperature:
      name: "aux AQI Temperature"
      id: temp
      internal: true
    humidity:
      name: "aux AQI Humidity"
      id: humi
      internal: true
    update_interval: 10s
    
  - platform: sds011
    pm_2_5:
      name: "Particulate Matter <2.5µm Concentration"
      id: pm_2_5_sensor
      filters:  
      - lambda: if (0 <= x && x <= 600) return x; else return {};
    pm_10_0:
      name: "Particulate Matter <10.0µm Concentration"
      id: pm_10_sensor
      filters:
      - lambda: if (0 <= x && x <= 600) return x; else return {};
    update_interval: 10min
  
  - platform: ccs811
    eco2:
      name: "CCS811 eCO2 Value"
      accuracy_decimals : 3
      id: eco2_sensor
      filters:
      - lambda: if (0 <= x && x <= 8000) return x; else return {};
    tvoc:
      name: "CCS811 Total Volatile Organic Compound"
      accuracy_decimals : 3
      id: tvoc2_sensor
      filters:
      - lambda: if (0 <= x && x <= 8000) return x; else return {};
    address: 0x5A
    update_interval: 10s
    baseline: 0x447B
    temperature: temp
    humidity: humi
    
  - platform: homeassistant
    name: "terrace_temperature"
    entity_id: sensor.terrace_temperature
    id: outdoor_temperature

  - platform: template #CO2 Number
    name: "AQI_eco2"
    id: eco2_number
    icon: "mdi:molecule-co2"
    internal: true
    lambda: |-
      id(iaq_index) = 0;
      id(component_index) = 0;

      /*
       * Transform eCO2 values to IAQ points according to Indoor Air Quality UK: 
       * http://www.iaquk.org.uk/
       */
      if (id(eco2_sensor).state <= 600) {
        return 1.0;
      }
      else if (id(eco2_sensor).state <= 800) {
        return 2.0;
      }
      else if (id(eco2_sensor).state <= 1500) {
        return 3.0;
      }
      else if (id(eco2_sensor).state <= 1800) {
        return 4.0;
      }
      else if (id(eco2_sensor).state > 1800) {
        return 5.0;
      }
      return {};
    update_interval: 10s
    
  - platform: template #TVOC Number
    name: "AQI_tvoc"
    id: tvoc_number
    icon: "mdi:molecule"
    internal: true
    lambda: |-
      id(iaq_index) = 0;
      id(component_index) = 0;

      /*
       * 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(tvoc2_sensor).state <= 65) {
        return 1.0;
      }
      else if (id(tvoc2_sensor).state <= 220) {
        return 2.0;
      }
      else if (id(tvoc2_sensor).state <= 660) {
        return 3.0;
      }
      else if (id(tvoc2_sensor).state <= 2200) {
        return 4.0;
      }
      else if (id(tvoc2_sensor).state > 2200) {
        return 5.0;
      }
      
      return {};
    update_interval: 10s

  - platform: template #PM2.5 Number
    name: "AQI_pm2_5"
    id: AQI_pm25_number
    icon: "mdi:factory"
    internal: true
    lambda: |-
      id(iaq_index) = 0;
      id(component_index) = 0;

      /*
      * Transform PM 2.5 values to IAQ points according to UK environmental guidelines: 
      * https://blissair.com/what-is-pm-2-5.htm
      */
      if (id(pm_2_5_sensor).state <= 35.4) {
        return 1.0;
      }
      else if (id(pm_2_5_sensor).state <= 55.4) {
        return 2.0;
      }
      else if (id(pm_2_5_sensor).state <= 150.4) {
        return 3.0;
      }
      else if (id(pm_2_5_sensor).state <= 250.4) {
        return 4.0;
      }
      else if (id(pm_2_5_sensor).state > 500.4) {
        return 5.0;
      }

    update_interval: 10s

  - platform: template #PM10 Number
    name: "AQI_pm10"
    id: AQI_pm10_number
    icon: "mdi:broom"
    internal: true
    lambda: |-
      id(iaq_index) = 0;
      id(component_index) = 0;

      /*
      * Transform PM 10.0 values to IAQ points according to UK environmental guidelines: 
      * https://blissair.com/what-is-pm-2-5.htm
      */
      if (id(pm_10_sensor).state <= 54) {
        return 1.0;
      }
      else if (id(pm_10_sensor).state <= 155) {
        return 2.0;
      }
      else if (id(pm_10_sensor).state <= 25) {
        return 3.0;
      }
      else if (id(pm_10_sensor).state <= 355) {
        return 4.0;
      }
      else if (id(pm_10_sensor).state > 425) {
        return 5.0;
      }
      return {};
    update_interval: 10s
    
  - platform: template #AQI Index
    name: "AQI_number"
    id: AQI_number
    internal: true
    icon: "mdi:air-filter"
    lambda: |-
      id(iaq_index) = 0;
      id(component_index) = 0;

      /*
       * Transform indoor temperature values to IAQ points according to Indoor Air Quality UK: 
       * http://www.iaquk.org.uk/
       */
      if (id(temp).state < 14 or id(temp).state > 28) {
        id(iaq_index) = 1;
        id(component_index) = 1;
        ESP_LOGD("main", "temp %d", id(component_index));
      }
      else if (id(temp).state < 15 or id(temp).state > 27) {
        id(iaq_index) = 2;
        id(component_index) = 2;
        ESP_LOGD("main", "temp %d", id(component_index));
      }
      else if (id(temp).state < 16 or id(temp).state > 26) {
        id(iaq_index) = 3;
        id(component_index) = 3;
        ESP_LOGD("main", "temp %d", id(component_index));
      }
      else if (id(temp).state < 18 or id(temp).state > 23) {
        id(iaq_index) = 4;
        id(component_index) = 4;
        ESP_LOGD("main", "temp %d", id(component_index));
      }
      else if (id(temp).state >= 18 and id(temp).state <= 23) {
        id(iaq_index) = 5;
        id(component_index) = 5;
        ESP_LOGD("main", "temp %d", id(component_index));
      }

      /*
       * 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;
        id(component_index) = 1;
      }
      else if (id(humi).state < 20 or id(humi).state > 80) {
        id(iaq_index) += 2;
        id(component_index) = 2;    
      }
      else if (id(humi).state < 30 or id(humi).state > 70) {
        id(iaq_index) += 3;
        id(component_index) = 3;
      }
      else if (id(humi).state < 40 or id(humi).state > 60) {
        id(iaq_index) += 4;
        id(component_index) = 4;
      }
      else if (id(humi).state >= 40 and id(humi).state <= 60) {
        id(iaq_index) += 5;
        id(component_index) = 5;
      }
      
      /*
       * Transform eCO2 values to IAQ points according to Indoor Air Quality UK: 
       * http://www.iaquk.org.uk/
       */
      if (id(eco2_sensor).state <= 600) {
        id(iaq_index) += 5;
        id(component_index) = 5;
      }
      else if (id(eco2_sensor).state <= 800) {
        id(iaq_index) += 4;
        id(component_index) = 4;
      }
      else if (id(eco2_sensor).state <= 1500) {
        id(iaq_index) += 3;
        id(component_index) = 3;
      }
      else if (id(eco2_sensor).state <= 1800) {
        id(iaq_index) += 2;
        id(component_index) = 2;
      }
      else if (id(eco2_sensor).state > 1800) {
        id(iaq_index) += 1;
        id(component_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(tvoc2_sensor).state <= 65) {
        id(iaq_index) += 5;
        id(component_index) = 5;
      }
      else if (id(tvoc2_sensor).state <= 220) {
        id(iaq_index) += 4;
        id(component_index) = 4;
      }
      else if (id(tvoc2_sensor).state <= 660) {
        id(iaq_index) += 3;
        id(component_index) = 3;
      }
      else if (id(tvoc2_sensor).state <= 2200) {
        id(iaq_index) += 2;
        id(component_index) = 2;
      }
      else if (id(tvoc2_sensor).state > 2200) {
        id(iaq_index) += 1;
        id(component_index) = 1;
      }

      /*
      * Transform PM 2.5 values to IAQ points according to UK environmental guidelines: 
      * https://blissair.com/what-is-pm-2-5.htm
      */
      if (id(pm_2_5_sensor).state <= 35.4) {
        id(iaq_index) += 5;
        id(component_index) = 5;
      }
      else if (id(pm_2_5_sensor).state <= 55.4) {
        id(iaq_index) += 4;
        id(component_index) = 4;
      }
      else if (id(pm_2_5_sensor).state <= 150.4) {
        id(iaq_index) += 3;
        id(component_index) = 3;
      }
      else if (id(pm_2_5_sensor).state <= 250.4) {
        id(iaq_index) += 2;
        id(component_index) = 2;
      }
      else if (id(pm_2_5_sensor).state > 500.4) {
        id(iaq_index) += 1;
        id(component_index) = 1;
      }
      
      ESP_LOGD("main", "Current IAQ index %d", id(iaq_index));

      
      if (id(pm_10_sensor).state <= 54) {
        id(iaq_index) += 5;
        id(component_index) = 5;
      }
      else if (id(pm_10_sensor).state <= 155) {
        id(iaq_index) += 4;
        id(component_index) = 4;
      }
      else if (id(pm_10_sensor).state <= 255) {
        id(iaq_index) += 3;
        id(component_index) = 3;
      }
      else if (id(pm_10_sensor).state <= 355) {
        id(iaq_index) += 2;
        id(component_index) = 2;
      }
      else if (id(pm_10_sensor).state > 425) {
        id(iaq_index) += 1;
        id(component_index) = 1;
      }
      
      
      if (id(iaq_index) <= 9) {
        return 1;
      }
      else if (id(iaq_index) <= 15) {
        return 2;
      }
      else if (id(iaq_index) <= 24) {
        return 3;
      }
      else if (id(iaq_index) <= 27) {
        return 4;
      }
      else if (id(iaq_index) >= 28) {
        return 5;
      }
      
    update_interval: 10s


text_sensor:  
  - platform: homeassistant
    name: "weather_condition"
    entity_id: sensor.openweathermap_condition
    id: 'weather_condition'
  - platform: template #AQI Sgtring
    name: "AQI"
    icon: "mdi:air-filter"
    lambda: |-
      id(iaq_index) = 0;
      id(component_index) = 0;


      /*
       * Transform indoor temperature values to IAQ points according to Indoor Air Quality UK: 
       * http://www.iaquk.org.uk/
       */
      if (id(temp).state < 14 or id(temp).state > 28) {
        id(iaq_index) = 1;
        id(component_index) = 1;
      }
      else if (id(temp).state < 15 or id(temp).state > 27) {
        id(iaq_index) = 2;
        id(component_index) = 2;
      }
      else if (id(temp).state < 16 or id(temp).state > 26) {
        id(iaq_index) = 3;
        id(component_index) = 3;
      }
      else if (id(temp).state < 18 or id(temp).state > 23) {
        id(iaq_index) = 4;
        id(component_index) = 4;
      }
      else if (id(temp).state >= 18 and id(temp).state <= 23) {
        id(iaq_index) = 5;
        id(component_index) = 5;
      }

      /*
       * 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;
        id(component_index) = 1;
      }
      else if (id(humi).state < 20 or id(humi).state > 80) {
        id(iaq_index) += 2;
        id(component_index) = 2;    
      }
      else if (id(humi).state < 30 or id(humi).state > 70) {
        id(iaq_index) += 3;
        id(component_index) = 3;
      }
      else if (id(humi).state < 40 or id(humi).state > 60) {
        id(iaq_index) += 4;
        id(component_index) = 4;
      }
      else if (id(humi).state >= 40 and id(humi).state <= 60) {
        id(iaq_index) += 5;
        id(component_index) = 5;
      }
      

      /*
       * Transform eCO2 values to IAQ points according to Indoor Air Quality UK: 
       * http://www.iaquk.org.uk/
       */
      if (id(eco2_sensor).state <= 600) {
        id(iaq_index) += 5;
        id(component_index) = 5;
      }
      else if (id(eco2_sensor).state <= 800) {
        id(iaq_index) += 4;
        id(component_index) = 4;
      }
      else if (id(eco2_sensor).state <= 1500) {
        id(iaq_index) += 3;
        id(component_index) = 3;
      }
      else if (id(eco2_sensor).state <= 1800) {
        id(iaq_index) += 2;
        id(component_index) = 2;
      }
      else if (id(eco2_sensor).state > 1800) {
        id(iaq_index) += 1;
        id(component_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(tvoc2_sensor).state <= 65) {
        id(iaq_index) += 5;
        id(component_index) = 5;
      }
      else if (id(tvoc2_sensor).state <= 220) {
        id(iaq_index) += 4;
        id(component_index) = 4;
      }
      else if (id(tvoc2_sensor).state <= 660) {
        id(iaq_index) += 3;
        id(component_index) = 3;
      }
      else if (id(tvoc2_sensor).state <= 2200) {
        id(iaq_index) += 2;
        id(component_index) = 2;
      }
      else if (id(tvoc2_sensor).state > 2200) {
        id(iaq_index) += 1;
        id(component_index) = 1;
      }


      /*
      * Transform PM 2.5 values to IAQ points according to UK environmental guidelines: 
      * https://blissair.com/what-is-pm-2-5.htm
      */
      if (id(pm_2_5_sensor).state <= 35.4) {
        id(iaq_index) += 5;
        id(component_index) = 5;
      }
      else if (id(pm_2_5_sensor).state <= 55.4) {
        id(iaq_index) += 4;
        id(component_index) = 4;
      }
      else if (id(pm_2_5_sensor).state <= 150.4) {
        id(iaq_index) += 3;
        id(component_index) = 3;
      }
      else if (id(pm_2_5_sensor).state <= 250.4) {
        id(iaq_index) += 2;
        id(component_index) = 2;
      }
      else if (id(pm_2_5_sensor).state > 500.4) {
        id(iaq_index) += 1;
        id(component_index) = 1;
      }
      

      /*
      * Transform PM 10.0 values to IAQ points according to UK environmental guidelines: 
      * https://blissair.com/what-is-pm-2-5.htm
      */
      if (id(pm_10_sensor).state <= 54) {
        id(iaq_index) += 5;
        id(component_index) = 5;
      }
      else if (id(pm_10_sensor).state <= 155) {
        id(iaq_index) += 4;
        id(component_index) = 4;
      }
      else if (id(pm_10_sensor).state <= 255) {
        id(iaq_index) += 3;
        id(component_index) = 3;
      }
      else if (id(pm_10_sensor).state <= 355) {
        id(iaq_index) += 2;
        id(component_index) = 2;
      }
      else if (id(pm_10_sensor).state > 425) {
        id(iaq_index) += 1;
        id(component_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) <= 9) {
        return {"Unhealty"};
      }
      else if (id(iaq_index) <= 15) {
        return {"Poor"};
      }
      else if (id(iaq_index) <= 24) {
        return {"Moderate"};
      }
      else if (id(iaq_index) <= 27) {
        return {"Good"};
      }
      else if (id(iaq_index) >= 28) {
        return {"Excellent"};
      }
      
      return {};
    update_interval: 10s

  - platform: template #Temperature String
    name: "AQI_tmp"
    icon: "mdi:thermometer"
    lambda: |-
      id(iaq_index) = 0;
      id(component_index) = 0;

      /*
       * Transform indoor temperature values to IAQ points according to Indoor Air Quality UK: 
       * http://www.iaquk.org.uk/
       */
      if (id(temp).state < 14 or id(temp).state > 28) {
        id(iaq_index) += 1;
        id(component_index) = 1;
      }
      else if (id(temp).state < 15 or id(temp).state > 27) {
        id(iaq_index) += 2;
        id(component_index) = 2;
      }
      else if (id(temp).state < 16 or id(temp).state > 26) {
        id(iaq_index) += 3;
        id(component_index) = 3;
      }
      else if (id(temp).state < 18 or id(temp).state > 23) {
        id(iaq_index) += 4;
        id(component_index) = 4;
      }
      else if (id(temp).state >= 18 and id(temp).state <= 23) {
        id(iaq_index) += 5;
        id(component_index) = 5;
      }
            
      if (id(iaq_index) <= 1) {
        return {"Unhealty"};
      }
      else if (id(iaq_index) <= 2) {
        return {"Poor"};
      }
      else if (id(iaq_index) <= 3) {
        return {"Moderate"};
      }
      else if (id(iaq_index) <= 4) {
        return {"Good"};
      }
      else if (id(iaq_index) >= 5) {
        return {"Excellent"};
      }
      
      return {};
    update_interval: 10s #Temperature String

  - platform: template #Humidity String
    name: "AQI_humi"
    icon: "mdi:water-percent"
    lambda: |-
      id(iaq_index) = 0;
      id(component_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;
        id(component_index) = 1;
      }
      else if (id(humi).state < 20 or id(humi).state > 80) {
        id(iaq_index) += 2;
        id(component_index) = 2;    
      }
      else if (id(humi).state < 30 or id(humi).state > 70) {
        id(iaq_index) += 3;
        id(component_index) = 3;
      }
      else if (id(humi).state < 40 or id(humi).state > 60) {
        id(iaq_index) += 4;
        id(component_index) = 4;
      }
      else if (id(humi).state >= 40 and id(humi).state <= 60) {
        id(iaq_index) += 5;
        id(component_index) = 5;
      }

      if (id(iaq_index) <= 1) {
        return {"Unhealty"};
      }
      else if (id(iaq_index) <= 2) {
        return {"Poor"};
      }
      else if (id(iaq_index) <= 3) {
        return {"Moderate"};
      }
      else if (id(iaq_index) <= 4) {
        return {"Good"};
      }
      else if (id(iaq_index) >= 5) {
        return {"Excellent"};
      }
      
      return {};
    update_interval: 10s

  - platform: template #CO2 String
    name: "AQI_eco2"
    icon: "mdi:molecule-co2"
    lambda: |-
      id(iaq_index) = 0;
      id(component_index) = 0;

      /*
       * Transform eCO2 values to IAQ points according to Indoor Air Quality UK: 
       * http://www.iaquk.org.uk/
       */
      if (id(eco2_sensor).state <= 600) {
        id(iaq_index) += 5;
        id(component_index) = 5;
      }
      else if (id(eco2_sensor).state <= 800) {
        id(iaq_index) += 4;
        id(component_index) = 4;
      }
      else if (id(eco2_sensor).state <= 1500) {
        id(iaq_index) += 3;
        id(component_index) = 3;
      }
      else if (id(eco2_sensor).state <= 1800) {
        id(iaq_index) += 2;
        id(component_index) = 2;
      }
      else if (id(eco2_sensor).state > 1800) {
        id(iaq_index) += 1;
        id(component_index) = 1;
      }

      if (id(iaq_index) <= 1) {
        return {"Unhealty"};
      }
      else if (id(iaq_index) <= 2) {
        return {"Poor"};
      }
      else if (id(iaq_index) <= 3) {
        return {"Moderate"};
      }
      else if (id(iaq_index) <= 4) {
        return {"Good"};
      }
      else if (id(iaq_index) >= 5) {
        return {"Excellent"};
      }
      
      return {};
    update_interval: 10s

  - platform: template #TVOC String
    name: "AQI_tvoc"
    icon: "mdi:molecule"
    lambda: |-
      id(iaq_index) = 0;
      id(component_index) = 0;

      /*
       * 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(tvoc2_sensor).state <= 65) {
        id(iaq_index) += 5;
        id(component_index) = 5;
      }
      else if (id(tvoc2_sensor).state <= 220) {
        id(iaq_index) += 4;
        id(component_index) = 4;
      }
      else if (id(tvoc2_sensor).state <= 660) {
        id(iaq_index) += 3;
        id(component_index) = 3;
      }
      else if (id(tvoc2_sensor).state <= 2200) {
        id(iaq_index) += 2;
        id(component_index) = 2;
      }
      else if (id(tvoc2_sensor).state > 2200) {
        id(iaq_index) += 1;
        id(component_index) = 1;
      }

      if (id(iaq_index) <= 1) {
        return {"Unhealty"};
      }
      else if (id(iaq_index) <= 2) {
        return {"Poor"};
      }
      else if (id(iaq_index) <= 3) {
        return {"Moderate"};
      }
      else if (id(iaq_index) <= 4) {
        return {"Good"};
      }
      else if (id(iaq_index) >= 5) {
        return {"Excellent"};
      }
      
      return {};
    update_interval: 10s

  - platform: template #PM2.5 String
    name: "AQI_pm2_5"
    icon: "mdi:factory"
    lambda: |-
      id(iaq_index) = 0;
      id(component_index) = 0;

      /*
      * Transform PM 2.5 values to IAQ points according to UK environmental guidelines: 
      * https://blissair.com/what-is-pm-2-5.htm
      */
      if (id(pm_2_5_sensor).state <= 35.4) {
        id(iaq_index) += 5;
        id(component_index) = 5;
      }
      else if (id(pm_2_5_sensor).state <= 55.4) {
        id(iaq_index) += 4;
        id(component_index) = 4;
      }
      else if (id(pm_2_5_sensor).state <= 150.4) {
        id(iaq_index) += 3;
        id(component_index) = 3;
      }
      else if (id(pm_2_5_sensor).state <= 250.4) {
        id(iaq_index) += 2;
        id(component_index) = 2;
      }
      else if (id(pm_2_5_sensor).state > 500.4) {
        id(iaq_index) += 1;
        id(component_index) = 1;
      }
      

      if (id(iaq_index) <= 1) {
        return {"Unhealty"};
      }
      else if (id(iaq_index) <= 2) {
        return {"Poor"};
      }
      else if (id(iaq_index) <= 3) {
        return {"Moderate"};
      }
      else if (id(iaq_index) <= 4) {
        return {"Good"};
      }
      else if (id(iaq_index) >= 5) {
        return {"Excellent"};
      }
      
      return {};
    update_interval: 10s

  - platform: template #PM10 String
    name: "AQI_pm10"
    icon: "mdi:broom"
    lambda: |-
      id(iaq_index) = 0;
      id(component_index) = 0;

      /*
      * Transform PM 10.0 values to IAQ points according to UK environmental guidelines: 
      * https://blissair.com/what-is-pm-2-5.htm
      */
      if (id(pm_10_sensor).state <= 54) {
        id(iaq_index) += 5;
        id(component_index) = 5;
      }
      else if (id(pm_10_sensor).state <= 155) {
        id(iaq_index) += 4;
        id(component_index) = 4;
      }
      else if (id(pm_10_sensor).state <= 25) {
        id(iaq_index) += 3;
        id(component_index) = 3;
      }
      else if (id(pm_10_sensor).state <= 355) {
        id(iaq_index) += 2;
        id(component_index) = 2;
      }
      else if (id(pm_10_sensor).state > 425) {
        id(iaq_index) += 1;
        id(component_index) = 1;
      }

      if (id(iaq_index) <= 1) {
        return {"Unhealty"};
      }
      else if (id(iaq_index) <= 2) {
        return {"Poor"};
      }
      else if (id(iaq_index) <= 3) {
        return {"Moderate"};
      }
      else if (id(iaq_index) <= 4) {
        return {"Good"};
      }
      else if (id(iaq_index) >= 5) {
        return {"Excellent"};
      }
      
      return {};
    update_interval: 10s


#SCREEN CONFIG
spi: #Screen config
  clk_pin: GPIO33
  mosi_pin: GPIO32 #DIN  

time:
  - platform: sntp
    timezone: Europe/Paris
    id: sntp_time
    
font:
  - file: "fonts/Bookerly-Regular.ttf"
    id: text_font_small
    size: 17
  - file: "fonts/Bookerly-Regular.ttf"
    id: text_font_small_time_temp
    size: 15
    glyphs:  ['!', ',', '.', '"', '%', '-', '_', ':', 'º', '/','C',
       '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ' ']

  - file: "fonts/Bookerly-Regular.ttf"
    id: text_font_tiny
    size: 10
  - file: "fonts/Bookerly-Regular.ttf"
    id: text_font_big
    size: 40
  - file: "fonts/materialdesignicons-webfont.ttf"
    id: icon_font_30
    size: 30
    glyphs: [
      󰟤, #mdi-molecule-co2
      󰮬, #mdi-molecule
      󰈏, #mdi-factory
      󰃢, #mdi-broom
      󰵃, #mdi-air-filter
      󰖙, #mdi-weather-sunny
      󰖗, #mdi-weather-rainy
      󰖕,#mdi-weather-partly-cloudy
      󰖘, #mdi-weather-snowy-heavy 
      󰼇, #error
      󰖐, #mdi-weather-cloudy
      󰦖 #mdi-progress-clock
      
    ]
  - file: "fonts/materialdesignicons-webfont.ttf"
    id: icon_font_40
    size: 35
    glyphs: [
      󰟤, #mdi-molecule-co2
      󰮬, #mdi-molecule
      󰈏, #mdi-factory
      󰃢, #mdi-broom
      󰵃, #mdi-air-filter
      󰖙, #mdi-weather-sunny
      󰖗, #mdi-weather-rainy
      󰖕,#mdi-weather-partly-cloudy
      󰖘, #mdi-weather-snowy-heavy
      󰖐, #mdi-weather-cloudy
      󰼇, #mdi-error
      󰦖 #mdi-progress-clock
    ]

display:
  - platform: waveshare_epaper
    id: my_display
    cs_pin: GPIO25
    dc_pin: GPIO26
    busy_pin: GPIO14
    reset_pin: GPIO27
    model: 4.20in
    update_interval: 60s
    lambda: |-

      // Variable definitions
      int screen_x = 400;
      int screen_y = 300;
       
      int left_margin = 20;
      int right_margin = screen_x - left_margin;
      int top_margin = 10;
      int bottom_margin = screen_y - top_margin;
       
      int a_third = (right_margin - left_margin)/3;
      int x_1rd = a_third + left_margin;
      int x_2rd = x_1rd + a_third;
       
      int circle_radius = 12;
      int circle_y_dist = 32;
       
      int CO2_center = left_margin + circle_radius;
      int pm10_center = x_2rd - circle_radius;
      int between_column_space = rint((pm10_center - CO2_center)/3);
      int tvoc_center =  CO2_center + between_column_space; //104; 
      int pm25_center = tvoc_center + between_column_space; //176; 

      int circle_botton_alineation = 190;
      int name_botton_alineation = 260;
      int icon_botton_alineation = 225;
      int value_botton_alineation = 280;
       
      int exterior_big_circle_radius = (right_margin-(x_2rd+circle_radius))/2;
      int interior_big_circle_radius = exterior_big_circle_radius - 3;
      int big_y_circle_center = rint(screen_y/2);
      int big_x_circle_center = (pm10_center + circle_radius) + between_column_space;

      int weather_icon_x = 5;
      int weather_icon_y = 25;
      int temperature_x = 40; 
      int time_location_x = screen_x - weather_icon_x - 40;

      //Weather and terrace temperature
      
      if (id(weather_condition).has_state()) {
        if (strcmp(id(weather_condition).state.c_str(),"sunny")==0) { 
          it.printf(weather_icon_x, weather_icon_y, id(icon_font_30),TextAlign::BASELINE, "󰖙");  
        } else if(strcmp(id(weather_condition).state.c_str(),"partlycloudy")==0) {
          it.printf(weather_icon_x, weather_icon_y, id(icon_font_30),TextAlign::BASELINE, "󰖕"); 
        } else if(strcmp(id(weather_condition).state.c_str(),"cloudy")==0) {
          it.printf(weather_icon_x, weather_icon_y, id(icon_font_30),TextAlign::BASELINE, "󰖐"); 
        } else {
          it.printf(weather_icon_x, weather_icon_y, id(icon_font_30),TextAlign::BASELINE, "󰷆"); //state not defined
        }
      } else {
          it.printf(weather_icon_x, weather_icon_y, id(icon_font_30),TextAlign::BASELINE, "󰦖");  //Progress
      }
      
      it.printf(temperature_x, weather_icon_y, id(text_font_small_time_temp),TextAlign::BOTTOM,"%.1fºC",id(outdoor_temperature).state);
      
      //Print the time
      int time = id(sntp_time).now().hour * 100 + id(sntp_time).now().minute;
      it.strftime(time_location_x, weather_icon_y, id(text_font_small_time_temp),TextAlign::BOTTOM, "%H:%M", id(sntp_time).now());

       
      //CO2 printing//
      //Icon & Name
      
      int measurement = 0;
      if (id(eco2_sensor).has_state()) {
        measurement = id(eco2_sensor).state;
      } 
      
      it.printf(CO2_center,icon_botton_alineation, id(icon_font_40),TextAlign::CENTER,"󰟤");
      it.printf(CO2_center,name_botton_alineation, id(text_font_small),TextAlign::CENTER,"CO2");
      it.printf(CO2_center,value_botton_alineation, id(text_font_tiny),TextAlign::CENTER,"%d ppm",measurement);
      
      int limit_c02 = 0;
      if (id(eco2_number).has_state()) {
        limit_c02 = id(eco2_number).state;
      } 
      

      //Quality bar
      for (int i = 0; i < 5; i++) {
        if (i<limit_c02){
          it.filled_circle(CO2_center, circle_botton_alineation+(-i*circle_y_dist), circle_radius);
        } else {
          it.circle(CO2_center, circle_botton_alineation+(-i*circle_y_dist), circle_radius);
        }
      }

      //TVOC printing//
      //Icon & Name
      measurement = 0;
      if (id(tvoc2_sensor).has_state()) {
        measurement = id(tvoc2_sensor).state;
      }
      
      it.printf(tvoc_center,icon_botton_alineation, id(icon_font_40),TextAlign::CENTER,"󰮬");
      it.printf(tvoc_center,name_botton_alineation, id(text_font_small),TextAlign::CENTER,"TVoc");
      it.printf(tvoc_center,value_botton_alineation, id(text_font_tiny),TextAlign::CENTER,"%d ppm",measurement);

      int limit_tvoc = 0;
      if (id(tvoc_number).has_state()) {
        limit_tvoc = id(tvoc_number).state;
      } 
      


      //Quality bar
      for (int i = 0; i < 5; i++) {
        if (i<limit_tvoc){
          it.filled_circle(tvoc_center, circle_botton_alineation+(-i*circle_y_dist), circle_radius);
        } else {
          it.circle(tvoc_center, circle_botton_alineation+(-i*circle_y_dist), circle_radius);
        }
      }

      //PM2.5 printing//
      //Icon & Name
      
      measurement = 0;
      if (id(pm_2_5_sensor).has_state()) {
        measurement = id(pm_2_5_sensor).state;
      } 
      
      it.printf(pm25_center,icon_botton_alineation, id(icon_font_40),TextAlign::CENTER,"󰈏");
      it.printf(pm25_center,name_botton_alineation, id(text_font_small),TextAlign::CENTER,"PM2.5");
      it.printf(pm25_center,value_botton_alineation, id(text_font_tiny),TextAlign::CENTER,"%d um",measurement);

      int limit_pm25 = 0;
      if (id(AQI_pm25_number).has_state()) {
        limit_pm25 = id(AQI_pm25_number).state;
      } 
      


      //Quality bar
      for (int i = 0; i < 5; i++) {
        if (i<limit_pm25){
          it.filled_circle(pm25_center, circle_botton_alineation+(-i*circle_y_dist), circle_radius);
        } else {
          it.circle(pm25_center, circle_botton_alineation+(-i*circle_y_dist), circle_radius);
        }
      }

      //PM10 printing//
      measurement = 0;
      if (id(pm_10_sensor).has_state()) {
        measurement = id(pm_10_sensor).state;
      } 
      //Icon & Name
      it.printf(pm10_center,icon_botton_alineation, id(icon_font_40),TextAlign::CENTER,"󰃢");
      it.printf(pm10_center,name_botton_alineation, id(text_font_small),TextAlign::CENTER,"PM10");
      it.printf(pm10_center,value_botton_alineation, id(text_font_tiny),TextAlign::CENTER,"%d um", measurement);
       
      int limit_pm10 = 0;
      if (id(AQI_pm10_number).has_state()) {
        limit_pm10 = id(AQI_pm10_number).state;
      } 
      


       
      //Quality bar
      for (int i = 0; i < 5; i++) {
        if (i<limit_pm10){
          it.filled_circle(pm10_center, circle_botton_alineation+(-i*circle_y_dist), circle_radius);
        } else {
          it.circle(pm10_center, circle_botton_alineation+(-i*circle_y_dist), circle_radius);
        }
      }
       
      //Big circle painting
      it.filled_circle(big_x_circle_center, big_y_circle_center, exterior_big_circle_radius);
      it.filled_circle(big_x_circle_center, big_y_circle_center, interior_big_circle_radius, COLOR_OFF);
      
      //Big circle number
      int aqi = 0;
      if (id(AQI_number).has_state()) {
        aqi = id(AQI_number).state;
      } 
      it.printf(big_x_circle_center,big_y_circle_center-5, id(text_font_big),TextAlign::CENTER,"%d",aqi);
      it.printf(big_x_circle_center,big_y_circle_center+25, id(text_font_small),TextAlign::CENTER,"AQI");