How to make my pool heating system smart

icebrian
Posts: 13
Joined: Wed Jul 12, 2023 4:56 pm

How to make my pool heating system smart

Postby icebrian » Wed Jul 12, 2023 5:05 pm

Hello all,

Reverting to the wisdom of this forum hopefully to get some guidance on how to automate my pool heating system, potentially using ESP32. Will try to explain as best as possible.

In summary I have a current water heating system, that uses solar panels. These same solar panels also heat the pool when certain thresholds are met.

This all happens via three main connections to the pool system:
1) The actual hot water circuit that comes from the solar panel and goes through a specific closed circuit that the pool water is in contact with (blue dashed lines / flow B)
2) A 220v line that powers the pool pump when the solar panel closed water circuit flow (Flow B) is being diverted to the pool (fat red line)
3) A PT1000 temp sensor that is connected to the Daikin/Rotex controler (fat purple line)
current.png
current.png (367.66 KiB) Viewed 10360 times
So general rule is, if water heater temp > 65ºc and Pool temp < 35ºc (uses the PT1000 temp sensor for this reading), then close Flow A (from solar panels to water heater) and open Flow B (to pool) and at the same time start and run the pool pump to get water flowing through the system.

As is also visible in the diagram, I already have a Shelly 1PM Pro device to be able to control the Pool Pump remotely, which is already setup and working.

What I now would like to acheive is two things:

1) Hook up the PT1000 temperature sensor (purle line), to not only the Rotex DSR1 controlor but some other SoC such as ESP32 or ESP8266
2) Hook up the 220v line (which could be coverted to 12v) to also a RaspPi or Arduino or ESP32 or ESP8266 so that I can simply know when "Flow B" above is active. By knowing this I can then remotely use the Shelly 1PM to activate the Pool Pump, all of course using Home Assistant (which is already in use for a multitude of things).
final.png
final.png (423.22 KiB) Viewed 10360 times
So my question is, are the above two scenarios feasible/possible? If so, what would any of you recommend as the architecture? what SoC? how would connections work? can I use a 240v current or should I reduce to 12v/24v? what software could I use to get the readings? would this be easily integratable into home assistant? etc...

I am very new to ESP32 or ESP8266, so would greatly appreciate some hand holding to get me through a potential solution.

Many thanks!

ESP_Sprite
Posts: 9729
Joined: Thu Nov 26, 2015 4:08 am

Re: How to make my pool heating system smart

Postby ESP_Sprite » Thu Jul 13, 2023 5:20 am

Detecting the 220V/12V is trivial; you can simply add a relay that has a coil of the voltage required, and use one of its contacts as a simple switch. Detecting the PT1000 is not so trivial, as you don't know how the Rotex drives that thing. Easiest would be to install a 2nd temperature sensor specifically for the ESP, methinks. You probably want to look at ESPHome if you don't want to dev your own software to interface with HAS.

icebrian
Posts: 13
Joined: Wed Jul 12, 2023 4:56 pm

Re: How to make my pool heating system smart

Postby icebrian » Thu Jul 13, 2023 9:40 am

Hey, thanks for the reply.

Given my lack of knowledge in this area, can you point me to hardware and maybe docs that potentially detail a bit more about what you say about using a "relay that has a coil of the voltage required, and use one of its contacts as a simple switch"?

Also, in regards to the temp sensor, my issue passing a new cable up to the pool, don't think that will be feasible. The original instalares have however mentioned that the 220v cable might have extra unsused lines, which potentially could be used for the temp sensor. What temp sensor would you recommend and how many lines does it require?

Thanks,

icebrian
Posts: 13
Joined: Wed Jul 12, 2023 4:56 pm

Re: How to make my pool heating system smart

Postby icebrian » Fri Sep 22, 2023 5:09 pm

Hello everyone,

So I have been advancing on this project with some help, but haven't manged to get any code to run. Am looking for some help.

