本帖最后由 shadowba 于 2021-12-25 15:54 编辑
声明,本人编程老白,欢迎提供修改代码
输入后通过gpio0的微动开关切换日期显示,延时三秒后显示时间
esphome:
name: clock
platform: ESP8266
board: esp01_1m
# Enable logging
logger:
api:
ota:
password: " "
wifi:
ssid: " "
password: " "
ap:
ssid: "clock"
password: "12345678"
web_server:
port: 80
captive_portal:
time:
- platform: sntp
timezone: "Asia/Shanghai"
id: sntp_time
servers: "time.windows.com"
binary_sensor:
- platform: gpio
pin:
number: GPIO0
mode:
input: true
pullup: true
inverted: true
name: "Button"
on_press:
- switch.toggle: relay
switch:
- platform: gpio
name: "Relay"
pin: GPIO12
id: relay
on_turn_on:
- delay: 3s
- switch.turn_off: relay
display:
platform: tm1637
clk_pin: 4
dio_pin: 5
update_interval: 500ms
lambda: |-
if (id(relay).state)
{
it.strftime("%m%d", id(sntp_time).now());
}
else {
static int i = 0;
i++;
if ((i % 2) == 0)
it.strftime("%H.%M", id(sntp_time).now());
else
it.strftime("%H%M", id(sntp_time).now());
}
|