Pool water / air temperature in HA

hello, I am running home assistant from raspberry pi 4 and I want to integrate my pool water temperature into the home-assistant. What would be the best integration or devices that I should buy?
I want to have:
2 different water sensors
1 air temperature sensor

I was thinking to use ESP module and 2 DS18B20. i’m not sure what other modules do I need that I’d be very helpful if you can give me a step-by-step tutorial of this implementation.

Thank you.

There are a few different ways you can integrate your pool water temperature and air temperature sensors into HA. One option is to use ESPHome, as you mentioned. To do this, you will need the following:

  1. An ESP8266 or ESP32 development board.
  2. Two DS18B20 temperature sensors, one for the pool water and one for the air.
  3. Wires to connect the sensors to the development board.
  4. A computer with ESPHome installed.

To set this up, you will need to do the following:

  1. Connect the temperature sensors to the development board according to the instructions in the ESPHome documentation. Dallas Temperature Sensor — ESPHome

  2. Install ESPHome on your computer and configure it to connect to your WiFi network.

  3. Connect your ESPHome device to your computer using a USB cable.

  4. In ESPHome, create a new “node” and select the type of device that you have connected (e.g. ESP8266 or ESP32).

  5. In the node configuration, select the “Custom” option and then click the “Edit Custom YAML” button. To establish the addresses of you sensors you will first need to run the following code:

# Example configuration entry
dallas:
  - pin: GPIO23

# Note you don't have to add any sensors at this point

You will find something like this when you check the specific node logs :

  1. In the custom YAML editor, add the following lines of code to the above code to define the temperature sensors as sensors:
# Example configuration entry
dallas:
  - pin: GPIO23

sensor:
  - platform: dallas
    address: 0xA40000031F055028
    name: "Temperature #1"
  - platform: dallas
    address: 0xDD0000031EFB0428
    name: "Temperature #2"
  - platform: dallas
    # ...
  1. In the node configuration, click the “Generate Code” button to generate the code for your ESPHome device.

  2. Click the “Flash” button to upload the code to your ESPHome device.

  3. Once the code is uploaded, your ESPHome device should be able to read the temperature sensors and send the data to Home Assistant. You can then use the ESPHome integration in Home Assistant to view and monitor the temperature data.

1 Like

@bastero this is gold for me !
Most of the steps i understood, but i still have some questions.

  1. what is most recommended for my application ? ESP 32 or ESP8266 ?
  2. can i use the raspberry PI as the main computer ? I can link via wifi or via BLE ? (it worth to chose ESP32 only for BLE capability ? )
    The ESP32 or ESP ESP8266 will only gather the temperature, and send the infos to HA, trough raspberry pi ? Or i have to install HA on the ESP board ?

Basically, i miss the link between ESP boards and my HA which is running on raspberry pi

  1. what is most recommended for my application ? ESP 32 or ESP8266 ?
  • Based on the scope of the project you outline, I would recommend ESP8266, however if you want to expand the project at a later date and the features of the ESP32 will be used then use that. (Note: they are both supported on ESPHome, so either choice works. )
  1. can i use the raspberry PI as the main computer ? I can link via wifi or via BLE ? (it worth to chose ESP32 only for BLE capability ? )
  • Yes you certainly can use a Raspberry Pi, although I’d personally I’ve found the Pi 4 performance better than the Pi 3b using HA.

  • Regarding the use of BLE vs. WiFi, again this is a personal choice. Obviously distance from the server/router/BLE Proxy server will come into your decision.

  1. The ESP32 or ESP ESP8266 will only gather the temperature, and send the infos to HA, trough raspberry pi ?
  • In simple terms, the way the data flows in your temperature example is that HA is installed and resides on your Raspberry Pi, you can consider ESPHome as an Add-on application installed within the HA environment. There is an Add-on store that you will see once you have HA installed and running, where there are numerous add-ons of which ESPHome is one.
  1. Or i have to install HA on the ESP board ?
  • Per above ESPHome is an add-on of HA and is where one configures the ESP8266 or ESP32 as well as the temp. sensors. This will send data to HA as entities for you to project on a dashboard of your making.

I believe that once you get into it, you will find the experience very rewarding and the community very helpful. However, the expectation is that one tries to research and work though the issues first.

