# HG changeset patch # User drewp@bigasterisk.com # Date 1722575890 25200 # Node ID dcd981e1386b2e42470ea42ef65cb1405da1175f # Parent 2f2a34ed4ead9f5dc5be6573477f038daa03c039 br-air-quality has new screen layout; wifi connection blinks; etc (tr-a-q is behind) diff -r 2f2a34ed4ead -r dcd981e1386b br-air-quality.yaml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/br-air-quality.yaml Thu Aug 01 22:18:10 2024 -0700 @@ -0,0 +1,166 @@ +# https://cdn.shopifycdn.net/s/files/1/0617/7190/7253/files/T-display-pin-diagram_1024x1024.jpg +# https://www.aqmd.gov/docs/default-source/aq-spec/resources-page/plantower-pms5003-manual_v2-3.pdf +esphome: + name: "br-air-quality" + platform: ESP32 + board: featheresp32 + on_boot: + priority: 590 + then: + - script.execute: on_wifi_disconnect + +logger: + level: DEBUG + logs: + sensor: INFO + pmsx003: INFO + +wifi: + networks: + - ssid: !secret wifi_ssid + password: !secret wifi_password + on_connect: + then: + - script.execute: on_wifi_connect + on_disconnect: + then: + - script.execute: on_wifi_disconnect + +ota: + platform: esphome + password: !secret ota_password_1 + +mqtt: + id: mqtt_client + broker: 'mqtt2.bigasterisk.com' + + # pms pin 1 (blk) to 5V + # pms pin 2 (red) to gnd NEXT TO ESP PIN 12!! + # pms pin 3 (blk) NC +# original setup +# GPIO13/RXD2 num 16 = pms tx (pin 5 blk) +# GPIO15/TXD2 num 17 = pms rx (pin 4 red) +# or on T-Display ESP32, +# pms tx pin 5 to esp 13 +# pms rx pin 4 tp esp 17 +# led strip: +5/gnd like pms; DIN to esp 27 +uart: + rx_pin: 13 + baud_rate: 9600 + +sensor: + - platform: pmsx003 + type: PMS5003T + pm_1_0: + name: "Particulate Matter <1.0µm Concentration" + pm_2_5: + name: "Particulate Matter <2.5µm Concentration" + id: pm_2_5 + pm_10_0: + name: "Particulate Matter <10.0µm Concentration" + temperature: + name: "air temperature C" + id: air_temp_c + + - platform: wifi_signal + id: my_wifi_signal + name: wifi_signal + update_interval: 4s + internal: true # no mqtt + +spi: + clk_pin: GPIO18 + mosi_pin: GPIO19 + +font: + - file: 'fonts/PassionOne-Regular.ttf' + id: font_14 + size: 34 + glyphs: "%-.°0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ " + +color: + - { id: color_title, hex: 88888a } + - { id: color_wifi_h, hex: 5998de } + - { id: color_wifi_b, hex: aec9e2 } + - { id: color_pm_h, hex: 5998de } + - { id: color_pm_b, hex: aec9e2 } + - { id: color_temp_h, hex: 5998de } + - { id: color_temp_b, hex: aec9e2 } + +output: + - platform: ledc + pin: GPIO04 + id: gpio_04_backlight_pwm + +light: + - platform: monochromatic + output: gpio_04_backlight_pwm + name: "Display Backlight" + id: back_light + restore_mode: ALWAYS_ON + + - platform: fastled_clockless + chipset: WS2812 + pin: GPIO27 + num_leds: 8 + rgb_order: GRB + name: "strip1" + id: strip1 + effects: + - pulse: + name: "wifi_connecting_effect" + transition_length: 0.5s + update_interval: 0.5s + min_brightness: 0% + max_brightness: 20% + +script: + - id: on_wifi_disconnect + then: + - light.turn_on: + id: strip1 + effect: "wifi_connecting_effect" + color_brightness: 100% + red: 100% + green: 0% + blue: 0% + - id: on_wifi_connect + then: + - light.turn_off: + id: strip1 + +display: + # see note at https://esphome.io/components/display/ili9xxx#:~:text=For-,Lilygo%20TTGO%20Boards,-if%20you%20move + - platform: ili9xxx + model: st7789v + dimensions: + height: 240 + width: 135 + offset_height: 40 + offset_width: 52 + rotation: 0° + invert_colors: true + cs_pin: GPIO5 + dc_pin: GPIO16 + reset_pin: GPIO23 + update_interval: 2s + pixel_mode: 16bit + lambda: |- + unsigned int row = 0; + unsigned int rh = 32; + unsigned int x0 = 0; + unsigned int x1 = 15; + + it.print(135 / 2, (row++)*rh, id(font_14), id(color_title), TextAlign::TOP_CENTER, "BR"); + it.line(0, rh, 135, rh, id(color_title)); + + it.print(x0, (row++)*rh, id(font_14), id(color_wifi_h), "WIFI"); + if (std::isnan(id(my_wifi_signal).state)) { + it.print(x1, (row++)*rh, id(font_14), id(color_wifi_b), "..."); + } else { + it.printf(x1, (row++)*rh, id(font_14), id(color_wifi_b), "%.0f%%", min(max(2 * (id(my_wifi_signal).state + 100.0), 0.0), 100.0)); + } + it.print(x0, (row++)*rh, id(font_14), id(color_pm_h), "PM2.5"); + it.printf(x1, (row++)*rh, id(font_14), id(color_pm_b), "%.1f", id(pm_2_5).state); + it.print(x0, (row++)*rh, id(font_14), id(color_temp_h), "TEMP °F"); + it.printf(x1, (row++)*rh, id(font_14), id(color_temp_b), "%.1f", 32 + (id(air_temp_c).state * 9 / 5)); diff -r 2f2a34ed4ead -r dcd981e1386b tr-air-quality.yaml --- a/tr-air-quality.yaml Thu Aug 01 22:17:00 2024 -0700 +++ b/tr-air-quality.yaml Thu Aug 01 22:18:10 2024 -0700 @@ -1,3 +1,5 @@ +# https://cdn.shopifycdn.net/s/files/1/0617/7190/7253/files/T-display-pin-diagram_1024x1024.jpg +# https://www.aqmd.gov/docs/default-source/aq-spec/resources-page/plantower-pms5003-manual_v2-3.pdf esphome: name: "tr-air-quality" platform: ESP32 @@ -29,11 +31,7 @@ mqtt: id: mqtt_client broker: 'mqtt2.bigasterisk.com' - -# light: -# - platform: status_led -# id: "status_out" -# pin: 2 + # pms pin 1 to 5V # pms pin 2 to gnd @@ -43,7 +41,7 @@ # GPIO15/TXD2 num 17 = pms rx (pin 4) # or on T-Display ESP32, # pms tx pin 5 to esp 13 -# pms rx pin 4 tp esp 12 +# pms rx pin 4 to esp 17 uart: rx_pin: 13 baud_rate: 9600 @@ -55,12 +53,12 @@ name: "Particulate Matter <1.0µm Concentration" pm_2_5: name: "Particulate Matter <2.5µm Concentration" + id: pm_2_5 pm_10_0: name: "Particulate Matter <10.0µm Concentration" temperature: name: "air temperature C" - - + id: air_temp_c spi: clk_pin: GPIO18 @@ -69,10 +67,9 @@ font: - file: 'fonts/DejaVuSerif.ttf' id: font_14 - size: 14 - glyphs: "!%()+,-/_.:°0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz" + size: 20 + glyphs: "!%()+,-/_.:°0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ conetdisa" - color: - id: color_red red: 1 @@ -95,27 +92,39 @@ green: 0.5 blue: 0.45 -switch: - - platform: gpio - pin: GPIO4 - name: "Backlight" - id: backlight +output: + - platform: ledc + pin: GPIO04 + id: gpio_04_backlight_pwm + +light: + - platform: monochromatic + output: gpio_04_backlight_pwm + name: "Display Backlight" + id: back_light restore_mode: ALWAYS_ON display: - - platform: ili9xxx - model: ST7789V + # see note at https://esphome.io/components/display/ili9xxx#:~:text=For-,Lilygo%20TTGO%20Boards,-if%20you%20move + - platform: ili9xxx + model: st7789v + dimensions: + height: 240 + width: 135 + offset_height: 40 + offset_width: 52 + rotation: 90° + invert_colors: true cs_pin: GPIO5 dc_pin: GPIO16 reset_pin: GPIO23 - rotation: 90° update_interval: 5s + pixel_mode: 16bit lambda: |- - auto bg = Color(30, 0, 0); - auto wifi_status2 = id(wifi_status).state; - # it.fill(bg); - it.print(0, 0, id(font_14), Color(255,0,0), "WiFi Status:"); - it.print(0, 20, id(font_14), Color(255,0,0), wifi_status2.c_str()); + it.printf(10, 10, id(font_14), Color(255,250,250), "TR-AIR-FILTER"); + it.printf(10, 40, id(font_14), Color(255,0,0), "WIFI: %s", id(wifi_status).state.c_str()); + it.printf(10, 70, id(font_14), Color(0,255,0), "PM2.5: %.1f", id(pm_2_5).state); + it.printf(10, 100, id(font_14), Color(0,255,255), "TEMP F: %.1f", 32 + (id(air_temp_c).state * 9 / 5)); text_sensor: - platform: template