esp32-clock.yaml
· 1.9 KiB · YAML
Raw
packages:
esphome.esp_web_tools_example: github://esphome/firmware/esp-web-tools/esp32c3.yaml@v2
esphome:
name: clock
name_add_mac_suffix: true
logger:
level: INFO
esp32:
board: esp32-c3-devkitm-1
variant: ESP32C3
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
api:
encryption:
key: !secret encryption_key
uart:
tx_pin: GPIO20
rx_pin: GPIO21
baud_rate: 9600
i2c:
sda: GPIO8
scl: GPIO9
frequency: 800kHz
font:
- file: "gfonts://Roboto"
id: roboto25
size: 25
- file: "gfonts://Roboto"
id: roboto14
size: 14
globals:
- id: current_time
type: esphome::ESPTime
restore_value: no
gps:
latitude:
id: lat
longitude:
id: lon
altitude:
id: alt
satellites:
id: satellites
speed:
id: speed
time:
- platform: sntp
id: sntp_time
- platform: gps
id: gps_time
script:
- id: check_time_source
then:
- lambda: |-
if (id(sntp_time).now().is_valid()) {
id(current_time) = id(sntp_time).now();
} else if (id(gps_time).now().is_valid()) {
id(current_time) = id(gps_time).now();
}
interval:
- interval: 0.5s
then:
- script.execute: check_time_source
display:
- platform: ssd1306_i2c
id: oled
model: "SSD1306 128x32"
lambda: |-
auto now = id(current_time);
if (now.hour >= 18 || now.hour < 6) id(oled).set_contrast(.25);
else id(oled).set_contrast(1);
it.strftime(0, -5, id(roboto25), "%H:%M", now);
it.strftime(64, -2, id(roboto14), "%S", now);
it.strftime(it.get_width(), -2, id(roboto14), TextAlign::TOP_RIGHT, "%a", now);
it.strftime(it.get_width(), 15, id(roboto14), TextAlign::TOP_RIGHT, "%b %d", now);
it.draw_pixel_at(now.second+1, 30, COLOR_ON);
it.line(0,27,61,27);
it.draw_pixel_at(0,28,COLOR_ON);
it.draw_pixel_at(61,28,COLOR_ON);
| 1 | packages: |
| 2 | esphome.esp_web_tools_example: github://esphome/firmware/esp-web-tools/esp32c3.yaml@v2 |
| 3 | esphome: |
| 4 | name: clock |
| 5 | name_add_mac_suffix: true |
| 6 | logger: |
| 7 | level: INFO |
| 8 | esp32: |
| 9 | board: esp32-c3-devkitm-1 |
| 10 | variant: ESP32C3 |
| 11 | wifi: |
| 12 | ssid: !secret wifi_ssid |
| 13 | password: !secret wifi_password |
| 14 | api: |
| 15 | encryption: |
| 16 | key: !secret encryption_key |
| 17 | |
| 18 | |
| 19 | uart: |
| 20 | tx_pin: GPIO20 |
| 21 | rx_pin: GPIO21 |
| 22 | baud_rate: 9600 |
| 23 | |
| 24 | i2c: |
| 25 | sda: GPIO8 |
| 26 | scl: GPIO9 |
| 27 | frequency: 800kHz |
| 28 | |
| 29 | font: |
| 30 | - file: "gfonts://Roboto" |
| 31 | id: roboto25 |
| 32 | size: 25 |
| 33 | - file: "gfonts://Roboto" |
| 34 | id: roboto14 |
| 35 | size: 14 |
| 36 | |
| 37 | |
| 38 | globals: |
| 39 | - id: current_time |
| 40 | type: esphome::ESPTime |
| 41 | restore_value: no |
| 42 | |
| 43 | gps: |
| 44 | latitude: |
| 45 | id: lat |
| 46 | longitude: |
| 47 | id: lon |
| 48 | altitude: |
| 49 | id: alt |
| 50 | satellites: |
| 51 | id: satellites |
| 52 | speed: |
| 53 | id: speed |
| 54 | |
| 55 | time: |
| 56 | - platform: sntp |
| 57 | id: sntp_time |
| 58 | - platform: gps |
| 59 | id: gps_time |
| 60 | |
| 61 | script: |
| 62 | - id: check_time_source |
| 63 | then: |
| 64 | - lambda: |- |
| 65 | if (id(sntp_time).now().is_valid()) { |
| 66 | id(current_time) = id(sntp_time).now(); |
| 67 | } else if (id(gps_time).now().is_valid()) { |
| 68 | id(current_time) = id(gps_time).now(); |
| 69 | } |
| 70 | |
| 71 | interval: |
| 72 | - interval: 0.5s |
| 73 | then: |
| 74 | - script.execute: check_time_source |
| 75 | |
| 76 | display: |
| 77 | - platform: ssd1306_i2c |
| 78 | id: oled |
| 79 | model: "SSD1306 128x32" |
| 80 | lambda: |- |
| 81 | auto now = id(current_time); |
| 82 | if (now.hour >= 18 || now.hour < 6) id(oled).set_contrast(.25); |
| 83 | else id(oled).set_contrast(1); |
| 84 | it.strftime(0, -5, id(roboto25), "%H:%M", now); |
| 85 | it.strftime(64, -2, id(roboto14), "%S", now); |
| 86 | it.strftime(it.get_width(), -2, id(roboto14), TextAlign::TOP_RIGHT, "%a", now); |
| 87 | it.strftime(it.get_width(), 15, id(roboto14), TextAlign::TOP_RIGHT, "%b %d", now); |
| 88 | it.draw_pixel_at(now.second+1, 30, COLOR_ON); |
| 89 | it.line(0,27,61,27); |
| 90 | it.draw_pixel_at(0,28,COLOR_ON); |
| 91 | it.draw_pixel_at(61,28,COLOR_ON); |
| 92 |