@bastero 'm planning to do the acquisitions
Do i miss something if i go with following hardware ?

  1. ESP32-WROOM-32D (also i saw -32U, and 32 simple. i hope * ESP32-WROOM-32D is the right choise). Also chip CP2102 vs CH9102 are not known for me.
  2. 2x temperature sensors DS18B20
  3. Optional: 1 breadboard for cable connections and trials
  4. 5V power source
  5. Rezistor of 4.7 Ohm

ESP32-WROOM-32D is a good choise? I miss anything ?

Thank you !

I went the easy route.

For pool temperature I just use a yolink outdoor sensor. It’s a LoRa so the distance is great and its battery powered. I have the sensor mounted in my skimmer and the hub sits in the basement and integrates easily with my HA. It is cloud connected but my pool temp is not a critical service for me.

It also was pretty cheap.

1 Like

You don’t need elaborate variant of the ESP32 for the project as described. The one you chose is perfect.

Please note that the ESP32’s operating voltage is 2.7V ~ 3.6V, therefore you will need to step down the PSU (Power supply Unit) to attain this voltage range.

This is done using a ‘Level converter / shifter’, with your 5V PSU. This can be ordered cheaply from Amazon or any other electronic distributor.

( Word of caution…, Please ensure to check the output voltage of the level shifter before plugging it into the ESP32, it must be within the operating range of the ESP32)

For a PSU, I would suggest you purchase a simple USB wall charger with Micro-usb to USB cable. The cable will also serve you to initially flash the ESP32 from HA.

Have fun!

I can not power my ESP32 dev kit is via the USB port ? I was thinking to use a standard 5 VDC power supply, connected trough micro USB port from ESP. I need also to use the Level converter ?
This version is right one ?
I also saw this part on some tutorials. I guess makes same thing but connecting to 5V and GND ?

Yes, you power your ESP32 ‘Dev’ board via the USB port on the PC, in this case the level shifter is already integrated on the board and therefore not necessary. To clarify, my assumption from your initial question was the you were using a bare ESP32 board in this case you would require the level shifter to power the ESP32 board.

Assuming that your plan is to use your ‘Dev’ board for the final product (which is perfectly reasonable…) then you don’t need to purchase the level shifter.

PS. the first level shifter you reference is perfectly good for the bare board application. Your second option is over kill (6Amp), as its current rating is overkill for your application.

Hope this clarifies your questions.

@bastero, i plan to buy this board. Maybe i used the “dev” not correct, but at this i was reffering.Model is ESP 32D - CH9102

For this one, i have all included or level shifter is required ?

No level shifter required, you are all set. Good luck!

you are gold ! thank you !

Hello, i just installed the sensors on esp32 and link to HA. seems to work fine. Even tho in the connection says to use an 4,7 resistor, i just used the plug attached.

Next plan is to command a relay, that will power on the hot water pump. I want to make a condition, that when water in the heat system is hotter with 30C, than pool water, pump will start. Is this possible? Is it safe to use 5V / 220v relays with esp32 board ?
This would be this model:

I also can use some sonoff basic relays, in order to stop/ start the poll pump. Is more safe than regular relays ?

Thank you !

‘’ Next plan is to command a relay, that will power on the hot water pump. I want to make a condition, that when water in the heat system is hotter with 30C, than pool water, pump will start. Is this possible? Is it safe to use 5V / 220v relays with esp32 board ? "

Yes, it’s certainly possible, although it’s advisable to isolate the relay from the ESP32, through the use of a transistor and/or an opto-isolator ( as shown below).

The following link may be of help: ESPHOME ESP32 DIY relay and switch module

The link you provide to the relay module with Optocoupler should work, as it already has an opto-isolator which will decouple the 3.3V from the 5.0V coil supply used to energize the relay.

Note: given that you are driving 220VAC, it is critical that you exercise care when working with the switch side of the relay, and that the relay is rated appropriately for the current the the pump will draw.

Typical relays are rated between 10-15 Amps, however check your pump to establish its current requirement

The circuit below explains how it works:

image

When the output of the ESP32/MCU (GPIO pin) goes high i.e. 3.3V this will activate D1&Q1 (Opto-isolator, note that this is powered by 5V supply). This will put a high (5.0V minus drop across R2) at the base of transistor Q2, which will in turn energize Q2 and the relay (also powered by 5V)

