esphome:
name: tds2-8266
friendly_name: tds2-8266
includes:
- TDSSensor.h
esp8266:
board: esp01_1m
# Enable logging
logger:
baud_rate: 0
web_server:
# Enable Home Assistant API
api:
encryption:
key: "bko9GlRpSUGyUBZl+USDm1eGKZbtMwOFnKJc+084HSI="
ota:
- platform: esphome
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Tds2-8266"
password: "12345678"
captive_portal:
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
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
time:
- platform: sntp
id: sntp_time
on_time:
- seconds: /9
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: /10
then:
- if:
condition:
lambda: |-
return id(tds_switch).state == true;
then:
- uart.write: [0x55, 0x07, 0x05, 0x02, 0x00, 0x00, 0x00, 0x63]