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

 找回密码
 立即注册
查看: 851|回复: 5

[已解决] esphome求大神帮忙时间组件设置晚上17点自动开启早上6点关闭

[复制链接]

2

主题

6

帖子

72

积分

注册会员

Rank: 2

积分
72
金钱
66
HASS币
0
发表于 2023-4-18 00:18:01 | 显示全部楼层 |阅读模式
本帖最后由 zy302688381 于 2023-4-18 19:45 编辑
<blockquote>esphome:
   
我这边可能是网络问题,ESP接入hass经常掉线,用MQTT也掉,所以有些打算用时间控制开关,自己捣鼓一会实在搞不定,不知道哪里出问题。麻烦你们了。谢谢
360截图20230418001414051.jpg
回复

使用道具 举报

2

主题

6

帖子

72

积分

注册会员

Rank: 2

积分
72
金钱
66
HASS币
0
 楼主| 发表于 2023-4-18 00:21:30 | 显示全部楼层
esphome:
  name: cs01

esp8266:
  board: esp01_1m

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:
  password: "1"

wifi:
  ssid: "99996"
  password: ""

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "ss"
    password: "12345678"

web_server:
  port: 80

captive_portal:

switch:
  - platform: gpio
    pin: GPIO0
    name: "smart-switch8"
    id: relay1
    restore_mode: RESTORE_DEFAULT_OFF
    
    
time:
  - platform: sntp #NTP时间
    id: sntp_time
    servers: ntp5.aliyun.com #NTP服务器地址
    timezone: UTC-8 #中国时区  
    
    on_time:
      - seconds: 0
        minutes: 0
        hours: 17
        days_of_week: MON-FRI
        id: on
        then:
          - switch.turn_on: relay1
          
      # Every morning on weekdays
      - seconds: 0
        minutes: 0
        hours: 6
        days_of_week: MON-FRI
        id: off
        then:
          - switch.turn_off: relay1
          
          
on_...:
  if:
    condition:
      time.has_time:
    then:
      - logger.log: Time has been set and is valid!

# Example lambda
lambda: |-
    if (id(my_time).now().is_valid()) {
      //do something here
    }
    
回复

使用道具 举报

2

主题

6

帖子

72

积分

注册会员

Rank: 2

积分
72
金钱
66
HASS币
0
 楼主| 发表于 2023-4-18 00:39:38 | 显示全部楼层
这是第二个代码也不行  老错误
esphome:
  name: esp01s
  platform: ESP8266
  board: esp01_1m

wifi:
  ssid: "your_wifi_ssid"
  password: "your_wifi_password"

# Enable logging
logger:

# Enable Home Assistant API
api:

# Enable OTA updates
ota:


time:
  - platform: homeassistant
    id: homeassistant_time

# Schedule the switch to turn on at 5pm and off at 6am
time:
  - platform: sntp
    timezone: Asia/Shanghai
    servers:
      - cn.pool.ntp.org
  - platform: template
    name: "Switch On Time"
    id: switch_on_time
    lambda: |-
      return id(homeassistant_time).now().hour == 17 && id(homeassistant_time).now().minute == 0 && id(homeassistant_time).now().second == 0;
  - platform: template
    name: "Switch Off Time"
    id: switch_off_time
    lambda: |-
      return id(homeassistant_time).now().hour == 6 && id(homeassistant_time).now().minute == 0 && id(homeassistant_time).now().second == 0;

switch:
  - platform: gpio
    name: "Switch"
    pin: GPIO0
    id: switch_pin
    restore_mode: RESTORE_DEFAULT_OFF
    

# Turn on the switch at 5pm and off at 6am
automation:
  - id: switch_on_automation
    alias: "Switch On"
    trigger:
      platform: time
      id: switch_on_time
    action:
      - switch.turn_on: switch_pin
  - id: switch_off_automation
    alias: "Switch Off"
    trigger:
      platform: time
      id: switch_off_time
    action:
      - switch.turn_off: switch_pin
回复

使用道具 举报

15

主题

307

帖子

2253

积分

金牌会员

Rank: 6Rank: 6

积分
2253
金钱
1946
HASS币
0
发表于 2023-4-18 02:37:47 来自手机 | 显示全部楼层
既然你这是接入HA使用,干脆用scheduler-component和scheduler-card配合来控制开关,功能上更加通用灵活。
回复

使用道具 举报

2

主题

125

帖子

1446

积分

金牌会员

Rank: 6Rank: 6

积分
1446
金钱
1321
HASS币
0
发表于 2023-4-18 08:47:12 | 显示全部楼层
第一个去掉id: on、id: off和最后两段
esphome:
  name: cs01

esp8266:
  board: esp01_1m

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:
  password: "1"

wifi:
  ssid: "99996"
  password: ""

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "ss"
    password: "12345678"

web_server:
  port: 80

captive_portal:

switch:
  - platform: gpio
    pin: GPIO0
    name: "smart-switch8"
    id: relay1
    restore_mode: RESTORE_DEFAULT_OFF
    
    
time:
  - platform: sntp #NTP时间
    id: sntp_time
    servers: ntp5.aliyun.com #NTP服务器地址
    timezone: UTC-8 #中国时区
    
    on_time:
      - seconds: 0
        minutes: 0
        hours: 17
        days_of_week: MON-FRI
        then:
          - switch.turn_on: relay1
          
      # Every morning on weekdays
      - seconds: 0
        minutes: 0
        hours: 6
        days_of_week: MON-FRI
        then:
          - switch.turn_off: relay1
回复

使用道具 举报

2

主题

6

帖子

72

积分

注册会员

Rank: 2

积分
72
金钱
66
HASS币
0
 楼主| 发表于 2023-4-18 19:45:31 | 显示全部楼层
adamjensen 发表于 2023-4-18 08:47
第一个去掉id: on、id: off和最后两段

原来如此  谢谢
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-5-3 05:55 , Processed in 0.120738 second(s), 30 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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