Great explanations again !
As i fail to completely understand the separate relays in esp32, i played with some SONOFF r2 relays i already had in pocket

I was able to power on / off the plug depending on temperature i set based on sensors, but i could not make A RELATIONS between them. So i could not say like:
When sensor_1 is above 30C than sensor_2 → power on plug

This is a condition i would like, so depending the temperature in the pool and heat system, this will run or not.

Thank you !

Yes, it’s sometimes difficult to understand what the Yaml is doing, so I’ll try and give you an example related to your temperature sensor used with binary sensor (threshold) that controls the switch component to switch the relay on or off.

In your case, I would use the Analog Threshold binary sensor sensor. In your Yaml code, I would insert the following where the trigger threshold is set to 30 deg:

switch:
  - platform: gpio
    pin: GPIO35       # Choose which output pin the relay is connected to.
    id: relay_status
    inverted: false  # You may need to change this to false depending on your logic 
    name: "Relay Status"

   
 # Defines the ESP32 pin the Dallas Temp sensor is attached to.
dallas:     
  - pin: GPIO34   # Choose which input pin the temp analog signal is connected to. 

# Individual sensors
sensor:
  - platform: dallas
    address: 0x1c0000031edd2a28  #  If you have multiple sensors the address will need to be different for each sensor.
    name: "temperature_sensor_1"   # The name used is linked with the binary_sensor below.

binary_sensor:
  - platform: analog_threshold
    name: "Pump controller"
    sensor_id: temperature_sensor_1
    threshold: 30   # Set this to the temperature you want to turn on/off the pump. 
    on_state:
      then:
        - switch.turn_on: relay_status  # If temp above threshold the relay will either be on.
    off_state:
      then:
        - switch.turn_off: relay_status  # If temp below threshold the relay will either be off.

Note that for the Analog Threshold binary component, there are upper and lower limits that can be set independently.

The comments in the code should help you understand the relationship between the sensor(s), logic and switch.

Hi,
For sure i will test this configuration. I’m missing tho the logic.As above obly one sensor is used , so how i will measure my pool temperature ?

Basically in my automation, i want to have:
Sensor 1: introduced in the pool
Sensor 2: introduced in the inflow pipe of the solar heating system. This will measure how hot the water from solar system got.

Condition:
When sensor2 is 30C + sensor1 temperature > Pump stat ~> water will get to be pumped in the pool. I want to start the pump only when temperature from heat system is hotter with 30 C than actual pool temperature

To understand the logic, think of it this way…

You defined the temperature sensor(s) as input(s) to the system each assigned their own unique addresses. You also defined the relay by id (relay_status) as the output from your system.

The logic is controlled by in original case, the analog threshold binary sensor. Where if above the 30deg threshold, turns the relay with id (relay_status) ON, and OFF when the water temperature falls below the 30deg threshold.

You may discover that you need to have different upper and lower bounds for temperature in the logic, otherwise your pump may oscillate when the temperature is close to your target. (see the previous link to the documentation for guidance)

New Case:
Sensor 1: introduced in the pool
Sensor 2: introduced in the inflow pipe of the solar heating system. This will measure how hot the water from solar system go

In this case you need to define two temperature sensors. Refer to the documentation on the “Getting Sensor ID’s” section of the Dallas Temperature Sensor

The switch component will remain as before, this defines the output that controls the relay.

The binary sensor logic will be per below (note that I haven’t tested it so you will have to do this…)

binary_sensor:
  - platform: analog_threshold
    name: "Pump controller"
    sensor_id: temperature_sensor_1
    threshold: 30   # Set this to the temperature you want to turn on/off the pump. 
    on_state:
      then:
        - if:
            condition:
              lambda: id(temperature_sensor_1).state + (id(temperature_sensor_2).state if "temperature_sensor_2" in locals() else 0) > 30
            then:
              - switch.turn_on: relay_status 
            else:
              - switch.turn_off: relay_status

@GavinCampbell - you still recommend YouLink for getting Pool Temp into HA? (I’m happy to pay a few dollars more to make it easier I think) Does it integrate directly/easily into HA?

Yup. Great distance and easy to setup. Integration is easy and the devices are relatively cheap.

I have one in my pool skimmer and a few in my fridges with no issues.

My only gripe is that its a cloud based integration. But my pool temperature is not a critical sensor so I’m OK with that.

2 Likes