esp32-clock.yaml
· 911 B · YAML
Raw
esp32:
board: esp32-c3-devkitm-1
variant: ESP32C3
i2c:
sda: GPIO6
scl: GPIO7
frequency: 800kHz
font:
- file: "gfonts://Roboto"
id: roboto
size: 12
time:
- platform: sntp
id: sntp_time
on_time:
- cron: '/2 * * * * *'
then:
- if:
condition:
switch.is_on: clock_active
then:
- switch.turn_off: relay
display:
- platform: ssd1306_i2c
model: "SSD1306 128x32"
lambda: |-
it.strftime(0, 0, id(roboto), "%Y-%m-%d", id(sntp_time).now());
it.strftime(0, 16, id(roboto), "%H:%M %a", id(sntp_time).now());
switch:
- platform: template
id: clock_active
name: "Clock active"
optimistic: True
restore_mode: ALWAYS_ON
- platform: gpio
name: "Relay"
id: relay
pin: GPIO3
inverted: False
on_turn_off:
- delay: 1s
- switch.turn_on: relay
| 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 | font: |
| 11 | - file: "gfonts://Roboto" |
| 12 | id: roboto |
| 13 | size: 12 |
| 14 | |
| 15 | time: |
| 16 | - platform: sntp |
| 17 | id: sntp_time |
| 18 | on_time: |
| 19 | - cron: '/2 * * * * *' |
| 20 | then: |
| 21 | - if: |
| 22 | condition: |
| 23 | switch.is_on: clock_active |
| 24 | then: |
| 25 | - switch.turn_off: relay |
| 26 | |
| 27 | display: |
| 28 | - platform: ssd1306_i2c |
| 29 | model: "SSD1306 128x32" |
| 30 | lambda: |- |
| 31 | it.strftime(0, 0, id(roboto), "%Y-%m-%d", id(sntp_time).now()); |
| 32 | it.strftime(0, 16, id(roboto), "%H:%M %a", id(sntp_time).now()); |
| 33 | |
| 34 | switch: |
| 35 | - platform: template |
| 36 | id: clock_active |
| 37 | name: "Clock active" |
| 38 | optimistic: True |
| 39 | restore_mode: ALWAYS_ON |
| 40 | - platform: gpio |
| 41 | name: "Relay" |
| 42 | id: relay |
| 43 | pin: GPIO3 |
| 44 | inverted: False |
| 45 | on_turn_off: |
| 46 | - delay: 1s |
| 47 | - switch.turn_on: relay |