Advertisement
Carlo1961

Untitled

May 31st, 2025
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. esphome:
  2. name: ens160
  3.  
  4. esp32:
  5. board: esp32doit-devkit-v1
  6.  
  7.  
  8. wifi:
  9. networks:
  10. - ssid: kkkkkk
  11. password: xxxxx
  12. - ssid: zzzzzz
  13. password: yyyyyyy
  14.  
  15. # Enable logging
  16. logger:
  17. level: debug
  18. # Enable Home Assistant API
  19. api:
  20.  
  21. # Enable over-the-air updates.
  22. ota:
  23. platform: esphome
  24.  
  25. # Enable Web server.
  26. web_server:
  27. port: 80
  28. version: 1
  29.  
  30. i2c:
  31. sda: 21
  32. scl: 22
  33. scan: true
  34.  
  35. sensor:
  36. - platform: ens160_i2c
  37. eco2:
  38. name: "ENS160 eCO2"
  39. tvoc:
  40. name: "ENS160 Total Volatile Organic Compounds"
  41. aqi:
  42. id: ens160_air_quality_index
  43. name: "ENS160 Air Quality Index"
  44. update_interval: 10s
  45. address: 0x53
  46. compensation:
  47. temperature: id_temperature_sensor
  48. humidity: id_humidity_sensor
  49. - platform: aht10
  50. variant: AHT10
  51. temperature:
  52. id: id_temperature_sensor
  53. name: "Temperature"
  54. humidity:
  55. id: id_humidity_sensor
  56. name: "Humidity"
  57. update_interval: 10s
  58. address: 0x38
  59.  
  60.  
  61. # You need the http_request component defined
  62. http_request:
  63. id: thingspeak_request # Give it an ID
  64. verify_ssl: false
  65.  
  66. interval:
  67. - interval: 10min
  68. then:
  69. # Use the http_request.get action provided by the component with the ID 'thingspeak_request'
  70. - http_request.get:
  71. id: thingspeak_request # Optional if you only have one http_request component
  72. url: !lambda |-
  73. // Use esphome::to_string for simpler float-to-string conversion
  74. std::string temp_str = esphome::to_string(id(id_temperature_sensor).state);
  75. std::string hum_str = esphome::to_string(id(id_humidity_sensor).state);
  76. std::string airq_str = esphome::to_string(id(ens160_air_quality_index).state);
  77.  
  78. // Construct the URL string
  79. std::string url = "https://api.thingspeak.com/update?api_key=xxxxxxxxxxxxxxxxxx";
  80. url += "&field3=" + temp_str; // Assuming field3 is temperature
  81. url += "&field4=" + hum_str; // Assuming field4 is humidity
  82. url += "&field5=" + airq_str; // Assuming field5 is AirQuality
  83. ESP_LOGD("thingspeak", "ThingSpeak URL: %s", url.c_str()); // Optional: Log the URL for debugging
  84. return url;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement