Caldin-Maldin

ikea+

Nov 15th, 2023 (edited)
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. uart:
  2. - id: ikea
  3. rx_pin: GPIO16
  4. baud_rate: 9600
  5.  
  6. debug:
  7. direction: RX
  8. dummy_receiver: true
  9. after:
  10. delimiter: "\r\n"
  11. sequence:
  12. - lambda: |-
  13. UARTDebug::log_string(direction, bytes); //Still log the data
  14. uint8_t checksum = 0;
  15. for (int i=0; i < bytes.size(); i++) {
  16. checksum+= bytes[i];
  17. }
  18. if (checksum==0){
  19. ESP_LOGD("UART","PM1006|PM1006k checksum validated, have %d", checksum);
  20. if (bytes.size()==20 and (bytes[0]==22 and bytes[1]==17 and bytes[2]==11)) {
  21. ESP_LOGD("UART", "Correct PM1006 response recieved. Updating sensors");
  22. id(pm25).publish_state(bytes[5]*256+bytes[6]);
  23. }
  24. if (bytes.size()==16 and (bytes[0]==22 and bytes[1]==13 and bytes[2]==2)) {
  25. ESP_LOGD("UART", "Correct PM1006K response recieved. Updating sensors");
  26. id(pm25).publish_state(bytes[5]*256+bytes[6]);
  27. }
  28. }
  29. else{
  30. ESP_LOGW("UART","PM1006|PM1006k checksum is wrong: %02x, expected zero. Sensors will not be updated", checksum);
  31. }
  32. sensor:
  33.  
  34. - platform: template
  35. name: "PM 2.5"
  36. id: "pm25"
  37. device_class: PM25
  38. accuracy_decimals: 0
  39. unit_of_measurement: µg/m³
  40.  
  41. - platform: uptime
  42. name: uptime
  43.  
  44. - platform: template
  45. name: "Average PM25"
  46. id: "average"
  47. accuracy_decimals: 0
  48. unit_of_measurement: µg/m³
  49. lambda: |-
  50. 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));
  51.  
  52. time:
  53. - platform: homeassistant
  54. id: time_now
  55. timezone: "Asia/Yekaterinburg"
  56. on_time:
  57. - seconds: 0
  58. minutes: 05
  59. hours: /1
  60. then:
  61. - lambda: |-
  62. id(values_)[id(time_now).now().hour] = id(pm25).state;
  63. int count = 0;
  64. for (int i = 0; i < 24; i++) {
  65. if (id(values_)[i] != 0) {
  66.  
  67. count++;
  68. }
  69. }
  70. id(count_values) = count;
  71.  
  72.  
  73. globals:
  74. - id: values_
  75. type: float[24]
  76. restore_value: no
  77. 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}'
  78.  
  79. - id: count_values
  80. type: float
  81. initial_value: "0"
Advertisement
Add Comment
Please, Sign In to add comment