15 Comments
Mar 16, 2023Liked by Alistair Young

If you want to use multiple sensors and use the potential of i2c you could change the following part of the code:

// Constructor

StemmaSoilSensor(int addr) : PollingComponent (30000)

{

this->i2c_addr = addr;

}

within esphome you can now do the following (max. 4 sensors :-) ):

sensor:

- platform: custom

lambda: |-

auto soil_sensor = new StemmaSoilSensor(0x36); // no bridge 0x36

App.register_component(soil_sensor);

return {soil_sensor->temperature_sensor, soil_sensor->moisture_sensor};

sensors:

- name: "Plant Temperature"

- name: "Plant Moisture"

- platform: custom

lambda: |-

auto soil_sensor = new StemmaSoilSensor(0x37); // sensor with AD0 bridged 0x37

App.register_component(soil_sensor);

return {soil_sensor->temperature_sensor, soil_sensor->moisture_sensor};

sensors:

- name: "Plant Temperature 2"

- name: "Plant Moisture 2"

- platform: custom

lambda: |-

auto soil_sensor = new StemmaSoilSensor(0x38); // sensor with AD1 bridged 0x38

App.register_component(soil_sensor);

return {soil_sensor->temperature_sensor, soil_sensor->moisture_sensor};

sensors:

- name: "Plant Temperature 3"

- name: "Plant Moisture 3"

- platform: custom

lambda: |-

auto soil_sensor = new StemmaSoilSensor(0x39); // sensor with AD0 and AD1 bridged 0x39

App.register_component(soil_sensor);

return {soil_sensor->temperature_sensor, soil_sensor->moisture_sensor};

sensors:

- name: "Plant Temperature 4"

- name: "Plant Moisture 4"

As you can see you can use 4 Sensors now.

Also if you have trouble while compiling,

watch that you have includes and libraries

esphome:

name: here-your-name

includes:

- stemma_soil_sensor.h

libraries:

- Wire

Expand full comment
Jan 12, 2023·edited Jan 12, 2023Liked by Alistair Young

This is what I did to get it working with a raspberry pi pico w

soil_sensor.h

```

#include "esphome.h"

#include "Adafruit_seesaw.h"

class SoilSensor : public PollingComponent, public Sensor {

public:

Adafruit_seesaw ss;

Sensor *TemperatureSensor = new Sensor();

Sensor *MoistureSensor = new Sensor();

SoilSensor() : PollingComponent(60000) {}

void setup() override {

ss.begin(0x36);

}

void update() override {

auto temp = ss.getTemp();

auto capread = ss.touchRead(0);

TemperatureSensor->publish_state(temp);

MoistureSensor->publish_state(capread);

}

};

```

```

esphome:

includes:

- soil_sensor.h

libraries:

- adafruit/Adafruit seesaw Library

```

```

# pico w

i2c:

sda: 8

scl: 9

```

```

sensor:

- platform: custom

lambda: |-

auto soil_sensor = new SoilSensor();

App.register_component(soil_sensor);

return {soil_sensor->TemperatureSensor, soil_sensor->MoistureSensor};

sensors:

- name: "Temperature"

unit_of_measurement: '°C'

- name: "Moisture"

```

Expand full comment

Unfortunately I couldn't get this working for me. Any help appreciated

log:

INFO Reading configuration /config/esphome/touch-sensor.yaml...

INFO Starting log output from /dev/ttyUSB0 with baud rate 115200

[11:06:06][I][ota:109]: Boot seems successful, resetting boot loop counter.

[11:06:06][D][esp32.preferences:113]: Saving 1 preferences to flash...

[11:06:06][D][esp32.preferences:142]: Saving 1 preferences to flash: 1 cached, 0 written, 0 failed

[11:06:06][E][ota:476]: No OTA attempt made, restarting.

[11:06:06][I][app:127]: Forcing a reboot...

[11:06:06]ets Jun 8 2016 00:22:57

[11:06:06]

[11:06:06]rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)

[11:06:06]configsip: 0, SPIWP:0xee

[11:06:06]clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00

[11:06:06]mode:DIO, clock div:2

[11:06:06]load:0x3fff0018,len:4

[11:06:06]load:0x3fff001c,len:1044

[11:06:06]load:0x40078000,len:10124

[11:06:06]load:0x40080400,len:5828

[11:06:06]entry 0x400806a8

[11:06:06][I][logger:243]: Log initialized

[11:06:06][C][ota:465]: There have been 0 suspected unsuccessful boot attempts.

[11:06:06][D][esp32.preferences:113]: Saving 1 preferences to flash...

[11:06:06][D][esp32.preferences:142]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed

[11:06:06][I][app:029]: Running through setup()...

[11:06:07][E][soil_sensor:060]: Failed to connect to soil sensor.

[11:06:07][I][soil_sensor:065]: Successfully reset soil sensor.

[11:06:07][C][wifi:037]: Setting up WiFi...

[11:06:07][D][wifi:384]: Starting scan...

[11:06:12]E (6448) task_wdt: Task watchdog got triggered. The following tasks did not reset the watchdog in time:

Expand full comment

Hey this works brilliantly! Thanks for putting this together. I'm having trouble getting the update interval to work.

- platform: custom

lambda: |-

auto soil_sensor = new StemmaSoilSensor();

App.register_component(soil_sensor);

return {soil_sensor->temperature_sensor, soil_sensor->moisture_sensor};

sensors:

- name: "Plant Temperature"

- name: "Plant Moisture"

update_interval: 60s

If I included update_interval on the custom sensor, it complains that update_interval isn't a valid option for custom sensor. Any ideas?

Expand full comment

Appreciate your work and you sharing it! Been struggling with cheap moisture sensors for a couple seansons now with generally unsatisfactory results. Wanted to try lady ada's version using your solution into home assistant. It's working but with issues. Only one of every 5 or 10 measurements are valid. It reads nearly max (1015 or so) and then a few values reflective of what the soil condition actually is then back to max. It repeats. A min filter has make it usable to get a fairly steady decline as moisture is decreasing, but it probably isn't intended to work that way. I'm not a programmer so my debug abilites are limited. Seem to be missing something. Got any ideas??

Expand full comment

Hi there, thx a lot. Copied your code and installed the .h in the ESPHome directory, but getting the following error "/config/esphome/solarfeuchte-v01.yaml: In lambda function:

/config/esphome/solarfeuchte-v01.yaml:64:30: error: expected type-specifier before 'StemmaSoilSensor'

auto soil_sensor = new StemmaSoilSensor();

^

/config/esphome/solarfeuchte-v01.yaml:66:76: error: could not convert '{<expression error>, <expression error>}' from '<brace-enclosed initializer list>' to 'std::vector<esphome::sensor::Sensor*>'

return {soil_sensor->temperature_sensor, soil_sensor->moisture_sensor};

^

*** [/data/solarfeuchte-v01/.pioenvs/solarfeuchte-v01/src/main.cpp.o] Error 1"

Any idea? What am I missing?

Expand full comment

Question for you. I'm looking to use this with outdoor compost bins. I don't have power out there, and was thinking I could have the probe mounted to the inside of the bins, and then the board itself mounted on the outside.

Do you think this would work with the setup? I'm assuming I need power to get there, but I really don't know.

Expand full comment