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

 找回密码
 立即注册
查看: 268|回复: 3

[求助] yaml文件修改

[复制链接]

16

主题

225

帖子

1570

积分

金牌会员

Rank: 6Rank: 6

积分
1570
金钱
1345
HASS币
0
发表于 2024-4-20 16:52:39 | 显示全部楼层 |阅读模式
5金钱
这yaml文件想去除TDS Switch,但是删了这个虚拟开关会会提示display和time下有些内容也要删,但是删了tds值就不显示,这个yaml该怎么改

esphome:
  name: tds-esp8266
  friendly_name: tds-esp8266
  platform: ESP8266
  board: nodemcuv2
  includes:
   - TDSSensor.h

# Enable logging
logger:
  # level: VERBOSE #makes uart stream available in esphome logstream
  baud_rate: 0 #disable logging over uart



# Enable Home Assistant API
api:
  password: "1"

ota:
  password: "1"

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

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Tds-Esp8266 Fallback Hotspot"
    password: "12345678"

captive_portal:
    
web_server:
  port: 80

display:
    platform: tm1637
    id: tm1637_display
    clk_pin: D1
    dio_pin: D2
    inverted: true
    length: 4
    intensity: 2
    lambda: |-
      if (id(tds_switch).state == false) {
        it.print("    ");
      } else {
        it.printf("%4.0f", id(tds1).state);
      }
      

uart:
  - id: uart_bus1
    tx_pin: TX
    rx_pin: RX
    baud_rate: 9600
    # debug:
      # direction: BOTH
      # dummy_receiver: true
      # after:
      #   delimiter: "\n"
      # sequence:
      #   - lambda: UARTDebug::log_string(direction, bytes);

sensor:
  - platform: custom
    lambda: |-
      auto tds_sensor = new TDSSensorComponent(id(uart_bus1));
      App.register_component(tds_sensor);
      return {tds_sensor->tds1,tds_sensor->temperature1,tds_sensor->tds2,tds_sensor->temperature2};
    sensors:
      - name: "tds1"
        id: "tds1"
        unit_of_measurement: ppm
        accuracy_decimals: 1
      - name: "temperature1"
        id: "temperature1"
        unit_of_measurement: °C
        accuracy_decimals: 2
      - name: "tds2"
        id: "tds2"
        unit_of_measurement: ppm
        accuracy_decimals: 1
      - name: "temperature2"
        id: "temperature2"
        unit_of_measurement: °C
        accuracy_decimals: 2

switch:
  - platform: template
    name: "TDS Switch"
    id: "tds_switch"
    lambda: return id(tds_switch).state;
    optimistic: true
    # turn_on_action:
      # - uart.write: [0x55, 0x07, 0x05, 0x01, 0x00, 0x00, 0x00, 0x62]
      # - uart.write: [0x55, 0x07, 0x03, 0x01, 0x01, 0x0B, 0xCA, 0x36]
    turn_off_action:
      - uart.write: [0x55, 0x07, 0x06, 0x00, 0x00, 0x00, 0x00, 0x62]
    #   - uart.write: [0x55, 0x07, 0x05, 0x02, 0x00, 0x00, 0x00, 0x63]
      # - switch.turn_on: switch1

time:
  - platform: sntp
    id: sntp_time
    on_time:
      - seconds: /1
        then:
          - if:
              condition:
                lambda: |-
                  if (id(tds_switch).state == true) {
                    auto time = id(sntp_time).now();
                    return time.second != 0;
                  }
                  return false;
              then:
                # - if:
                #   condition:
                #     lambda: |-
                #       # auto time = id(sntp_time).now();
                #       # return time.second != 0;
                #       return id(tds_switch).state == true;
                #   then:
                #     - uart.write: [0x55, 0x07, 0x05, 0x01, 0x00, 0x00, 0x00, 0x62]
                #   else:
                #     - uart.write: [0x55, 0x07, 0x05, 0x02, 0x00, 0x00, 0x00, 0x63]
                # - delay: 5s
                - uart.write: [0x55, 0x07, 0x05, 0x01, 0x00, 0x00, 0x00, 0x62]

  - platform: sntp
    on_time:
      - seconds: /60
        then:
          - if:
              condition:
                lambda: |-
                  return id(tds_switch).state == true;
              then:
                - uart.write: [0x55, 0x07, 0x05, 0x02, 0x00, 0x00, 0x00, 0x63]


回复

使用道具 举报

1

主题

31

帖子

134

积分

注册会员

Rank: 2

积分
134
金钱
103
HASS币
0
发表于 2024-4-20 17:27:34 | 显示全部楼层
直接在ui里面隐藏就行了
回复

使用道具 举报

16

主题

225

帖子

1570

积分

金牌会员

Rank: 6Rank: 6

积分
1570
金钱
1345
HASS币
0
 楼主| 发表于 2024-4-20 19:23:18 | 显示全部楼层
ms_jiang144 发表于 2024-4-20 17:27
直接在ui里面隐藏就行了

会一直关闭,嫌麻烦
回复

使用道具 举报

12

主题

321

帖子

2167

积分

金牌会员

Rank: 6Rank: 6

积分
2167
金钱
1846
HASS币
0
发表于 2024-4-20 21:53:55 | 显示全部楼层
kaka0992 发表于 2024-4-20 19:23
会一直关闭,嫌麻烦

我在裡面加了一行指令
讓他每次開啟時  
Switch會自動開啟


switch:
  - platform: template
    restore_mode: ALWAYS_ON #启动时始终将开关初始化为 ON。
    name: "TDS Switch"
    id: "tds_switch"
    lambda: return id(tds_switch).state;
    optimistic: true
    # turn_on_action:
      # - uart.write: [0x55, 0x07, 0x05, 0x01, 0x00, 0x00, 0x00, 0x62]
      # - uart.write: [0x55, 0x07, 0x03, 0x01, 0x01, 0x0B, 0xCA, 0x36]
    turn_off_action:
      - uart.write: [0x55, 0x07, 0x06, 0x00, 0x00, 0x00, 0x00, 0x62]
    #   - uart.write: [0x55, 0x07, 0x05, 0x02, 0x00, 0x00, 0x00, 0x63]
      # - switch.turn_on: switch1
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-6-2 19:24 , Processed in 0.054151 second(s), 23 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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