esphome / feature-requests

ESPHome Feature Request Tracker
https://esphome.io/
417 stars 26 forks source link

Add support for the HC8 CO2 sensor #2550

Open ClarkAlmazan opened 9 months ago

ClarkAlmazan commented 9 months ago

Describe the problem you have/What new integration you would like

I would like to see the HC8 CO2 sensor integrated. This sensor is almost the same as the MHZ19, but uses a different protocol. It's been reported previously on https://github.com/esphome/issues/issues/4534.

Please describe your use case for this integration and alternatives you've tried:

This is one of the NDIR-based CO2 sensors that are available for a very cheap price. Currently, it's already supported in Tasmota. I've tested their code for reading the CO2 values on an Arduino UNO R3 and I can confirm that it works.

I'm unaware of other functions besides reading the values.

Additional context

Blogpost from someone who found this sensor. Cached datasheet

fanfaron2004 commented 8 months ago

hello ... i use the PWM output ...

I measure the pulsation time (x), and we can calculate the CO2 value: ppm = (1000x-2)*5

image image

here is an ESPhome example

sensor:

image

ClarkAlmazan commented 8 months ago

Hi @fanfaron2004, this looks kinda neat, definitely much simpler than what I had in mind. Never thought about using PWM, as I've never used it before. For this method, I'm assuming you only need 5V, GND, and the PWM pins connected, right?

For my own use, I made an esphome component, but honestly it's not very good so I don't think I want to make a pull request. I started off copying the mhz19 code, then just changed it to run like how the tasmota implementation did. It works but not without issues... You can see it here: https://github.com/ClarkAlmazan/esphome/commit/f751d198f07954478eb8664255f5dd9d7d0158a0

Racer0412 commented 8 months ago

Hey @fanfaron2004.

Could you please share the code in a different format so it's easier to copy? That'd be nice. My ESPHome is throwing errors and due to my limited experience I'm not able to fix it on my own :/

Thanks a lot!

IZZE2000 commented 7 months ago

FYI i asked Bing (GPT4) to fix the indentation and it worked out nicely!

sensor:
  platform: pulse_width
  pin: GPIO19
  name: "Co2"
  device_class: carbon_dioxide
  state_class: measurement
  filters:
    lambda: !lambda |-
      if (x < 0.02) return {};
      return round(((1000*x)-2)*5);
  unit_of_measurement: "ppm"
  update_interval: 60s
alexschultze commented 5 months ago

+1 For implementing this "C08" type of sensor protocol.