Making a DIY Pool Sensor


If you’re lucky enough to have a pool, knowing the temperture of it is a big plus. Is it up to temperature? Whilst you can do this with some pool controllers, they have a few disadvantages;

  1. mostly they are stand alone, so don’t integrate in to existing apps or automations systems. I want to keep using home assistant.
  2. they’re expensive e.g. my pool uses Pentair, their wifi bridge is > $600.
  3. also, maybe a minor detail, they tend to not be measuring the tempertature in the pool; most measure in a pipe somewhere.
  4. however, they were wired-in — meaning no batteries to replace

So, based on this my requirements were;

  • integrates in to home assistant
  • not too expensive (<$100)
  • takes the in-pool temperature
  • solar, or at least a very long battery life (3m+?)

This is a quick write up of the tools, hardware, sofware and setup of this project. The total price to assemble this (excluding tools) for me was ~$68, but I have 3 spare batteries, a spare solar panel, and 4 extra temperature sensors for that, and also could have used a $10 rather than $20 board — so you can probably build it for < $50 if you try.

View original post on Twitter

Tools

I used just a soldering iron and a cheap glue gun.

Hardware

You’ll need to have the following things:

An ESP32 or ESP8266 board

One of those would be my choice, but actually any of the compatible boards for the esp-home project listed here should work.

Note, you’ll want one that has some ability to charge a battery either via a cable, or built in. Seach for “esp32 jst” on Amazon. If I didn't have a spare TTGO LORA board laying about, I’d have bought a generic board, being careful of the JST connector size. Est $10–20.

I you don’t have / can’t get a board with charging built in, you can get a very cheap charge controller board — but it complicates things. I’d just run solar-only at that point.

Optionally, a battery for overnight readings

You can run without, but obviously you’ll only get readings when there is enough solar to run the board. This might actually be ok for some folks.

Note, you’ll want to check two things when ordering a battery:

  1. the polarity of the connector vs your board. there doesn’t seem to be a fixed standard; some of my ESP32 boards are +/-, then another board will be reversed: with the same connector. Double check, or risk frying something.
  2. the connector type. My board uses JST1.25.

I bought a 4 pack of 1000mAh batteries that are quite small. I didn’t bother testing / sizing these properly; so far they seem ok and last the night.

FYI I’m likely to swap to LiFeP04 due to having had one battery slightly “puff”; I’d be more worried of fire if this wasn’t a project floating in water. I think it puffed as the temperature in the shade Las Vegas is nearly 40c now, and it gets hotter.

A solar panel

I bought bunch to try, but one I settled on was from a pair for $14. Maybe you could try a smaller one, but this seems totally able to charge / last so far.

Prep:

  1. solder a reasonbly long pair of wires to the outputs. I used some heatshrink to protect where the wire goes through the lid of the pool float.
  2. hot-glue over the other exposed pads / outputs; I figured it would help stop any corrosion / shorts if it got wet.
  3. hot glue it to the lid of the chlorine float
  4. solder the positive to the 5v+ (or charge input) and negative to the gnd (or equiv on your charging setup).

A temperature sensor

DS18B20 sensors are “1-wire”. Confusingly they have 3 wires, I guess only one is for comms, say compared to i2c. Anyway, they’re cheap, fit the range of a pool and you can get them waterproof for cheap.

I bought this pack of 5 for $11 with the intention of adding a couple more to the project to sense diffent depths. Watch this space.

Prep: solder the black to GND, red to 5v+ and yellow to a GPIO — in my case (and config you’ll see later pin 13).

A zip-lock bag and cable tie / twist-tie

Shrug, I had these at home. The first attempt I used a zip-lock bag and hot-glued it shut with the wires through the glue to waterproof it. When I wanted to change sensors, or reflash it (I was still fiddling) this proved to be a real pain.

My current version I don’t seal, just fold and aim to have the opening as high up away from the water as possible. The twist-tie fits through the holes in the lid and you can use it to secure it up there. If it submerges, it will obviously drown.

