『瀚思彼岸』» 智能家居技术论坛

 找回密码
 立即注册
查看: 1631|回复: 0

[基础教程] tm1637网络时钟支持日期切换ephome代码

[复制链接]

43

主题

326

帖子

2734

积分

论坛DIY达人

积分
2734
金钱
2403
HASS币
50
发表于 2021-12-23 09:28:04 | 显示全部楼层 |阅读模式
本帖最后由 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());      
            }

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-11-27 23:43 , Processed in 0.160707 second(s), 22 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表