diff air-quality/tr-air-quality.yaml @ 20:ec7e7d2c763f

aq sync and refactors; start hw.md
author drewp@bigasterisk.com
date Tue, 13 Aug 2024 22:38:39 -0700
parents tr-air-quality.yaml@dcd981e1386b
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/air-quality/tr-air-quality.yaml	Tue Aug 13 22:38:39 2024 -0700
@@ -0,0 +1,190 @@
+substitutions:
+  location: tr
+  location_caps: TR
+
+esphome:
+  name: "${location}-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"
+
+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: 40%
+
+      - addressable_lambda:
+          name: "lighthouse"
+          update_interval: 30ms
+          lambda: |-
+            static const Color lamp(255, 200, 160);
+
+            static const int32_t wid = 32;
+            static const int32_t mul = 256 / wid;
+            
+            static const int32_t ctr[] = {65, 90, 110, 120};
+            static const int32_t ctr_mirror[] = {
+              ctr[0], ctr[1], ctr[2], ctr[3], 
+              255 - ctr[3], 255 - ctr[2], 255 - ctr[1], 255 - ctr[0]
+            };
+
+            const uint32_t now = millis();
+
+            int16_t phase256 = ((int32_t)now / 10) % 256;
+
+            for (int i = 0; i < 8; i++) {
+              int16_t dist256 = abs(phase256 - ctr_mirror[i]); 
+              if (dist256 < wid) {
+                it[i] = lamp * (mul * (wid - dist256));
+              } else {
+                  it[i] =  Color::BLACK;
+              }
+            }
+
+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
+      # # debugging
+      # - light.turn_on:
+      #     id: strip1
+      #     effect: "lighthouse"
+      
+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, "${location_caps}");
+      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));