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]