Basically I bought the following components:
[*] HiLetgo ESP-WROOM-32 ESP32 board (https://www.amazon.es/dp/B0718T232Z)
[*] HiLetgo MAX6675 DC 5V Temperature sensor (https://www.amazon.es/dp/B01F8PVZJ6)
[*] CA ZMPT101B Electricity sensor (https://www.amazon.es/dp/B0C33XV9Y2)
[*] AUKENIEN Breadboard + Jump wires (https://www.amazon.es/dp/B0B2DJPZG4)
[*] Hailege 5 V 2 Channel Relay Module (https://www.amazon.es/dp/B07XYWWDKW)

Wiring diagram is currently as follows:
circuit_schematic_icebrain_revised_bb.jpg
circuit_schematic_icebrain_revised_bb.jpg (956.56 KiB) Viewed 10070 times
And last revision of the code as follows:

Code: Select all

esphome:
  name: pool-sensors

esp32:
  board: nodemcu-32s
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  password: ""

ota:
  password: "REMOVED"

wifi:
  ssid: "MYSSID"
  password: "REMOVED"
    
# Code
spi:
  clk_pin: GPIO25
  miso_pin: GPIO27

sensor:
  - platform: adc
    pin: GPIO36
    name: "Voltage Sensor"
    update_interval: 60s

  - platform: max31865
    name: "Pool Temperature Sensor"
    cs_pin: GPIO26
    #miso_pin: GPIO27
    #clk_pin: GPIO25
    update_interval: 60s
    id: pool_temp_sensor
    reference_resistance: 430 Ω
    rtd_nominal_resistance: 100 Ω

binary_sensor:
  - platform: gpio
    pin: GPIO5
    id: relay_1
  - platform: gpio
    pin: GPIO18
    id: relay_2

text_sensor:
  - platform: template
    name: "Pool Temperature Display"
    lambda: |-
      return id(pool_temp_sensor).state;
    icon: "mdi:thermometer"
    
#uart:

output:
But I am always getting the following error:

Code: Select all

pool-sensors.yaml: In lambda function:
pool-sensors.yaml:63:32: error: could not convert 'pool_temp_sensor->esphome::max31865::MAX31865Sensor::<anonymous>.esphome::sensor::Sensor::state' from 'float' to 'esphome::optional<std::__cxx11::basic_string<char> >'
* [.pioenvs/pool-sensors/src/main.cpp.o] Error 1
I have tried everything to convert, but nothing works, allways get some similar error.

Can any help? Is the code going in the right direction? Is something completely wrong?

Thank you!

MicroController
Posts: 1706
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: How to make my pool heating system smart

Postby MicroController » Sat Sep 23, 2023 10:00 pm

Code: Select all

text_sensor:
  - platform: template
    name: "Pool Temperature Display"
    lambda: |-
      return id(pool_temp_sensor).state;
    icon: "mdi:thermometer"
The error

Code: Select all

could not convert '...state' from 'float' to '...basic_string<char>...'
indicates that the "state" is a floating point number, but 'text_sensor' expects a string to be returned.
This answer seems to solve the problem by using the sprintf()-function to format a float into a string.
In your case, something like this could do the trick:

Code: Select all

    lambda: |-
      char buf[16];
      sprintf(buf, "%.2f", id(pool_temp_sensor).state);
      return std::string {buf};
(See printf() or a tutorial for details on how to format the float value to your needs. In short, %.2f says a Float number is to be 'printed' with 2 digits after the decimal point.)

icebrian
Posts: 13
Joined: Wed Jul 12, 2023 4:56 pm

Re: How to make my pool heating system smart

Postby icebrian » Sun Sep 24, 2023 12:23 pm

Wow, fantastic, thanks so much MicroController. I did try everything before, but never managed to convert. Any code is now running, however, I am not getting any readings from my voltage sensor or temperature sensor.

Code: Select all

[13:21:30][E][max31865:101]: SPI bus read all 0 or all 1 (0x0000), check MAX31865 wiring & power.
[13:21:30][D][sensor:094]: 'Pool Temperature Sensor': Sending state nan °C with 2 decimals of accuracy
[13:21:30][D][sensor:094]: 'Voltage Sensor': Sending state 1.05700 V with 2 decimals of accuracy
So temperature is only just "nan" and voltage is always 1v even thou I have it connected to a power outlet and have confirmed voltage.

Can anyone help? might this be wiring or code?

Thanks,

MicroController
Posts: 1706
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: How to make my pool heating system smart

Postby MicroController » Sun Sep 24, 2023 1:17 pm

"Not A Number" (NAN) is usually the result of an 'illegal' floating point calculation, like dividing by 0.
Hard to tell where that value comes from. May be some code doing erroneous computations, or a sensor being read as '0', or something else.

icebrian
Posts: 13
Joined: Wed Jul 12, 2023 4:56 pm

Re: How to make my pool heating system smart

Postby icebrian » Sun Sep 24, 2023 6:54 pm

Hi once again, and thanks again also, as it was a tip in the right direction.

I managed to solve the issue with a few pin changes:

[*] clk pin = GPIO25 -> GPIO27
[*] Miso pin = GPIO27 -> GPIO19

And code corrections

Code: Select all

  #- platform: max31865
  - platform: max6675
    name: "Pool Temperature Sensor"
    cs_pin: GPIO26
    update_interval: 60s
    id: pool_temp_sensor
    #reference_resistance: 4300 Ω
    #rtd_nominal_resistance: 1000 Ω
Basically was using wrong platform for the sensor. Ups.

Temperature sensor is now working great, but my voltage sensor is not.

Even with power hooked up to the ZMPT101B sensor, my voltage is always 1v. I've tried various permutations with "attenuation" but voltage sensor just seemsto be completely all over the place.

Basically, all that I need is to get a "ON / OFF" or "1 / 0" for power ON or power OFF.

Can anyone help?

Thanks,

bidrohini
Posts: 202
Joined: Thu Oct 27, 2022 12:55 pm

Re: How to make my pool heating system smart

Postby bidrohini » Wed Sep 27, 2023 3:13 pm

I think, for the temperature sensor part, the DS18B20 underwater version will be a good choice too
https://www.theengineeringprojects.com/ ... 18b20.html
The sensor comes with a long cable. That will help you to connect the sensor with ESP32.

icebrian
Posts: 13
Joined: Wed Jul 12, 2023 4:56 pm

Re: How to make my pool heating system smart

Postby icebrian » Mon Oct 09, 2023 4:48 pm

Hello once again everyone,

So I think I have everything up and running! Firstly thanks very much for everyone's support, it was definately appreciated as it did stear me in the right direction. In the end I do have a few more questions, but let me first start of with changes and end result.

So firstly in terms of components, my final list is:
[*] HiLetgo ESP-WROOM-32 ESP32 board (https://www.amazon.es/dp/B0718T232Z)
[*] HiLetgo MAX6675 DC 5V Temperature sensor (https://www.amazon.es/dp/B01F8PVZJ6)
[*] 220V AC Mains Sensor / Optocoupler Isolation Module Ac 220v (https://www.fruugo.pt/modulo-de-isolame ... anguage=en)
[*] AUKENIEN Breadboard + Jump wires (https://www.amazon.es/dp/B0B2DJPZG4)

So, this means I ditched the ZMPT101B voltage sensor (never managed to calibrate it) and the Relay module, as I realised I didn't need it.

My final wiring diagram is as so:
diagram-simplified-va.png
diagram-simplified-va.png (467.91 KiB) Viewed 9507 times
And my final esphome code is as so:

Code: Select all

esphome:
  name: pool-sensors

esp32:
  board: nodemcu-32s
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  password: ""

ota:
  password: ""

wifi:
  ssid: ""
  password: ""
    
# Code
spi:
  clk_pin: GPIO27
  miso_pin: GPIO19

sensor:
  - platform: adc
    pin: GPIO33
    name: "Pool Voltage Sensor"
    update_interval: 5s
    accuracy_decimals: 0
    raw: true
    filters:
      - multiply: 0.095238
      - offset: 0
      - lambda: !lambda |-
          if (x < 3) {
            return x;
          } else {
            return (220-round(x))+round(x);
          }

  - platform: max6675
    name: "Pool Temperature Sensor"
    cs_pin: GPIO26
    update_interval: 15s
    id: pool_temp_sensor


    
text_sensor:
  - platform: template
    name: "Pool Temperature Display"
    lambda: |-
      char buf[16];
      sprintf(buf, "%.2f", id(pool_temp_sensor).state);
      return std::string {buf};
    icon: "mdi:thermometer"

output:
I also have it integrated with home assistant where I am using custom cards to show both temp sensor and voltage sensor.
ad2ad129-feda-448d-97b5-0876528945ff.jpeg
ad2ad129-feda-448d-97b5-0876528945ff.jpeg (17.35 KiB) Viewed 9507 times

So I guess my only question here is if anyone spots anything that doesn't make much sense or seems out of place? How can I potentially even simplify this more?

Thanks,

Who is online

Users browsing this forum: Majestic-12 [Bot] and 60 guests