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

 找回密码
 立即注册
查看: 1999|回复: 13

[技术探讨] 关于Esphome墙壁开关自动化求助

[复制链接]

1

主题

98

帖子

1066

积分

金牌会员

Rank: 6Rank: 6

积分
1066
金钱
968
HASS币
0
发表于 2023-1-12 21:47:16 | 显示全部楼层 |阅读模式
本帖最后由 wsq0387 于 2023-1-12 21:49 编辑

最近看了65999wlc大佬的帖子https://bbs.hassbian.com/forum.p ... =%E7%BD%97%E6%80%BB,也打板做了几个2路的,并按照原理图接了两个LED面板指示灯,但65999wlc上传的代码没有加LED指示灯,本人小白一个不会写代码,于是上官网查看例程,用翻译软件翻译出来的内容看的也是云里雾里不知所以然,最后在代码中加入了这句- output.turn_on:,生成固件刷机后发现用面板开关可以正常控制灯亮灭,对应的LED状态指示灯显示也正常,在UI界面点击开关也能正常控制灯,就是对应的LED状态指示灯不亮,不知道问题出在哪里,本地化代码应该如何写,还请各位大佬指点迷津,谢谢!贴出代码:
binary_sensor:
  - platform: gpio
    pin:
      number: GPIO04
      mode:
        input: true
        pullup: true
      inverted: true
    id: button_1
    on_press:
      then:
        - light.toggle: light_1   
        - output.turn_on: led1   
    on_release:
      then:
        - light.toggle: light_1   
        - output.turn_off: led1   
  - platform: gpio
    pin:
      number: GPIO09
      mode:
        input: true
        pullup: true
      inverted: true
    id: button_2
    on_press:
      then:
        - light.toggle: light_2   
        - output.turn_on: led2
    on_release:
      then:
        - light.toggle: light_2
        - output.turn_off: led2
        

#  - platform: status
#    name: "Status"

output:
  - platform: gpio
    pin: GPIO14
    id: relay_1   
  - platform: gpio
    pin: GPIO12
    id: relay_2   
  - platform: gpio
    pin: GPIO0
    id: led1   
  - platform: gpio
    pin: GPIO2
    id: led2
light:
  - platform: binary
    name: "ktdadeng"
    id: light_1
    output: relay_1

  - platform: binary
    name: "ktdengdai"
    id: light_2
    output: relay_2


  



回复

使用道具 举报

2

主题

53

帖子

830

积分

高级会员

Rank: 4

积分
830
金钱
777
HASS币
0
发表于 2023-1-12 22:43:02 | 显示全部楼层
罗总git 写着
面板指示灯:
S1:GPIO0
S2:GPIO2
S3:GPIO15

你的物理开关如何接线呢。有图?
回复

使用道具 举报

1

主题

98

帖子

1066

积分

金牌会员

Rank: 6Rank: 6

积分
1066
金钱
968
HASS币
0
 楼主| 发表于 2023-1-12 22:51:13 | 显示全部楼层
本帖最后由 wsq0387 于 2023-1-12 22:53 编辑
breakjia 发表于 2023-1-12 22:43
罗总git 写着
面板指示灯:
S1:GPIO0

指示灯接线没错,用为用物理开关开关灯后,状态LED指示灯能跟着正常亮灭


1730652246.jpg
回复

使用道具 举报

50

主题

1316

帖子

5079

积分

论坛DIY达人

积分
5079
金钱
3763
HASS币
20
发表于 2023-1-13 08:31:33 | 显示全部楼层
代码这玩意看起来真的让人·头晕脑胀。
回复

使用道具 举报

1

主题

98

帖子

1066

积分

金牌会员

Rank: 6Rank: 6

积分
1066
金钱
968
HASS币
0
 楼主| 发表于 2023-1-13 12:57:37 来自手机 | 显示全部楼层
是的,苦于不会写代码,自己顶起来,希望大佬能看见
回复

使用道具 举报

1

主题

98

帖子

1066

积分

金牌会员

Rank: 6Rank: 6

积分
1066
金钱
968
HASS币
0
 楼主| 发表于 2023-1-13 20:09:28 | 显示全部楼层
自己顶起来,希望不要沉下去,恳请大佬帮忙
回复

使用道具 举报

7

主题

110

帖子

856

积分

论坛DIY达人

积分
856
金钱
741
HASS币
20
发表于 2023-1-13 20:36:43 | 显示全部楼层
output:
  - platform: gpio
    pin: GPIO14
    id: relay_1  
    on_turn_on:
     - switch.turn_on: led1
    on_turn_off:
     - switch.turn_off: led1

回复

使用道具 举报

2

主题

64

帖子

