The custom UART component makes the software side a bit more complex. Here was an alternative approach that I think would be easier to implement. This link has the background information:
uart:
baud_rate: 9600
tx_pin: 12
rx_pin: 14
debug:
direction: RX
dummy_receiver: true
sequence:
- lambda: |-
UARTDebug::log_hex(direction, bytes,':'); //Log hex data
if (bytes.size() == 26 ) {
//only update if expected response bytes returned
id(zphs01b_pm1).publish_state( bytes[2] * 256 + bytes[3] );
//////////add rest of sensors here////////////////
}
sensor:
- platform: template
name: PM1.0
id: zphs01b_pm1
unit_of_measurement: ug/m3
accuracy_decimals: 0
lambda: "return {};"
- name: PM2.5
platform: template
id: zphs01b_pm25
unit_of_measurement: ug/m3
accuracy_decimals: 0
lambda: "return {};"
- name: PM10
platform: template
id: zphs01b_pm10
unit_of_measurement: ug/m3
accuracy_decimals: 0
lambda: "return {};"
- name: CO2
platform: template
id: zphs01b_co2
unit_of_measurement: ppm
accuracy_decimals: 0
lambda: "return {};"
- name: TVOC
platform: template
id: zphs01b_voc
unit_of_measurement: grades
accuracy_decimals: 0
lambda: "return {};"
- name: Temperature
platform: template
id: zphs01b_temp
unit_of_measurement: "°C"
accuracy_decimals: 0
lambda: "return {};"
- name: Humidity
platform: template
id: zphs01b_hum
unit_of_measurement: "%"
accuracy_decimals: 0
lambda: "return {};"
- name: CH2O
platform: template
id: zphs01b_ch2o
unit_of_measurement: ppm
accuracy_decimals: 0
lambda: "return {};"
- name: CO
platform: template
id: zphs01b_co
unit_of_measurement: ppm
accuracy_decimals: 0
lambda: "return {};"
- name: O3
platform: template
id: zphs01b_o3
unit_of_measurement: ppm
accuracy_decimals: 0
lambda: "return {};"
- name: NO2
platform: template
id: zphs01b_no2
unit_of_measurement: ppm
accuracy_decimals: 0
lambda: "return {};"
#write command to get new data every 5 seconds
interval:
- interval: 5s
then:
- uart.write: [0xFF, 0x01, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79]