分类 EspHome 下的文章

5V/12V ESP8266双路WiFi继电器(uart总线)

5V/12V ESP8266双路WiFi继电器


uart:                                    //定义uart总线
  baud_rate: 115200                      //定义uart波特率
  tx_pin: GPIO1                          //定义tx接入IO
  rx_pin: GPIO3                          //定义rx接入IO
 
  debug:
    direction: BOTH
    dummy_receiver: false
    after:
      delimiter: "\n"
    sequence:
      - lambda: UARTDebug::log_string(direction, bytes);

switch:                                 //定义开关
  - platform: template
    id: relay1                          //自定义开关ID(后面代码要用到)
    optimistic: false
    turn_on_action:
      - uart.write: [0xA0, 0x01, 0x01, 0xA2]
    turn_off_action:
      - uart.write: [0xA0, 0x01, 0x00, 0xA1]

  - platform: template                 //定义类型
    id: relay2                         //自定义开关ID(后面代码要用到)
    optimistic: true
    turn_on_action:
      - uart.write: [0xA0, 0x02, 0x01, 0xA3]
    turn_off_action:
      - uart.write: [0xA0, 0x02, 0x00, 0xA2]

  - platform: template                 //定义类型
    name: "FansPower"                  //自定义实体名称
    id: FansPower                      //自定义实体id
    turn_on_action:
    - switch.turn_on: relay1            
    turn_off_action:
    - switch.turn_off: relay1  

  - platform: template                 //定义类型
    name: "PTCPower"                   //自定义实体名称
    id: PTCPower                       //自定义实体id
    turn_on_action:
    - switch.turn_on: relay2
    turn_off_action:
    - switch.turn_off: relay2   

HDC1080 温湿度传感器(i2c总线)

传感器图片

EspHome接入代码

captive_portal:(从此处开始以下为esphome编辑代码)

i2c:                                   //定义i2c总线
    sda: GPIO0                         //D3(本次接入IO)
    scl: GPIO2                         //D4(本次接入IO)
    scan: True                         //ic总线激活端口(可以激活后扫描不同的地址,接线方式可以多设备同端口并联也可以多设备不同端口串联)
sensor:                                //定义传感器
  - platform: hdc1080                  //传感器名称
    temperature:                       //传感器类型
      name: "Living Room Temperature"  //自定义实体
    humidity:                          //传感器类型
      name: "Living Room Humidity"     //自定义实体
    update_interval: 1s                //自定义刷新时间