Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- uart:
- - id: ikea
- rx_pin: GPIO16
- baud_rate: 9600
- debug:
- direction: RX
- dummy_receiver: true
- after:
- delimiter: "\r\n"
- sequence:
- - lambda: |-
- UARTDebug::log_string(direction, bytes); //Still log the data
- uint8_t checksum = 0;
- for (int i=0; i < bytes.size(); i++) {
- checksum+= bytes[i];
- }
- if (checksum==0){
- ESP_LOGD("UART","PM1006|PM1006k checksum validated, have %d", checksum);
- if (bytes.size()==20 and (bytes[0]==22 and bytes[1]==17 and bytes[2]==11)) {
- ESP_LOGD("UART", "Correct PM1006 response recieved. Updating sensors");
- id(pm25).publish_state(bytes[5]*256+bytes[6]);
- }
- if (bytes.size()==16 and (bytes[0]==22 and bytes[1]==13 and bytes[2]==2)) {
- ESP_LOGD("UART", "Correct PM1006K response recieved. Updating sensors");
- id(pm25).publish_state(bytes[5]*256+bytes[6]);
- }
- }
- else{
- ESP_LOGW("UART","PM1006|PM1006k checksum is wrong: %02x, expected zero. Sensors will not be updated", checksum);
- }
- sensor:
- - platform: template
- name: "PM 2.5"
- id: "pm25"
- device_class: PM25
- accuracy_decimals: 0
- unit_of_measurement: µg/m³
- - platform: uptime
- name: uptime
- - platform: template
- name: "Average PM25"
- id: "average"
- accuracy_decimals: 0
- unit_of_measurement: µg/m³
- lambda: |-
- return ((id(values_)[0] + id(values_)[1] + id(values_)[2] + id(values_)[3] + id(values_)[4] + id(values_)[5] + id(values_)[6] + id(values_)[7] + id(values_)[8] + id(values_)[9] + id(values_)[10] + id(values_)[11] + id(values_)[12] + id(values_)[13] + id(values_)[14] + id(values_)[15] + id(values_)[16] + id(values_)[17] + id(values_)[18] + id(values_)[19] + id(values_)[20] + id(values_)[21] + id(values_)[22] + id(values_)[23]) / id(count_values));
- time:
- - platform: homeassistant
- id: time_now
- timezone: "Asia/Yekaterinburg"
- on_time:
- - seconds: 0
- minutes: 05
- hours: /1
- then:
- - lambda: |-
- id(values_)[id(time_now).now().hour] = id(pm25).state;
- int count = 0;
- for (int i = 0; i < 24; i++) {
- if (id(values_)[i] != 0) {
- count++;
- }
- }
- id(count_values) = count;
- globals:
- - id: values_
- type: float[24]
- restore_value: no
- initial_value: '{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}'
- - id: count_values
- type: float
- initial_value: "0"
Advertisement
Add Comment
Please, Sign In to add comment