legends, that has the M701 - 7 in 1 air sensor working. I get the following error in the logs tho: “Component uart took a long time for an operation (93 ms)” and “Components should block for at most 30 ms.”
I think I need to add a delay or something.
Would it be easy to turn this to an external component now to make it easier for others to use this air sensor?
here is the .yaml
logger:
baud_rate: 9600
uart:
id: uart_bus
baud_rate: 9600
tx_pin: 16
rx_pin: 17
debug:
direction: RX
dummy_receiver: true
after:
delimiter: "\r\n"
sequence:
- lambda: |-
UARTDebug::log_hex(direction, bytes, ','); // Log the message as int.
ESP_LOGD("custom", "Bytes size: %d", bytes.size()); // Log how many bytes in the message.
if (direction == UART_DIRECTION_RX) // Check message direction (Change to TX if required)
{
if (bytes[0] == 0x3C && bytes[1] == 0x02)
{
int eCO2 = (bytes[2] << 8) | bytes[3];
int eCH2O = (bytes[4] << 8) | bytes[5];
int TVOC = (bytes[6] << 8) | bytes[7];
int PM2_5 = (bytes[8] << 8) | bytes[9];
int PM10 = (bytes[10] << 8) | bytes[11];
float temperature = bytes[12] + bytes[13] / 100.0;
float humidity = bytes[14] + bytes[15] / 100.0;
id(eCO2_sensor).publish_state(eCO2);
id(eCH2O_sensor).publish_state(eCH2O);
id(TVOC_sensor).publish_state(TVOC);
id(PM2_5_sensor).publish_state(PM2_5);
id(PM10_sensor).publish_state(PM10);
id(temperature_sensor).publish_state(temperature);
id(humidity_sensor).publish_state(humidity);
}
}
sensor:
- platform: template
name: "eCO2 reading"
id: eCO2_sensor
device_class: carbon_dioxide
state_class: measurement
unit_of_measurement: "ppm"
- platform: template
name: "eCH2O reading"
id: eCH2O_sensor
device_class: volatile_organic_compounds
state_class: "measurement"
unit_of_measurement: "µg/m³"
- platform: template
name: "TVOC reading"
id: TVOC_sensor
device_class: volatile_organic_compounds
state_class: "measurement"
unit_of_measurement: "µg/m³"
- platform: template
name: "PM2.5 reading"
id: PM2_5_sensor
unit_of_measurement: μg/m³
accuracy_decimals: 0
device_class: PM25
state_class: "measurement"
- platform: template
name: "PM10 reading"
id: PM10_sensor
unit_of_measurement: μg/m³
accuracy_decimals: 0
device_class: PM10
state_class: "measurement"
- platform: template
name: "Temperature reading"
id: temperature_sensor
unit_of_measurement: "°C"
device_class: "temperature"
state_class: "measurement"
accuracy_decimals: 1
- platform: template
name: "Humidity reading"
id: humidity_sensor
unit_of_measurement: "%"
device_class: "humidity"
state_class: "measurement"