esp32-clock.yaml
· 1.7 KiB · YAML
Raw
esp32:
board: esp32-c3-devkitm-1
variant: ESP32C3
i2c:
sda: GPIO6
scl: GPIO7
frequency: 800kHz
binary_sensor:
- platform: gpio
pin: GPIO9
id: boot
filters:
- delayed_on: 10ms
on_release:
then:
- switch.toggle: clock_active
internal: True
time:
- platform: sntp
id: sntp_time
on_time:
- cron: '/2 * * * * *'
then:
- if:
condition:
- switch.is_on: clock_active
then:
- delay: 500ms
- switch.turn_on: relay
switch:
- platform: template
id: clock_active
name: "Clock active"
optimistic: True
restore_mode: ALWAYS_OFF
- platform: gpio
name: "Relay"
id: relay
pin: GPIO0
inverted: True
on_turn_on:
- delay: 1s
- switch.turn_off: relay
font:
- file: "gfonts://Roboto"
id: roboto25
size: 25
- file: "gfonts://Roboto"
id: roboto14
size: 14
display:
- platform: ssd1306_i2c
model: "SSD1306 128x32"
flip_y: False
flip_x: False
lambda: |-
it.strftime(0, -5, id(roboto25), "%H:%M", id(sntp_time).now());
it.strftime(64, -2, id(roboto14), "%S", id(sntp_time).now());
it.strftime(it.get_width(), -2, id(roboto14), TextAlign::TOP_RIGHT, "%a", id(sntp_time).now());
it.strftime(it.get_width(), 15, id(roboto14), TextAlign::TOP_RIGHT, "%b %d", id(sntp_time).now());
it.draw_pixel_at(id(sntp_time).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);
# it.printf(it.get_width(), 0, id(roboto14), TextAlign::TOP_RIGHT, "%.2f°C", id(temp).state);
# it.printf(0, 0, id(roboto14), "%.5f", id(temp).state);
| 1 | esp32: |
| 2 | board: esp32-c3-devkitm-1 |
| 3 | variant: ESP32C3 |
| 4 | |
| 5 | i2c: |
| 6 | sda: GPIO6 |
| 7 | scl: GPIO7 |
| 8 | frequency: 800kHz |
| 9 | |
| 10 | binary_sensor: |
| 11 | - platform: gpio |
| 12 | pin: GPIO9 |
| 13 | id: boot |
| 14 | filters: |
| 15 | - delayed_on: 10ms |
| 16 | on_release: |
| 17 | then: |
| 18 | - switch.toggle: clock_active |
| 19 | internal: True |
| 20 | |
| 21 | time: |
| 22 | - platform: sntp |
| 23 | id: sntp_time |
| 24 | on_time: |
| 25 | - cron: '/2 * * * * *' |
| 26 | then: |
| 27 | - if: |
| 28 | condition: |
| 29 | - switch.is_on: clock_active |
| 30 | then: |
| 31 | - delay: 500ms |
| 32 | - switch.turn_on: relay |
| 33 | |
| 34 | switch: |
| 35 | - platform: template |
| 36 | id: clock_active |
| 37 | name: "Clock active" |
| 38 | optimistic: True |
| 39 | restore_mode: ALWAYS_OFF |
| 40 | |
| 41 | - platform: gpio |
| 42 | name: "Relay" |
| 43 | id: relay |
| 44 | pin: GPIO0 |
| 45 | inverted: True |
| 46 | on_turn_on: |
| 47 | - delay: 1s |
| 48 | - switch.turn_off: relay |
| 49 | |
| 50 | font: |
| 51 | - file: "gfonts://Roboto" |
| 52 | id: roboto25 |
| 53 | size: 25 |
| 54 | - file: "gfonts://Roboto" |
| 55 | id: roboto14 |
| 56 | size: 14 |
| 57 | |
| 58 | display: |
| 59 | - platform: ssd1306_i2c |
| 60 | model: "SSD1306 128x32" |
| 61 | flip_y: False |
| 62 | flip_x: False |
| 63 | lambda: |- |
| 64 | it.strftime(0, -5, id(roboto25), "%H:%M", id(sntp_time).now()); |
| 65 | it.strftime(64, -2, id(roboto14), "%S", id(sntp_time).now()); |
| 66 | it.strftime(it.get_width(), -2, id(roboto14), TextAlign::TOP_RIGHT, "%a", id(sntp_time).now()); |
| 67 | it.strftime(it.get_width(), 15, id(roboto14), TextAlign::TOP_RIGHT, "%b %d", id(sntp_time).now()); |
| 68 | it.draw_pixel_at(id(sntp_time).now().second+1, 30, COLOR_ON); |
| 69 | it.line(0,27,61,27); |
| 70 | it.draw_pixel_at(0,28,COLOR_ON); |
| 71 | it.draw_pixel_at(61,28,COLOR_ON); |
| 72 | # it.printf(it.get_width(), 0, id(roboto14), TextAlign::TOP_RIGHT, "%.2f°C", id(temp).state); |
| 73 | # it.printf(0, 0, id(roboto14), "%.5f", id(temp).state); |
| 74 |