comparison 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
comparison
equal deleted inserted replaced
19:075b7e4854ba 20:ec7e7d2c763f
1 substitutions:
2 location: tr
3 location_caps: TR
4
5 esphome:
6 name: "${location}-air-quality"
7 platform: ESP32
8 board: featheresp32
9 on_boot:
10 priority: 590
11 then:
12 - script.execute: on_wifi_disconnect
13
14 logger:
15 level: DEBUG
16 logs:
17 sensor: INFO
18 pmsx003: INFO
19
20 wifi:
21 networks:
22 - ssid: !secret wifi_ssid
23 password: !secret wifi_password
24 on_connect:
25 then:
26 - script.execute: on_wifi_connect
27 on_disconnect:
28 then:
29 - script.execute: on_wifi_disconnect
30
31 ota:
32 platform: esphome
33 password: !secret ota_password_1
34
35 mqtt:
36 id: mqtt_client
37 broker: "mqtt2.bigasterisk.com"
38
39 uart:
40 rx_pin: 13
41 baud_rate: 9600
42
43 sensor:
44 - platform: pmsx003
45 type: PMS5003T
46 pm_1_0:
47 name: "Particulate Matter <1.0µm Concentration"
48 pm_2_5:
49 name: "Particulate Matter <2.5µm Concentration"
50 id: pm_2_5
51 pm_10_0:
52 name: "Particulate Matter <10.0µm Concentration"
53 temperature:
54 name: "air temperature C"
55 id: air_temp_c
56
57 - platform: wifi_signal
58 id: my_wifi_signal
59 name: wifi_signal
60 update_interval: 4s
61 internal: true # no mqtt
62
63 spi:
64 clk_pin: GPIO18
65 mosi_pin: GPIO19
66
67 font:
68 - file: "../fonts/PassionOne-Regular.ttf"
69 id: font_14
70 size: 34
71 glyphs: "%-.°0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ "
72
73 color:
74 - { id: color_title, hex: 88888a }
75 - { id: color_wifi_h, hex: 5998de }
76 - { id: color_wifi_b, hex: aec9e2 }
77 - { id: color_pm_h, hex: 5998de }
78 - { id: color_pm_b, hex: aec9e2 }
79 - { id: color_temp_h, hex: 5998de }
80 - { id: color_temp_b, hex: aec9e2 }
81
82 output:
83 - platform: ledc
84 pin: GPIO04
85 id: gpio_04_backlight_pwm
86
87 light:
88 - platform: monochromatic
89 output: gpio_04_backlight_pwm
90 name: "Display Backlight"
91 id: back_light
92 restore_mode: ALWAYS_ON
93
94 - platform: fastled_clockless
95 chipset: WS2812
96 pin: GPIO27
97 num_leds: 8
98 rgb_order: GRB
99 name: "strip1"
100 id: strip1
101 effects:
102 - pulse:
103 name: "wifi_connecting_effect"
104 transition_length: 0.5s
105 update_interval: 0.5s
106 min_brightness: 0%
107 max_brightness: 40%
108
109 - addressable_lambda:
110 name: "lighthouse"
111 update_interval: 30ms
112 lambda: |-
113 static const Color lamp(255, 200, 160);
114
115 static const int32_t wid = 32;
116 static const int32_t mul = 256 / wid;
117
118 static const int32_t ctr[] = {65, 90, 110, 120};
119 static const int32_t ctr_mirror[] = {
120 ctr[0], ctr[1], ctr[2], ctr[3],
121 255 - ctr[3], 255 - ctr[2], 255 - ctr[1], 255 - ctr[0]
122 };
123
124 const uint32_t now = millis();
125
126 int16_t phase256 = ((int32_t)now / 10) % 256;
127
128 for (int i = 0; i < 8; i++) {
129 int16_t dist256 = abs(phase256 - ctr_mirror[i]);
130 if (dist256 < wid) {
131 it[i] = lamp * (mul * (wid - dist256));
132 } else {
133 it[i] = Color::BLACK;
134 }
135 }
136
137 script:
138 - id: on_wifi_disconnect
139 then:
140 - light.turn_on:
141 id: strip1
142 effect: "wifi_connecting_effect"
143 color_brightness: 100%
144 red: 100%
145 green: 0%
146 blue: 0%
147 - id: on_wifi_connect
148 then:
149 - light.turn_off:
150 id: strip1
151 # # debugging
152 # - light.turn_on:
153 # id: strip1
154 # effect: "lighthouse"
155
156 display:
157 # see note at https://esphome.io/components/display/ili9xxx#:~:text=For-,Lilygo%20TTGO%20Boards,-if%20you%20move
158 - platform: ili9xxx
159 model: st7789v
160 dimensions:
161 height: 240
162 width: 135
163 offset_height: 40
164 offset_width: 52
165 rotation: 0°
166 invert_colors: true
167 cs_pin: GPIO5
168 dc_pin: GPIO16
169 reset_pin: GPIO23
170 update_interval: 2s
171 pixel_mode: 16bit
172 lambda: |-
173 unsigned int row = 0;
174 unsigned int rh = 32;
175 unsigned int x0 = 0;
176 unsigned int x1 = 15;
177
178 it.print(135 / 2, (row++)*rh, id(font_14), id(color_title), TextAlign::TOP_CENTER, "${location_caps}");
179 it.line(0, rh, 135, rh, id(color_title));
180
181 it.print(x0, (row++)*rh, id(font_14), id(color_wifi_h), "WIFI");
182 if (std::isnan(id(my_wifi_signal).state)) {
183 it.print(x1, (row++)*rh, id(font_14), id(color_wifi_b), "...");
184 } else {
185 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));
186 }
187 it.print(x0, (row++)*rh, id(font_14), id(color_pm_h), "PM2.5");
188 it.printf(x1, (row++)*rh, id(font_14), id(color_pm_b), "%.1f", id(pm_2_5).state);
189 it.print(x0, (row++)*rh, id(font_14), id(color_temp_h), "TEMP °F");
190 it.printf(x1, (row++)*rh, id(font_14), id(color_temp_b), "%.1f", 32 + (id(air_temp_c).state * 9 / 5));