Skip to content

Instantly share code, notes, and snippets.

@mainar
Last active January 9, 2025 13:01
Show Gist options
  • Save mainar/c79699ae2886d69e43dab49d8bec3c53 to your computer and use it in GitHub Desktop.
Save mainar/c79699ae2886d69e43dab49d8bec3c53 to your computer and use it in GitHub Desktop.
substitutions:
device_name: air-quality2
wifi_ssid: !secret wifi_ssid
wifi_password: !secret wifi_password
api_password: !secret api_password
ota_password: !secret ota_password
globals:
- id: led_brightness
type: float
restore_value: no
initial_value: '0.4'
esphome:
name: ${device_name}
comment: IKEA LaskaKit ESP-VINDRIKTNING ESP-32 I2C
on_boot:
then:
- lambda: |-
auto call = id(status_led_top).turn_on();
call.set_brightness(id(led_brightness));
call.set_rgb(1.0,1.0,1.0); // white
call.perform();
- lambda: |-
auto call = id(status_led_middle).turn_on();
call.set_brightness(id(led_brightness));
call.set_rgb(1.0,1.0,1.0); // white
call.perform();
- lambda: |-
auto call = id(status_led_bottom).turn_on();
call.set_brightness(id(led_brightness));
call.set_rgb(1.0,1.0,1.0); // white
call.perform();
esp32:
board: nodemcu-32s
framework:
type: arduino
wifi:
ssid: ${wifi_ssid}
password: ${wifi_password}
api:
password: ${api_password}
reboot_timeout: 0s
services:
- service: calibrate_co2_value
variables:
co2_ppm: int
then:
- scd4x.perform_forced_calibration:
value: !lambda 'return co2_ppm;'
id: scd41
ota:
- platform: esphome
password: ${ota_password}
# Enable logging
logger:
#level: VERBOSE
uart:
rx_pin: 16
tx_pin: 17
baud_rate: 9600
id: uartbus
sensor:
#- platform: bme280_i2c
# temperature:
# name: "BME280 Temperature"
# oversampling: 16x
# pressure:
# name: "BME280 Pressure"
# humidity:
# name: "BME280 Humidity"
# update_interval: 60s
- platform: scd4x
id: scd41
humidity:
name: "SCD41 Humidity"
id: humidity
#filters:
# offset: -12.0
on_value:
lambda: |-
auto call = id(status_led_top).turn_on();
call.set_brightness(id(led_brightness));
if (x < 30) {
call.set_rgb(1.0,0.75,0.0); } // orange
else if ((x >= 30) and (x < 40)) {
call.set_rgb(1.0,1.0,0.0); } // yellow
else if ((x >= 40) and (x < 50)) {
call.set_rgb(0.0,1.0,0.0); } // green
else if ((x >= 50) and (x < 60)) {
call.set_rgb(0.0,1.0,1.0); } // turquoise
else if (x >= 60) {
call.set_rgb(1.0,0.0,1.0); } // violet
call.perform();
co2:
name: "SCD41 CO2"
id: co2
on_value:
lambda: |-
auto call = id(status_led_middle).turn_on();
call.set_brightness(id(led_brightness));
if (x < 1000) {
call.set_rgb(0.0,1.0,0.0); } // green
else if ((x >= 1000) and (x < 1500)) {
call.set_rgb(1.0,1.0,0.0); } // yellow
else if ((x >= 1500) and (x < 2000)) {
call.set_rgb(1.0,0.75,0.0); } // orange
else if (x >= 2000) {
call.set_rgb(1.0,0.0,0.0); } // red
call.perform();
temperature:
name: "SCD41 Temperature"
update_interval: 60s
- platform: pm1006
pm_2_5:
name: "Particulate Matter 2.5µm Concentration"
id: pm25
accuracy_decimals: 1
on_value:
lambda: |-
auto call = id(status_led_bottom).turn_on();
call.set_brightness(id(led_brightness));
if (x < 30) {
call.set_rgb(0.0,1.0,0.0); } // green
else if ((x >= 30) and (x < 60)) {
call.set_rgb(1.0,1.0,0.0); } // yellow
else if ((x >= 60) and (x < 110)) {
call.set_rgb(1.0,0.75,0.0); } // orange
else if (x >= 110) {
call.set_rgb(1.0,0.0,0.0); } // red
call.perform();
uart_id: uartbus
update_interval: 60s
- platform: wifi_signal
name: "Air quality WiFi Signal Sensor"
entity_category: diagnostic
disabled_by_default: true
update_interval: 60s
- platform: adc
pin: 33
name: "brightness"
# attenuation: 11dB
update_interval: 60s
- platform: sun
name: Sun Elevation
type: elevation
on_value:
- if:
condition:
- sun.is_above_horizon:
then:
- lambda: |-
id(led_brightness) = 0.5;
else:
- lambda: |-
id(led_brightness) = 0.3;
- platform: sun
name: Sun Azimuth
type: azimuth
switch:
- platform: gpio
pin: 12
id: fan
restore_mode: ALWAYS_ON
disabled_by_default: true
entity_category: diagnostic
light:
- platform: neopixelbus
type: GRB
variant: WS2812X
pin: GPIO25
num_leds: 3
id: status_leds
restore_mode: ALWAYS_OFF
- platform: partition
name: "Status LED humidity"
id: status_led_top
segments:
- id: status_leds
from: 2
to: 2
- platform: partition
name: "Status LED co2"
id: status_led_middle
segments:
- id: status_leds
from: 1
to: 1
- platform: partition
name: "Status LED particulates"
id: status_led_bottom
segments:
- id: status_leds
from: 0
to: 0
i2c:
sda: 21
scl: 22
scan: true
id: bus_a
button:
- platform: restart
name: "Restart ${device_name}"
id: restart_aq
disabled_by_default: true
entity_category: diagnostic
time:
- platform: sntp
id: sntp_time
servers:
- tik.cesnet.cz
- tak.cesnet.cz
timezone: Europe/Prague
update_interval: 60min
on_time:
# restart at 12:00 every 2nd day to perform PM1006 auto calibration
- cron: '0 0 12 2/2 * *'
then:
button.press: restart_aq
sun:
# nearby Europe/Czech Republic/Prague
latitude: 50.1
longitude: 14.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment