Data from Arduino to ESP32 to Raspberry Pi

Hi guys,
i build a watering system for some of my plants and i want to monitor the sensor data in Home assistant.

I am able so send some data from the Arduino via the TX/RX pins to the ESP32, but now i dont know how to get the Data to Home Assistant and plot it. I plan to send the data from 4 moisture sensors.

The parts i have: Raspberry Pi 4, Arduino and ESP32 D1 Mini NodeMCU

Isn’t the ESP32 with esphome software enough? The ESP has GPIO, too.

@m0wlheld As i see it, you have an analog input, but digital only binary. Maybe i am missing something here.

Some GPIO are multi-purpose and with using the Analog Digital Converter sensor of esphome, you can use them to report analog values.

On the ESP32 pins GPIO32 through GPIO39 can be used.

I know that it has an ADC, but i want to send digital data from my arduino to the esp and then to the Home Assistant

Understood. My proposal was to connect the moisture sensors to the ESP32 directly and configure them as ADC inputs in ESPHome. ESPHome has a native integration in Home Assistant (which will actully pop-up as soon as your ESPHome-flashed devices starts).

Use esphome on the esp32. Use the UART text component I pointed to earlier.

@m0wlheld: I dont want to connect the moisture sensor directly to the esp32. I use the sensor as input data for the Arduino system. Besides that, i prefere digital data so i have less disturbance.

@nickrout: I am a beginner and would need some guidance.
In the UART example it is written
"Store this file in your configuration directory, for example “uart_read_line_sensor.h”
How do i do that? Is that something i have to do on the microSD card of the raspberry PI4?

Or do i have to do it in the Home Assistance interface in my browser? If it is here, where exactly? I have a “Configuration” in my menu and there is a “Skript” option, but i don’t think thats the right one.

So nobody can help me?

The directory where you store the esphome yaml file.

So i created a new Node which is called “WaterSensor.yaml”.
This file was saved in the folder: “/config/esphome”.
Then i created the file “uart_read_line_sensor.h” in the same folder.
After that, i added the rest from: https://esphome.io/components/text_sensor/uart.html to the “WaterSensor.yaml” file. It now looks like:

esphome:
  name: WaterSensor
  platform: ESP32
  board: nodemcu-32s
  includes:
    - uart_read_line_sensor.h

wifi:
  ssid: "xxx"
  password: "xxx"

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Watersensor Fallback Hotspot"
    password: "xxx"

captive_portal:

# Enable logging
logger:
    level: VERBOSE #makes uart stream available in esphome logstream
    baud_rate: 0
  
# Enable Home Assistant API
api:
  password: "xxx"

ota:
  password: "xxx"

uart:
    id: uart_bus
    tx_pin: D0
    rx_pin: D1
    baud_rate: 9600

text_sensor:
- platform: custom
  lambda: |-
    auto my_custom_sensor = new UartReadLineSensor(id(uart_bus));
    App.register_component(my_custom_sensor);
    return {my_custom_sensor};
  text_sensors:
    id: "uart_readline"

switch:
  - platform: template
    name: "Switch"
    lambda: |-
      if (id(uart_readline).state == "*POW=ON#") {
        return true;
      } else if(id(uart_readline).state == "*POW=OFF#") {
        return false;
      } else {
        return {};
      }
    turn_on_action:
      - uart.write: "\r*pow=on#\r"
    turn_off_action:
      - uart.write: "\r*pow=off#\r"

interval:
  - interval: 10s
    then:
      - uart.write: "\r*pow=?#\r"

Was that right?

When i try to compile it, i get the message:

INFO Reading configuration /config/esphome/watersensor.yaml...
Failed config

uart: 
  - [source /config/esphome/watersensor.yaml:32]
    id: uart_bus
    
    Cannot resolve pin name 'D0' for board nodemcu-32s.
    tx_pin: D0 [source /config/esphome/watersensor.yaml:33]
    
    Cannot resolve pin name 'D1' for board nodemcu-32s.
    rx_pin: D1 [source /config/esphome/watersensor.yaml:34]
    baud_rate: 9600