esphome / feature-requests

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

Support for i2c sensor chirp! - the plant watering alarm #473

Closed Destix closed 2 years ago

Destix commented 4 years ago

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

Please add support for i2c sensor: chirp! - the plant watering alarm

description and code: https://wemakethings.net/chirp/ replica available on Aliexpress (CJMCU Plant https://www.aliexpress.com/af/CJMCU-Plant.html ) https://www.aliexpress.com/item/32912460636.html https://www.aliexpress.com/item/32842054964.html

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

i2c capacitive humidity sensor for plants

Additional context

Sample Arduino code

#include <Wire.h>

void writeI2CRegister8bit(int addr, int value) {
  Wire.beginTransmission(addr);
  Wire.write(value);
  Wire.endTransmission();
}

unsigned int readI2CRegister16bit(int addr, int reg) {
  Wire.beginTransmission(addr);
  Wire.write(reg);
  Wire.endTransmission();
  delay(20);
  Wire.requestFrom(addr, 2);
  unsigned int t = Wire.read() << 8;
  t = t | Wire.read();
  return t;
}

void setup() {
  Wire.begin();
  Serial.begin(9600);
  writeI2CRegister8bit(0x20, 6); //reset
}

void loop() {
  Serial.print(readI2CRegister16bit(0x20, 0)); //read capacitance register
  Serial.print(", ");
  Serial.print(readI2CRegister16bit(0x20, 5)); //temperature register
  Serial.print(", ");
  writeI2CRegister8bit(0x20, 3); //request light measurement 
  Serial.println(readI2CRegister16bit(0x20, 4)); //read light register
}
mredone commented 4 years ago

Hello. How can i help to add this sensor to esphome?

lupumihai commented 4 years ago

I manage to make it work, even if I don't use all its functionality, I believe that my code could help you. in my code I just read values from Chirp, in the same way, you could write registers to trigger light measurement or temperature by adding the "writeI2CRegister8bit( addr, value)"

Setup for ESPHome is below + the attached extra code "chirp.h" - Remove the ".txt"

esphome: includes:

i2c: sda: GPIO4 scl: GPIO5 scan: false

sensor:

Attachement: chirp.h.txt