How to make my pool heating system smart

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 » Fri Oct 13, 2023 9:55 am

I think you did a really good job getting things to work in a very clean way.

I just don't get what the intention is of

Code: Select all

return (220-round(x))+round(x);

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

Re: How to make my pool heating system smart

Postby icebrian » Fri Oct 13, 2023 10:30 pm

Thanks.

So the

Code: Select all

return (220-round(x))+round(x);
Serves the specific purpose of either giving me a 0 voltage reading, or 220 voltage reading. The thing is that voltage seems to fluctuate, and I was basically just looking for a kind of ON/OFF signal and not an actual voltage reading, so in this case, ON=220v and OFF=0v.

So take a voltage reading of say 180.4v, the rounding returns 180, the 220-180 returns 40, which when added to the rounded 180 results in 220v. So whenver there is a voltage reading higher than 5v, which implies the power is on, the voltage reading, irrespective of what it might be, will always returno 220v.

Oh and it also makes my charts in Home Assistant nicer to look at :)

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 Oct 14, 2023 11:18 am

icebrian wrote:
Fri Oct 13, 2023 10:30 pm
So whenver there is a voltage reading higher than 5v, which implies the power is on, the voltage reading, irrespective of what it might be, will always returno 220v.
That's what I figured. How about

Code: Select all

return 220;
in that case? :)

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

Re: How to make my pool heating system smart

Postby icebrian » Sat Oct 14, 2023 5:58 pm

Oh boy.... yes, I think that would work... :oops: :oops: :oops:

Amazing how one can overcomplicate.

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 » Sat Oct 14, 2023 6:50 pm

The thing is that voltage seems to fluctuate, and I was basically just looking for a kind of ON/OFF signal and not an actual voltage reading
Your mains sensor's output is actually intended to be used as a digital signal feeding into a high-impedance digital input. You could potentially simplify your code (and get more stable results) by using GPIO33 as a digital input/"binary sensor".

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

Re: How to make my pool heating system smart

Postby icebrian » Tue Oct 17, 2023 2:04 pm

Thanks for your comment and suggestion MicroController, unfortunately I am not sure what you mean (am still learning), however, in a way I am not very much concerned about the voltage fluctuations because I really just need to detect current, versus no current, an ON/OFF signal lets say.

One thing that I have been working on is on my temperature sensor, here I have two topics.

1. To use the sensor in my pool I needed to use an unused electricity cable to cover the distance between my attic (where my heating system is) and my pool. Now the sensor that came with my MAX6675 works perfectly, it was however somewhat short, so I need to buy a new longer sensor. In the meantime I've already bought two new additional sensors (this one https://www.amazon.es/-/pt/dp/B07N7DGZM4 and this one https://www.amazon.es/-/pt/dp/B08J48JMH5) , but it seems that either of these new sensors is always giving very big temperature fluctuations, sometime up to 7ºC in less than 40 seconds. It seems that in 6 reading, 4 are moderately correct and two are just completely off. In the end I had to revert back to original sensor that came with the MAX6675 board (https://www.amazon.es/-/pt/dp/B01F8PVZJ6). Anyone have any ideas on why this could happen?

2. So currently I am using the short temp sensor that works just fine. Temperature fluctuations are within 1ºC, which for my use case is fine. Now however I wanted to write a return function that only returns x.0ºc or x.5ºc. So if temp is say 20.4ºC return 20ºC, if temp is say 20.6ºc, return 20.5ºC. I tested the following in a python simulator:

Code: Select all

return (int(round(x*2, 1)) / 2);
Which works as intended, but when I add it to my esphome code I get the following error:

Code: Select all

pool-sensors.yaml: In lambda function:
pool-sensors.yaml:81:25: error: no matching function for call to 'round(float&, int)'
In file included from /home/icebrian/.platformio/packages/toolchain-xtensa-esp32/xtensa-esp32-elf/include/c++/8.4.0/cmath:45,
                 from src/esphome/core/component.h:5,
                 from src/esphome/components/adc/adc_sensor.h:3,
                 from src/esphome.h:3,
                 from src/main.cpp:3:
/home/icebrian/.platformio/packages/toolchain-xtensa-esp32/xtensa-esp32-elf/sys-include/math.h:308:15: note: candidate: 'double round(double)'
 extern double round (double);
               ^~~~~
It seems like I can't provide any parameter to the "round()" function, is that it? anyone know any other way in which I can accomplish this?

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 » Tue Oct 17, 2023 11:23 pm

anyone know any other way in which I can accomplish this?
Simply

Code: Select all

round(2*x)/2
should do the trick. Then return the "%.1f" formatted number.

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 » Tue Oct 17, 2023 11:53 pm

To use the sensor in my pool I needed to use an unused electricity cable to cover the distance
Thermocouples by their nature are sensitive to the material of the conductor they are connected to, i.e. using "random" copper wires can cause issues. Basically, the thermocouple works via the thermoelectric effect at the junction between two specific alloys, and by bringing another metal into the circuit you create a second "parasitic" thermocouple in the loop.

Edit:
"Si lo que se desea es aumentar la longitud de las guías, se debe usar el tipo correcto del cable de extensión. Así por ejemplo, el tipo K corresponde al termopar K. Al usar otro tipo se introducirá otra unión termopar (generando error en la medición)." ;-)

Since you probably don't need to measure >110°C in the pool, a cheap digital temperature sensor may be the better option. The DS18B20 is by far the most common sensor people use for things like this.

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

Re: How to make my pool heating system smart

Postby icebrian » Wed Oct 18, 2023 9:13 am

You are right "round(2*x)/2" does indeed work, I thought I tried this but concluded it didn't work, don't know why, Thanks!

And in the meantime have ordered a DS18B20 along with a plugable terminal to make things easier. Will test and report back.

Thanks! :)

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

Re: How to make my pool heating system smart

Postby icebrian » Fri Oct 20, 2023 1:59 pm

Hi, so I've received the new DS18B20. To test things, I brought my board down from the attic, removed the max6675 and wired everything for the DS18B20.

In my lab, everything is working great! I even simplified my wiring (no longer need a breadboard) and code to:

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: "REMOVED"
  password: "REMOVED"
    
dallas:
  - pin: GPIO17

sensor:
  - platform: dallas
    address: 0xcff57a1e1e64ff28
    name: "Pool Dallas Temperature Sensor"
    resolution: 10
  - platform: adc
    pin: GPIO33
    name: "Pool Voltage Sensor"
    update_interval: 60s
    accuracy_decimals: 0
    raw: true
    filters:
      - multiply: 0.095238
      - lambda: !lambda |-
          if (x < 6) {
            return 0;
          } else {
            return 220;
          }

output:
Now issue however is that when I put the DS18B20 sensor in my pool, thus use the 30m electric cabling for extension, I keep getting:

Code: Select all

[14:56:22][W][dallas.sensor:263]: 'Pool Dallas Temperature Sensor' - Scratch pad config register invalid!
[14:56:22][D][sensor:094]: 'Pool Dallas Temperature Sensor': Sending state nan °C with 1 decimals of accuracy
Basically sensor is not being found. I tested with a smaller 1m extension (same type of cable) and it worked, but with 30m of it, it is not working.

I searched online and have found many saying, distance shouldn't be much of an issue, but it seems that in my case it is.

Anyone have any ideas of what i could try?

Thanks,

Who is online

Users browsing this forum: No registered users and 79 guests