分享最近买的一些垃圾及复活方法

先是这个温湿度传感器,采用的是dht11,精确度嘛也就那样

菜鸡的我只会esphome还不精,分享下代码

substitutions:
  device_name: dht11
  wifi_ssid: '@qqcdrbs'
  wifi_password: '12345678'
  wifi_fast_connect: 'false'
  wifi_reboot_timeout: 60s
  ota_password: '123456'
  api_reboot_timeout: 0s                     个人喜欢用mqtt不喜欢用接入ha的api

esphome:
  name: $device_name
  platform: ESP8266
  board: esp01_1m
  on_boot:                               开机后亮灯
    priority: 250
    # ...
    then:
      - switch.turn_on: led

wifi:
  ssid: $wifi_ssid
  password: $wifi_password
  reboot_timeout: $wifi_reboot_timeout
  power_save_mode: none
  fast_connect: $wifi_fast_connect
  ap:
    ssid: dht11
    password: "12345678"

logger:

mqtt:
  id: mqtt_client
  broker: 192.168.1.233
  port: 1883
  username: mqtt
  password: mqtt
  discovery_retain: false          这里是ha的自动发现因为我们要让他休眠,休眠会显示不可用所以关闭
#  birth_message: 
#    topic: dht11/ailabilitystate 
#    payload: online        
#  will_message:          
#    topic: dht11/ailabilitystate     
#    payload: offline
  on_message:                                         这里是阻止休眠方便ota
    topic: dht11/ota_mode
    payload: 'ON'
    then:
      - deep_sleep.prevent: deep_sleep_1 

ota:
  safe_mode: true
  password: $ota_password

deep_sleep:                                       休眠时间根据自己需要修改 
  run_duration: 10s                            注意一点的是  esp的rst针脚要与GPIO16连接
  sleep_duration: 10min                     要不然就会一睡不醒
  id: deep_sleep_1

switch:
  - platform: gpio
    pin: 12
    id: led

sensor:
  - platform: dht
    model: DHT11
    pin: 4
    temperature:
      name: "br_temp"
      state_topic: dht11/temp
    humidity:
      name: "br_hum"
      state_topic: dht11/hum
    update_interval: 4s

  - platform: adc                     测量内部电压
    pin: VCC
    name: vcc
   #  internal: true
    id: Voltage
    state_topic: dht11/Voltage
    update_interval: 3s

  - platform: template                            一个粗略的电量计算方法
    name: "battery"
    icon: mdi:battery
    lambda: |-
      if (id(Voltage).state > 3.41) {
        return id(Voltage).state*380/3-432 ;
      } else {
        return 0;
      }
    update_interval: 4s
    unit_of_measurement: "%"
    state_topic: dht11/battery

目前 运行良好 可以看出休眠有在稳定运行


接下来是这个东西

`

好像没啥用的东西,方便练习用了

substitutions:
  device_name: tpm
  wifi_ssid: '@qqcdrbs'
  wifi_password: '12345678'
  wifi_fast_connect: 'false'
  wifi_reboot_timeout: 60s
  ota_password: '123456'
  api_reboot_timeout: 0s


esphome:
  name: $device_name
  platform: ESP8266
  board: nodemcuv2
  on_boot:                                  开机的时候推送等级0
    priority: -10
    then:
      - text_sensor.template.publish:
          id: template_text
          state: "等级0"


wifi:
  ssid: $wifi_ssid
  password: $wifi_password
  reboot_timeout: $wifi_reboot_timeout
  power_save_mode: none
  fast_connect: $wifi_fast_connect
  ap:
    ssid: tpm
    password: "12345678"

logger:

# web_server:                  web网页方便调试用,调试完毕后推荐关闭
  # port: 80
  # css_url: https://esphome.io/_static/webserver-v1.min.css
  # js_url: https://esphome.io/_static/webserver-v1.min.js 

mqtt:
  id: mqtt_client
  broker: 192.168.1.233
  port: 1883
  username: mqtt
  password: mqtt
  discovery_retain: false


ota:
  safe_mode: true
  password: $ota_password


#deep_sleep:
#  run_duration: 6s
#  sleep_duration: 1min


text_sensor:                         一个文本传感器
  - platform: template
    name: "class of pollution"
    id: template_text
    state_topic: hdmi/text

binary_sensor:

  - platform: gpio
    name: tpm_a
    internal: true
    pin:
      number: GPIO12
      mode: INPUT_PULLUP
    id: tpm_a
    on_state:                           根据tb详情页做的一个自动化  if 走起,当状态变化后执行下面代码
      then:
        - lambda: |-
            if (id(tpm_a).state) {
              if(id(tpm_b).state) {
                id(template_text).publish_state("等级3"); 
              }else{
                id(template_text).publish_state("等级2");
              }                
            } else {
              if(id(tpm_b).state) {
                id(template_text).publish_state("等级1"); 
              }else{
                id(template_text).publish_state("等级0");
              }   
            }

  - platform: gpio
    name: tpm_b
    internal: true
    pin:
      number: GPIO14
      mode: INPUT_PULLUP
    id: tpm_b
    on_state:
      then:
        - lambda: |-
            if (id(tpm_a).state) {
              if(id(tpm_b).state) {
                id(template_text).publish_state("等级3"); 
              }else{
                id(template_text).publish_state("等级2");
              }                
            } else {
              if(id(tpm_b).state) {
                id(template_text).publish_state("等级1"); 
              }else{
                id(template_text).publish_state("等级0");
              }   
            }

很牛,玩的很爽, :grinning: :grinning: :grinning:

不错啊!!厉害!!垃圾复活了。。

不需要改,就添加配置就能接入啊。

请问大佬DHT11在ha那边怎么写?麻烦给个代码,另外多个DHT11怎么办?修改esphome固件区别开来?