|
发表于 2025-1-23 21:26:55
|
显示全部楼层
uart:
- id: uart_bus1
rx_pin: 1
tx_pin: 3
baud_rate: 9600
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_off_action:
- uart.write: [0x55, 0x07, 0x06, 0x00, 0x00, 0x00, 0x00, 0x62]
restore_mode: ALWAYS_ON
time:
- platform: sntp
id: sntp_time
on_time:
- seconds: /30
then:
- if:
condition:
lambda: |-
if (id(tds_switch).state == true) {
auto time = id(sntp_time).now();
return time.second != 0;
}
return false;
then:
- 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] |
|