2142

积分

金牌会员

Rank: 6Rank: 6

积分
2142
金钱
2073
HASS币
30
发表于 2023-1-13 21:08:02 | 显示全部楼层
我这是三开的,你改下看看行不行

esphome:
  name: $device_name
  build_path: build/$device_name
  name_add_mac_suffix: yes
esp8266:
  board: esp_wroom_02

substitutions:
  key_1:  GPIO04  
  key_2:  GPIO09
  key_3:  GPIO10
  output_1: GPIO14
  output_2: GPIO12
  output_3: GPIO05
  output_4: GPIO15
  output_5: GPIO02
  output_6: GPIO00
  device_name: "esp01m-3k"

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "aXfqBFSZPHffQCWAZN/CPvCFMp8r4jL1dqUhcTruUYg="

ota:
  password: "262ec6b2b073ab0596b9cdf9d1351ecf"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Esp-01M-3Relay Fallback Hotspot"
    password: "vMQDcaNSiBIw"

captive_portal:

web_server:
  port: 80

status_led:
  pin: GPIO16

sensor:
# Wifi signal
  - platform: wifi_signal
    name: "${device_name}_RSSI"
    update_interval: 60s

text_sensor:
  - platform: wifi_info
    ip_address:
      name: '${device_name}_IP'
    mac_address:
      name: '${device_name}_MAC'

binary_sensor:
#按键开关
  - platform: gpio
    pin:
      number: GPIO04
      mode:
        input: true
        pullup: true
      inverted: true
    id: button_1
    on_press:
      then:
        - light.toggle: light_1
    on_release:
      then:
        - light.toggle: light_1        
  - platform: gpio
    pin:
      number: GPIO09
      mode:
        input: true
        pullup: true
      inverted: true
    id: button_2
    on_press:
      then:
        - light.toggle: light_2
    on_release:
      then:
        - light.toggle: light_2         
  - platform: gpio
    pin:
      number: GPIO010
      mode:
        input: true
        pullup: true
      inverted: true
    id: button_3
    on_press:
      then:
        - light.toggle: light_3
    on_release:
      then:
        - light.toggle: light_3
#按键开关

output:
  - platform: gpio
    pin: GPIO14
    id: relay_1
  - platform: gpio
    pin: GPIO12
    id: relay_2   
  - platform: gpio
    pin: GPIO5
    id: relay_3

  - platform: gpio
    pin: GPIO15
    id: out_led_1
  - platform: gpio
    pin: GPIO02
    id: out_led_2   
  - platform: gpio
    pin: GPIO00
    id: out_led_3      

switch:
  - platform: restart
    name: "${device_name}_Restart"

light:
  - platform: binary
    name: "${device_name}_light1"
    id: light_1
    output: relay_1
    on_turn_on:
      then:
        - light.turn_on: led_1
    on_turn_off:
      then:
        - light.turn_off: led_1   
  - platform: binary
    name: "${device_name}_light2"
    id: light_2
    output: relay_2
    on_turn_on:
      then:
        - light.turn_on: led_2
    on_turn_off:
      then:
        - light.turn_off: led_2      
  - platform: binary
    name: "${device_name}_light3"
    id: light_3
    output: relay_3
    on_turn_on:
      then:
        - light.turn_on: led_3
    on_turn_off:
      then:
        - light.turn_off: led_3   

  - platform: binary
    name: "led_1"
    id: led_1
    internal: true #是否对外隐藏(true/false)
    output: out_led_1
  - platform: binary
    name: "led_2"
    id: led_2
    output: out_led_2  
    internal: true #是否对外隐藏(true/false)
  - platform: binary
    name: "led_3"
    id: led_3
    output: out_led_3
    internal: true #是否对外隐藏(true/false)


回复

使用道具 举报

1

主题

98

帖子

1066

积分

金牌会员

Rank: 6Rank: 6

积分
1066
金钱
968
HASS币
0
 楼主| 发表于 2023-1-13 21:10:39 | 显示全部楼层
本帖最后由 wsq0387 于 2023-1-13 21:12 编辑
cmsj 发表于 2023-1-13 20:36
output:
  - platform: gpio
    pin: GPIO14

感谢回复 试了下报错
报错.jpg
回复

使用道具 举报

1

主题

98

帖子

1066

积分

金牌会员

Rank: 6Rank: 6

积分
1066
金钱
968
HASS币
0
 楼主| 发表于 2023-1-13 21:12:05 | 显示全部楼层
创意无限 发表于 2023-1-13 21:08
我这是三开的,你改下看看行不行

esphome:

我试着改下看看效果,谢谢
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-6-2 16:11 , Processed in 0.078270 second(s), 34 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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