Hydroponic Testing from Multiple Reservoir with centralized testing

I have multiple reservoir in a hydroponic setup I am using to grow vegetables and greens. Each hydroponics reservoir has a pump that I turn on with Home Assistant that pumps to a centralized testing tub. Then from the testing tub I can read different values(temperature, PH, EC) using a few ESPHome nodeMCU devices. However, I want the results from the testing to be recorded not one same sensor where the values would get muddled together but as related to the reservoir where the water came from. I am trying to figure out how I can have virtual sensors for temp, PH and EC for each reservoir and then send the values to the correct virtual sensor. I am using Node-Red as well as Home Assistant automatons as well as ESPHome devices - so I have a lot of flexibility but I have not figured out how I can integrate them together in a simple but functional way to accomplish this goal. Any ideas would be appreciated.

Template sensors.

Create an input select with options for each reservoir. Select the appropriate input select option when ready to measure (as an action at the end of your pumping automation for example). Use this input select to gate the update of your sensors. e.g.

input select:

input_select:
  tank_to_measure:
    name: Tank to measure
    options:
      - 'None'
      - 'Tank 1'
      - 'Tank 2'
      - 'Tank 3'

sensors:

  - platform: template
    sensors:
      tank_1_ph:
        friendly_name: 'Tank 1 pH'
        unit_of_measurement: 'pH'
        value_template: >
          {% if is_state('input_select.tank_to_measure', 'Tank 1' %}
            {{ states('sensor.common_ph') }}
          {% else %}
            {{ states('sensor.tank_1_ph') }}
          {% endif %}
      tank_2_ph:
        friendly_name: 'Tank 2 pH'
        unit_of_measurement: 'pH'
        value_template: >
          {% if is_state('input_select.tank_to_measure', 'Tank 2' %}
            {{ states('sensor.common_ph') }}
          {% else %}
            {{ states('sensor.tank_2_ph') }}
          {% endif %}
      tank_3_ph:
        friendly_name: 'Tank 3 pH'
        unit_of_measurement: 'pH'
        value_template: >
          {% if is_state('input_select.tank_to_measure', 'Tank 3' %}
            {{ states('sensor.common_ph') }}
          {% else %}
            {{ states('sensor.tank_3_ph') }}
          {% endif %}
      tank_1_ec:
        friendly_name: 'Tank 1 EC'
        unit_of_measurement: 'mS/cm'
        value_template: >
          {% if is_state('input_select.tank_to_measure', 'Tank 1' %}
            {{ states('sensor.common_ec') }}
          {% else %}
            {{ states('sensor.tank_1_ec') }}
          {% endif %}
      tank_2_ec:
        friendly_name: 'Tank 2 EC'
        unit_of_measurement: 'mS/cm'
        value_template: >
          {% if is_state('input_select.tank_to_measure', 'Tank 2' %}
            {{ states('sensor.common_ec') }}
          {% else %}
            {{ states('sensor.tank_2_ec') }}
          {% endif %}
      tank_3_ec:
        friendly_name: 'Tank 3 EC'
        unit_of_measurement: 'mS/cm'
        value_template: >
          {% if is_state('input_select.tank_to_measure', 'Tank 3' %}
            {{ states('sensor.common_ec') }}
          {% else %}
            {{ states('sensor.tank_3_ec') }}
          {% endif %}

The templates above will maintain the last value between samples. You can of course set it to 0 or unknown, or whatever you want in the else cases.

Set the input select to ‘None’ to stop updating of the sensors.

@tom_l - thanks so much for your help. That worked perfectly.

Nick

I’m looking to build something similar to this could you share you’re nodemcu sensor set up? Are you using esphome?

@jerame20 I am using esphome for almost all of my controls and sensors in my Greenhouse. Currently, I just have a DS18B20 for temperature that is using the multiple reservoir setup. I am just about to launch some 3d printed peristaltic pumps which are controlled by ESPhome for feeding nutrients and then I am going to work on the EC and PH sensor. So at the moment, I don’t have a lot of sensors to share but I am happy to share any of my configs if you are interested. Hopefully within a month or so I will have the EC and PH probes up and running on ESPhome and could share them then.

I’m interested in your project. How are you progressing. I’d like to automate some aspects of our aquaponics setup (temperature, EC and PH). It sounds like I can learn from your project.

I am really close but keep getting sidetracked on a different project. I am using the DFRobot Analog pH Sensor / Meter Pro Kit V2 and the Dfrobot Analog Electrical Conductivity Sensor /Meter V2. The key to getting this to work is to get the Gravity: Analog Signal Isolator otherwise the 2 sensors mess each other up. I have test the setup working and it seems to be working correctly. But calibration is kind of tricky to sort out because the units of measure are strange compared to the EC I am used to. Also, I hooked up a temperature sensor and need to write a lambda in ESPhome to do the conversion because EC varies quite a bit with temperature changes. My spring growing season is coming up soon so probably need to finish it up soon. I did get my 3d printed peristaltic pumps working for adding nutrients so the testing component is the last piece. FYI - I am using netDaemon to handle the automation.

Hi, @ngelotte Could you please share the code of ESPHome for pH and EC sensors that you used?

Here is my esphome config for EC sensor with adjustment for temperature. I have a Dallas based temperature sensor attached to the same ESP device.

i2c:
  sda: D1
  scl: D2
  scan: True
  id: bus_a
ads1115:
  - address: 0x49
dallas:
  - pin: D5
    update_interval: 5s
sensor:
  - platform: ads1115
    multiplexer: 'A0_GND'
    unit_of_measurement: 'EC'
    gain: 4.096
    id: 'ecSensor'
    name: "EC Sensor"
    update_interval: 3s
    accuracy_decimals: 0
    filters:
    - calibrate_linear:
      - 0.297 -> 1460 
      - 2.495 -> 12665
    - lambda: return x/(1 + (0.0185 * (id(watertemp).state - 25)));
    - lambda: if(x > 0) {return x;} else{ return 0;};
  - platform: dallas
    address: 0x6D011457A47EAA28
    name: "Water Temperature"
    id: watertemp

The calibration values would need to be updated based on your own tests with the reference solutions. bit the temperature conversion formula remains the same.

I went another route here… I was curious about this EC/TDS/pH/temp sensor on AliExpress. It advertised a bluetooth feature so I thought I could take a crack at reverse engineering it.

Here’s an ESPHome definition which uses BLE Client sensor (ESP32 only, obviously) to broadcast the readings into Home Assistant. The way they use BLE is pretty awkward so I had to do a bunch of text manipulation and publish to template sensors. The sensor is pretty much using BLE as a serial output and just outputting the contents of the screen (including only publishing the currently selected units). However, it works extremely well, considering it was a weekend hack project, though it is still incomplete (need to handle all units).

Ignore that EC spike, that’s because I changed units on the sensor and I don’t yet calculate the conversion. The pH spike seems to be that it can give weird and unstable readings when not in water. I am surprised it ever gave anything >14, but it also isn’t yet calibrated so /shrug…

I haven’t yet calibrated the unit or tested it for accuracy though.

Nonetheless, here is my ESPHome yml definition if anybody else wants to try it: ESPHome definition to pick up readings from the PH-260BD water PH/EC/TDS/Temp sensor - https://www.aliexpress.com/item/1005002707585119.html · GitHub

(cross-posting from Water quality pH0-14 Sensor - #6 by bjeanes)

That is really interesting. If you could reply back when you get it calibrated I may be interested in moving over if it works well. I prefer off the shelf components vs building my own but I did not know of a cost effective option that could integrate with HA. Those custom bluetooth messages are always annoying to figure out - glad you had some success decoding it.