A pool chlorine floater

I used this one as it matches the one already in my pool. It’s ~$22 on Amazon.

Code / Software

I use home assistant, so this setup is for assuming that you already have that running.

Setup

You’ll need a usb cable from your computer → the ESP board you chose.

Install esphome in your homeassistant. There are instructions here.

Secondly, install esphome on a computer that you can connect the board to. This will be used to build and flash the firmware from esphome to your board. Docs are here.

On a Mac (if you have homebrew already) it’s just “brew install esphome”…

Copy this YAML to a file. Update the wifi SSID (name) and password.

esphome:
  name: pool-sensor

esp32:
  board: heltec_wifi_lora_32_V2
  framework:
    type: arduino

logger:

api:
  password: ""

ota:
  password: ""

# try turning off the status LED on this board, to save power
status_led:
  pin:
    number: GPIO25
    inverted: false

# with "fast_connect" wifi, this works with 10s run duration
deep_sleep:
  run_duration: 10s
  sleep_duration: 10min

dallas:
  - pin: GPIO13

sensor:
  - platform: dallas
    address: 0xYOURSENSORID
    id: pool_temperature
    name: "Pool Temperature"
    device_class: temperature

wifi:
  ssid: "your-ssid"
  password: "your-password"
  fast_connect: true
Original Gist
For testing and finding the sensor ID it can be easier to comment out (prefix with #) the lines relating to deep_sleep.

Connect your board to USB. It should power-on in someway.

Next we’ll build and flash the board. In a terminal, run:

esphome run pool-sensor.yaml

It should do a bunch of stuff, then ask you to choose how to connect to the board. With a little luck, you’ll see a option matching the port / board you conencted. Choose that, it will flash the board.

Post flashing, you’ll get a log of what the board is doing. You want to:

  1. see it connect to your wifi (if not, fix the config and reflash)
  2. see it find your sensor’s ID — then replace this in the config and reflash, if not debug your connection to the sensor.
  3. see it connect to homeassistant. You’ll see it in the logs here, and if successful also in HA itself.

That should be it!

Final Assembly

  1. do the prep steps from above; attach the battery
  2. thread twist-tie through the chlorine float lid
  3. put board in zip-lock bag, and fix with the twist-tie to the lid
  4. put the sensor coiled up in the bottom and lock it together
  5. gently lower into the pool; don’t throw it as it’s top-heavy before there is water in the bottom.

Misc pictures

After a while you should end up with some data in Home Assistant! The drop is me taking the sensor out for pictures.
I also push this through to Apple Home

Issues so far

The first version of this project used a more normal i2c temperature sensor that wasn’t waterproof. I put 3–4 coats of plasti-dip on it, and it seemed to work well. I sealed and ESP32 and the wires to this up in a bag (…with hot glue), and then decided I wanted to support multiple depths. So this got disassembled. It was a REAL pain to remove from the bag.

The first version of this fell in to the pool whilst it was testing on the side. The battery and ESP32 didn’t live, but the sensor and solar panel survived.

The second version seems to get very hot itself. The battery seems to expand a little — I think due to being in direct sunlight. Maybe moving to LiFePO4 will be less sensitive?

Also, I’ve picked the sensor out of the water by the solar panel — at least here, it’s hot enough that the hot-glue isn’t that strong. Avoid doing this, or upgrade your glue.

What is next?

Ideas, and things I want to do next:

  1. add 1–2 more sensors for deeper in the pool
  2. figure out a different battery, as any lipo getting hot doesn’t seem great — or just run without a battery (obvious downsides though)
  3. figure out how to adjust the schedule; I’d rather have much more accurate updates during the day, and then less overnight — but I don’t see that option in esphome.
  4. ph sensing
  5. battery and or solar voltage reporting
  6. mapping / location reporting for where the reading was taken. super pointless / overkill, but tbh sounds like a fun challenge