Using the DS3231 Module and Other Modules for Time and Relay State Management with ESP-Easy

Moderators: grovkillen, Stuntteam, TD-er

Message
Author
Neoseb38
Normal user
Posts: 122
Joined: 02 Dec 2024, 18:48

Re: Using the DS3231 Module and Other Modules for Time and Relay State Management with ESP-Easy

#51 Post by Neoseb38 » 17 Feb 2025, 19:41

149 euros!!!
It's nothing like before.
When you get to the payment stage, it jumps to 142 euros for DHL DDP (with customs fees included).
Otherwise, it's over 130 without customs fees and only 3 shipping options (UPS, DHL, and FedEx).
It’s nothing like what was advertised.
I even tried 3 times and removed as many items as possible...
This is outrageous.
Attachments
Capture d’écran 2025-02-17 à 19.23.44.png
Capture d’écran 2025-02-17 à 19.23.44.png (306.48 KiB) Viewed 4876 times

TD-er
Core team member
Posts: 9884
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Using the DS3231 Module and Other Modules for Time and Relay State Management with ESP-Easy

#52 Post by TD-er » 17 Feb 2025, 19:53

The costs are very likely because of through-hole component placement.
If you only have the PCBs, the shipment costs will still be the most expensive part.

You can also order 5 or 10 PCBs and then let them only assemble 2 or 5 boards.


With JLCPCB assembly you have 2 types of parts: Basic and Extended.
The Basic parts will add just the costs of the parts, the Extended parts add about 4 euro per different part.
That's why you should always look at the stock count and whether it can be done using a "Basic" part.
And if you need an Extended part, you should try to use it as often as possible (e.g. assume you need 10k and 20k resistors for whatever reason, you better use 2x 10k in series compared to 1x 20k)

Also through-hole components are _always_ "extended" parts.

And those larger parts like the HiLink transformers are quite heavy, which will add to the weight and thus shipping costs.
Those are also quite easy to solder yourself, so you could order those yourself from AliExpress or some local webshop.
You probably don't need 5 of those HiLink ones, right?
Those are probably the more expensive parts anyway.

Neoseb38
Normal user
Posts: 122
Joined: 02 Dec 2024, 18:48

Re: Using the DS3231 Module and Other Modules for Time and Relay State Management with ESP-Easy

#53 Post by Neoseb38 » 17 Feb 2025, 20:20

I will take a look at all of this and maybe remove the 3/4 and go back to the simpler approach to solder the components myself.
It's not necessarily the almost 70 euros for the supplies that bother me, since for 5 PCBs and with the Hilink, it comes to almost 15 euros per PCB.
What bothers me are the almost 80 euros for shipping, which is excessive. They also impose express shipping, and I can’t even choose Europacket as initially stated.

TD-er
Core team member
Posts: 9884
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Using the DS3231 Module and Other Modules for Time and Relay State Management with ESP-Easy

#54 Post by TD-er » 17 Feb 2025, 20:27

Check what happens if you uncheck the HiLink modules when uploading the BOM.
I guess the weight and dimensions of the package greatly depends on those.

Neoseb38
Normal user
Posts: 122
Joined: 02 Dec 2024, 18:48

Re: Using the DS3231 Module and Other Modules for Time and Relay State Management with ESP-Easy

#55 Post by Neoseb38 » 18 Feb 2025, 06:35

If I remove all the components and only leave the small resistors, the fuse holder, and the PCF chip, the price drops to 92 euros for 5 PCBs, delivered with DHL Express Priority (DDP).
If I only remove the HLK-10M05, the price goes to 104 euros.
Leaving everything as is, the total is 137 euros this morning (surprising how much prices fluctuate...).

If I only assemble 2 PCBs, I don’t save much—around 10 euros (without the HLK).

At around 5 euros per HLK on AliExpress, I’m wondering if it's really worth removing everything...

TD-er
Core team member
Posts: 9884
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Using the DS3231 Module and Other Modules for Time and Relay State Management with ESP-Easy

#56 Post by TD-er » 18 Feb 2025, 10:52

Well at least it is worth looking into the pricing structure as it will help you make an educated guess.
And this will help you accept the costs too :)

This is a rather simple board, but still assembling it yourself would at least cost you 30 - 45 minutes per board if you do it methodical and in series.
In other words, for roughly 45 euro more you don't need to spend about 4 hours soldering.

One tip when soldering the green headers... 3D print a clamp to keep them in a straight line and keep the female screw terminals plugged in while soldering. Otherwise you will make the pins tilt while soldering. Been-there-done-that.
The same for the other terminal headers.

I always do this for soldering headers.

For example to solder headers to a SenseAir S11 (Sunrise) sensor: https://www.tinkercad.com/things/1X9mRe ... ytqhjB9uPs

Clamp to hold those green pin headers (3.81mm, 4-pin and 3-pin)
https://www.tinkercad.com/things/3KRNlA ... ejPnq8SVhA

Neoseb38
Normal user
Posts: 122
Joined: 02 Dec 2024, 18:48

Re: Using the DS3231 Module and Other Modules for Time and Relay State Management with ESP-Easy

#57 Post by Neoseb38 » 18 Feb 2025, 17:18

12 euros with shipping euro packets for 5 PCBs if I don’t have anything assembled.
I’m redoing my PCB and replacing the PCF chip by pcf dip and resistors with larger ones.
No doubt about it! 😃

TD-er
Core team member
Posts: 9884
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Using the DS3231 Module and Other Modules for Time and Relay State Management with ESP-Easy

#58 Post by TD-er » 18 Feb 2025, 20:56

Just another warning/prediction ;)

You're hooked now and there will many PCBs follow :twisted:

Neoseb38
Normal user
Posts: 122
Joined: 02 Dec 2024, 18:48

Re: Using the DS3231 Module and Other Modules for Time and Relay State Management with ESP-Easy

#59 Post by Neoseb38 » 20 Feb 2025, 16:14

Hi, yes, I think you got it right 😃 I'm getting addicted.

I have a question:
I removed all the components that are too complicated for me to solder myself, such as the PCF chip and resistors.
Capture d’écran 2025-02-20 à 16.14.11.png
Capture d’écran 2025-02-20 à 16.14.11.png (197.82 KiB) Viewed 4365 times
I added this USB module, which is the one I currently use on my prototype and with which I haven’t had any power issues.

Should I also add the two 5.1kΩ resistances on D+ and D-?
Capture d’écran 2025-02-20 à 15.59.29.png
Capture d’écran 2025-02-20 à 15.59.29.png (194.85 KiB) Viewed 4365 times
I also wanted to know if it’s possible to flash the ESP32-ETH01, which doesn’t have a USB port, using this USB module.

I don’t really remember the exact procedure to install ESP Easy on it, but if I recall correctly, I had to use the module in the picture and connect the TX, RX pins, etc.
Capture d’écran 2025-02-20 à 15.59.18.png
Capture d’écran 2025-02-20 à 15.59.18.png (463.82 KiB) Viewed 4365 times
Do you think I can do the same without this flashing module since I will now have a USB-C port (if I create a male Dupont header and connect the TX, RX, 3.3V, GND, D+, and D- pins to it)?

TD-er
Core team member
Posts: 9884
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Using the DS3231 Module and Other Modules for Time and Relay State Management with ESP-Easy

#60 Post by TD-er » 20 Feb 2025, 16:23

The 5k1 resistors are connected to the CC pins.
Since those are not exposed on that board, you just have to hope they either have them included or your power supply will accept it as discussed before :)

I am not sure whether you need to have resistors between the D+/D- and GND/VCC.
I would leave them alone for now.
When needed, those pins are still accessible.


Flashing is 'just' pull GPIO-0 down to GND, then power on the device and flash using the USB to serial adapter.
N.B. you need to have TX and RX crossed, so RX of the USB adapter to TX of the ESP and vice verse. (as is done on the picture you placed)
... At least assuming the writing on the USB to serial adapter has written the actual signals on the silk screen and not the label of the pin it should connect to (trust me, those do exist)

So when it isn't working, you can always try to swap the RX/TX on one side.

Keep in mind you need a beefy power supply for flashing that Ethernet module as the Ethernet chip also may take 50 - 100 mA.

Neoseb38
Normal user
Posts: 122
Joined: 02 Dec 2024, 18:48

Re: Using the DS3231 Module and Other Modules for Time and Relay State Management with ESP-Easy

#61 Post by Neoseb38 » 20 Feb 2025, 16:31

So, to flash it, do I absolutely need the USB-to-serial module?

Wouldn't the small USB module on my PCB be enough?

So I just need to create a connector grouping TX, RX, GND, (5V, as I believe 3.3V didn’t work), and GPIO0?

Sorry if I got it all wrong.

TD-er
Core team member
Posts: 9884
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Using the DS3231 Module and Other Modules for Time and Relay State Management with ESP-Easy

#62 Post by TD-er » 20 Feb 2025, 22:55

The USB connector does only have pins with USB-level signals.
Not UART level signals.

The ESP board is going to be plugged in pin headers.
Programming you only need to do once, so you can pull out the ESP and program the board.

bidrohini
Normal user
Posts: 147
Joined: 03 Nov 2022, 16:24

Re: Using the DS3231 Module and Other Modules for Time and Relay State Management with ESP-Easy

#63 Post by bidrohini » 02 Mar 2025, 15:42

Neoseb38 wrote: 20 Feb 2025, 16:31
So I just need to create a connector grouping TX, RX, GND, (5V, as I believe 3.3V didn’t work), and GPIO0?
That's not a must. As Mr. TD-er has said above, "Programming you only need to do once, so you can pull out the ESP and program the board."
However, if you want to keep a provision for on-board programming in your board, it's better to modify your PCB and add an USART pinout that you mentioned. That will let you modify the program whenever you want to without removing the ESP from the board. By the way, is your board still in the designing phase or have you made a prototype? If you are thinking about the cost, you may have some idea from here: https://www.allpcb.com/blog/pcb-orderin ... -unit.html

Neoseb38
Normal user
Posts: 122
Joined: 02 Dec 2024, 18:48

Re: Using the DS3231 Module and Other Modules for Time and Relay State Management with ESP-Easy

#64 Post by Neoseb38 » 04 Mar 2025, 20:30

PCB received in 6 days with Europackets delivery and for only 12 euros.
Just wait for my Aliexpress order for the components.

PS: yes I made a prototype but on this ad, I made quite a few changes (see above)
I also added a connector grouping all the unconnected pins of the esp32, the ADS1115 and the PCF.

To be continued...

Neoseb38
Normal user
Posts: 122
Joined: 02 Dec 2024, 18:48

Re: Using the DS3231 Module and Other Modules for Time and Relay State Management with ESP-Easy

#65 Post by Neoseb38 » 09 Mar 2025, 11:34

IMG_5779.jpeg
IMG_5779.jpeg (3.4 MiB) Viewed 2231 times
IMG_5777.jpeg
IMG_5777.jpeg (3.39 MiB) Viewed 2231 times
Everything is working perfectly! :D
I received all the components in 6 days, same for the PCBs.
It works exactly like on my prototype, and my fears about integrating the PCF module have disappeared. The integrated chip works just like the module.



A huge thank you, TD-er, really.
And as you told me, I doubt this will be my last PCB! :D

Now, it's time for the rules...
That part scares me because I don't code, yet I managed to create one that works well and controls the filtration based on the water temperature. But I realize it's not going to be optimal.

Indeed, I have to modify the rules manually if I want to increase or decrease the filtration times.
So I’d like to add two push buttons to adjust this directly on the control box.
But this is beyond my skills.

Would you mind helping me?
I've been struggling with this for a while, and I hesitated to ask because I don't want to abuse your kindness.
And if you agree, how can I thank you? Financially?

I've tried several AIs, and they all generate code easily and quickly, but they don't always say the same things.
One in particular (GROK 3 of Elon Musk in "X")gives great explanations but generates unknown lines of code that I can't find in the ESPEasy documentation, such as Savevar and Loadvar to retrieve data once a day in case of a power outage.

It insists that it works and claims to have found it in some "hidden discussions"... lol
In short, AI isn't really helping me move forward.

Can I make a new post about this?
Could you help me?

TD-er
Core team member
Posts: 9884
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Using the DS3231 Module and Other Modules for Time and Relay State Management with ESP-Easy

#66 Post by TD-er » 09 Mar 2025, 16:33

All I can confirm is that those AI tools are halucinating :)

There is one plugin which allows to store (to flash) a variable. This is the "Level" plugin.
See: https://espeasy.readthedocs.io/en/lates ... #p021-page
As you can see in the commands of this plugin, there is no "SaveVar" or "LoadVar" command: https://espeasy.readthedocs.io/en/lates ... -available

The syntax to set a level: config,task,<taskname>,SetLevel,<value|calculation>
And to refer to a set level: [<taskname>#GetLevel]

With 1 write per day, I think it will not wear out the flash that quickly.
Not sure why you would like to change this adjustment daily though.

Personally I would not store the duration or start/end time as suggested in the AI-generated code.
I would calculate the required runtime in seconds, based on the temperature and set a timer to turn it off.

This leaves the question on what to do when the ESP boots after the filtration should have started, since you have no idea how long the pump has been running.
So the question here is, does it matter if the filtration is running too long?
If not, then I would suggest to start running a normal cycle if the ESP boots between 9 am and the expected duration based on the current temperature.


Calculating the runtime is something like this (assuming [TempEau#Temperature] has the correct temperature)
Please note to keep the more specific "On Clock#Time=.. do" lines before the one intended to run every minute.

I assume the task for the 'level' plugin to store the adjustment will be called "adjust"

Code: Select all

// Initialization on boot: Turn off pump, load saved variables, start timers
On System#Boot do
  gpio,12,0           // Turn off pump on startup (safety)
  
  if [adjust#GetLevel] < 0.5 OR [adjust#GetLevel] > 1.5
    config,task,adjust,SetLevel,1  // Default multiplier (100%)
  endif
  looptimerset,1,60   // Check every minute for filtration
endon


// Calculate filtration times
On Clock#Time=9:00 do
  asyncevent,calculateFiltration
endon

On Clock#Time=0:00 do
   let,1,0 // Clear calculated times
endon

// Check every minute if pump should remain on
On Rules#Timer=1 do
  // Check to see if the time is already past 9 am  (9 * 3600 = 32400 sec)
  if %unixday_sec% > 32400 and [int#1] = 0
    event,calculateFiltration
  endif
  
  if [TempEau#Temperature]<3  // If temperature < 3°C
    gpio,12,1         // Turn on pump (anti-freeze priority)
  else
    if %unixday_sec% > [int#2] and %unixday_sec% < [int#3]
      gpio,12,1           // Keep pump on
    else
      gpio,12,0           // Turn off pump
    endif
  endif
endon


on calculateFiltration do
  // Calculate filtration duration (store in var#1)
  Let,1,5400          // Minimum duration of 5400 sec if T < 10°C
  if [TempEau#Temperature] > 10
    Let,1,5400 + ([TempEau#Temperature]-10)*1800  // Add 0.5h per degree above 10°C
  endif
  
  // Apply adjustment
  let,1,[adjust#GetLevel] * [int#1]  
  
  // Now calculate start-time and end-time for pivot
  // Use %unixday_sec% variable to get the number of seconds of "today"
  // 14:00 is 3600 * 14 is at 50400 seconds in the current day
  let,2,50400 - ([var#1]/2)  // start time
  let,3,50400 + ([var#1]/2)  // end time
endon


// Increase multiplier by 5% with plus button
On ButtonPlus#State=1 do
  if [adjust#GetLevel] < 1.45
    Let,10,[adjust#GetLevel]+0.05  // Add 5%
    if [Var#10]>1.5       // Max limit: 150%
      Let,10,1.5
    endif
    config,task,adjust,SetLevel,[Var#10] // Save new multiplier
  endif
endon

// Decrease multiplier by 5% with minus button
On ButtonMinus#State=1 do
  if [adjust#GetLevel] > 0.55
    Let,10,[adjust#GetLevel]-0.05  // Subtract 5%
    if [Var#10]<0.5       // Min limit: 50%
      Let,10,0.5
    endif
    config,task,adjust,SetLevel,[Var#10] // Save new multiplier
  endif
endon


Of course not tested, just a simple write-down of what I see in your requirements.
Only thing not taken into account is the 10 minute interval when running in anti-freeze mode.

Neoseb38
Normal user
Posts: 122
Joined: 02 Dec 2024, 18:48

Re: Using the DS3231 Module and Other Modules for Time and Relay State Management with ESP-Easy

#67 Post by Neoseb38 » 09 Mar 2025, 17:47

Thanks again for everything you're doing to help me.

Until now, I was using this code:

Code: Select all

//Boot
On System#Boot do
   oledframedcmd,6,"Filtration: OFF"  // Affiche "Filtration: OFF" sur l'écran OLED
   oledframedcmd,7,"Eclairage: OFF"   // Affiche "Eclairage: OFF" sur l'écran OLED
   oledframedcmd,8,"PAC: OFF"         // Affiche "PAC: OFF" sur l'écran OLED
   logentry,"Système démarré."        // Log: Système démarré
endon

// Sécurité ANTI-GEL
On Temperature#Piscine do
   if [ModeAUTO#EtatModeAUTO]=1 And [InterOFF#EtatInterOFF]=0 And [Temperature#Piscine]<=8
     GPIO,2,1                        // Active la filtration
     timerSet,1,30                   // Timer de 30 secondes
     oledframedcmd,5,"ANTI-GEL ON"   // Affiche "ANTI-GEL ON" sur l'écran OLED
     logentry,"Anti-gel activé."     // Log: Anti-gel activé
   endif
endon

// Début journée
On Clock#Time=All,19:00 do
  if [ModeAUTO#EtatModeAUTO]=1
    if [Temperature#Piscine]>8 and [Temperature#Piscine]<=10
      timerSet,1,30                   // Timer de 30 secondes
      GPIO,2,1
      oledframedcmd,9,"Filtration AUTO"  // Affiche "Filtration AUTO" sur la ligne 9
      oledframedcmd,10,"de 9h à 11h"     // Affiche "de 9h à 11h" sur la ligne 10
      oledframedcmd,11,"Total:"          // Affiche "Total:" sur la ligne 11
      oledframedcmd,12,"30 sec"          // Affiche "30 sec" sur la ligne 12
      logentry,"Filtration: 30s"      // Log: Filtration activée pour 30 secondes
    elseif [Temperature#Piscine]<=15
      timerSet,1,60                   // Timer de 1 minute
      GPIO,2,1
      oledframedcmd,9,"Filtration AUTO"  // Affiche "Filtration AUTO" sur la ligne 9
      oledframedcmd,10,"de 9h à 11h"     // Affiche "de 9h à 11h" sur la ligne 10
      oledframedcmd,11,"Total:"          // Affiche "Total:" sur la ligne 11
      oledframedcmd,12,"1 min"           // Affiche "1 min" sur la ligne 12
      logentry,"Filtration: 1min"     // Log: Filtration activée pour 1 minute
    elseif [Temperature#Piscine]<=20
      timerSet,1,90                   // Timer de 1 minute 30
      GPIO,2,1
      oledframedcmd,9,"Filtration AUTO"  // Affiche "Filtration AUTO" sur la ligne 9
      oledframedcmd,10,"de 9h à 11h"     // Affiche "de 9h à 11h" sur la ligne 10
      oledframedcmd,11,"Total:"          // Affiche "Total:" sur la ligne 11
      oledframedcmd,12,"1 min 30"        // Affiche "1 min 30" sur la ligne 12
      logentry,"Filtration: 1min30"   // Log: Filtration activée pour 1 minute 30
    elseif [Temperature#Piscine]<=25
      timerSet,1,120                  // Timer de 2 minutes
      GPIO,2,1
      oledframedcmd,9,"Filtration AUTO"  // Affiche "Filtration AUTO" sur la ligne 9
      oledframedcmd,10,"de 9h à 11h"     // Affiche "de 9h à 11h" sur la ligne 10
      oledframedcmd,11,"Total:"          // Affiche "Total:" sur la ligne 11
      oledframedcmd,12,"2 min"           // Affiche "2 min" sur la ligne 12
      logentry,"Filtration: 2h"       // Log: Filtration activée pour 2 heures
    elseif [Temperature#Piscine]<=28
      timerSet,1,150                  // Timer de 2 minutes 30
      GPIO,2,1
      oledframedcmd,9,"Filtration AUTO"  // Affiche "Filtration AUTO" sur la ligne 9
      oledframedcmd,10,"de 9h à 11h"     // Affiche "de 9h à 11h" sur la ligne 10
      oledframedcmd,11,"Total:"          // Affiche "Total:" sur la ligne 11
      oledframedcmd,12,"2 min 30"        // Affiche "2 min 30" sur la ligne 12
      logentry,"Filtration: 2min30"   // Log: Filtration activée pour 2 minutes 30
    elseif [Temperature#Piscine]>28
      timerSet,1,180                  // Timer de 3 minutes
      GPIO,2,1
      oledframedcmd,9,"Filtration AUTO"  // Affiche "Filtration AUTO" sur la ligne 9
      oledframedcmd,10,"de 9h à 11h"     // Affiche "de 9h à 11h" sur la ligne 10
      oledframedcmd,11,"Total:"          // Affiche "Total:" sur la ligne 11
      oledframedcmd,12,"3 min"           // Affiche "3 min" sur la ligne 12
      logentry,"Filtration: 3min"     // Log: Filtration activée pour 3 minutes
    endif
  endif
endon

// Fin du timer
On Rules#Timer=1 do
  GPIO,2,0                            // Désactive la filtration
  oledframedcmd,5,"Mode: AUTO"        // Affiche "Mode: AUTO" sur la ligne 5
  oledframedcmd,9," "                 // Efface la ligne 9
  oledframedcmd,10," "                // Efface la ligne 10
  oledframedcmd,11," "                // Efface la ligne 11
  oledframedcmd,12," "                // Efface la ligne 12
  logentry,"Filtration désactivée. Affichage nettoyé."  // Log: Filtration désactivée et affichage nettoyé
endon

// Sécurité - Fin de journée
On Clock#Time=All,19:58 do
  if [ModeAUTO#EtatModeAUTO]=1
    if [Temperature#Piscine]>8
      GPIO,2,0                        // Désactive la filtration
      logentry,"Fin de journée."      // Log: Filtration désactivée en fin de journée
    endif
  endif
endon
It's the only one that works, but with no possibility of modifying the timers using my 2 push buttons.

Being a beginner, I admit I am completely lost in your code, but I will take the time to try to understand it, modify the devices to match mine, etc.
I will follow your advice to the letter, but please forgive me if I don't understand everything.
Just to let you know, I don’t have a dummy device; I’ve never made one.

PS: I’m still using the ESPeasy version you gave me (ESP32 ETH01)(ESP_Easy_mega_20241216_normal_ESP32_4M316k_LittleFS_ETH), and this time, I’m struggling a lot with saving my rules over Wi-Fi.
It’s gotten to the point where now it works perfectly over Ethernet (whereas before your help, it was the opposite...)
Last edited by Neoseb38 on 09 Mar 2025, 17:57, edited 1 time in total.

Neoseb38
Normal user
Posts: 122
Joined: 02 Dec 2024, 18:48

Re: Using the DS3231 Module and Other Modules for Time and Relay State Management with ESP-Easy

#68 Post by Neoseb38 » 09 Mar 2025, 17:55

Just in case:

My two other rules and my devices.

Now, I’m taking the time to decipher your code, it seems really great :D
Capture d’écran 2025-03-09 à 17.49.36.png
Capture d’écran 2025-03-09 à 17.49.36.png (561.11 KiB) Viewed 2175 times
Capture d’écran 2025-03-09 à 17.49.59.png
Capture d’écran 2025-03-09 à 17.49.59.png (191.83 KiB) Viewed 2175 times

Code: Select all

// Affichage Filtration sur l'ecran
On Filtration#EtatFiltration do
   if [Filtration#EtatFiltration]=1
      oledframedcmd,6,"Filtration: ON"
   else
      oledframedcmd,6,"Filtration: OFF"
   endif
endon

// Affichage Eclairage sur l'ecran
On Eclairage#EtatEclairage do
   if [Eclairage#EtatEclairage]=1
      oledframedcmd,7,"Eclairage: ON"
   else
      oledframedcmd,7,"Eclairage: OFF"
   endif
endon

//Affichage PAC sur l'ecran
On PAC#EtatPAC do
   if [PAC#EtatPAC]=1
      oledframedcmd,8,"PAC: ON"
   else
      oledframedcmd,8,"PAC: OFF"
   endif
endon

Code: Select all

// Mode Auto/Manuel
On ModeAuto#EtatModeAUTO do
   // Ne change rien si en mode Forcé ou Arrêt
   if ([InterON#EtatInterON]=0 and [InterOFF#EtatInterOFF]=0)
      if [ModeAuto#EtatModeAUTO]=1
         oledframedcmd,5,"Mode : Auto"
      else
         oledframedcmd,5,"Mode : Manuel"
      endif
   endif
endon

// Mode Forcé (InterON)
On InterON#EtatInterON do
   if [InterON#EtatInterON]=1
      oledframedcmd,5,"Mode : Forcé"
      gpio,2,1  // Active la filtration
   endif
   if [InterON#EtatInterON]=0 and [InterOFF#EtatInterOFF]=0
      // Retour au mode précédent (Auto ou Manuel), mais ne désactive pas la filtration
      if [ModeAuto#EtatModeAUTO]=1
         oledframedcmd,5,"Mode : Auto"
      else
         oledframedcmd,5,"Mode : Manuel"
      endif
   endif
endon

// Mode Arrêt (InterOFF)
On InterOFF#EtatInterOFF do
   if [InterOFF#EtatInterOFF]=1
      oledframedcmd,5,"Mode : Arrêt"
      gpio,2,0  // Désactive la filtration
   endif
   if [InterON#EtatInterON]=0 and [InterOFF#EtatInterOFF]=0
      // Retour au mode précédent (Auto ou Manuel)
      if [ModeAuto#EtatModeAUTO]=1
         oledframedcmd,5,"Mode : Auto"
      else
         oledframedcmd,5,"Mode : Manuel"
      endif
      // Désactive la filtration uniquement en mode Arrêt
      gpio,2,0  // Désactive la filtration
   endif
endon

Neoseb38
Normal user
Posts: 122
Joined: 02 Dec 2024, 18:48

Re: Using the DS3231 Module and Other Modules for Time and Relay State Management with ESP-Easy

#69 Post by Neoseb38 » 09 Mar 2025, 18:32

Here it is, I just put your code with my devices.

Code: Select all

// Initialisation au démarrage : Éteindre la pompe, charger les variables sauvegardées, démarrer les minuteries
On System#Boot do
  gpio,2,0           // Éteindre la pompe au démarrage (sécurité)
  
  if [adjust#GetLevel] < 0.5 OR [adjust#GetLevel] > 1.5
    config,task,adjust,SetLevel,1  // Multiplicateur par défaut (100%)
  endif
  looptimerset,1,60   // Vérifier toutes les minutes pour la filtration
endon


// Calcul des temps de filtration
On Clock#Time=9:00 do
  asyncevent,calculateFiltration
endon

On Clock#Time=0:00 do
   let,1,0 // Effacer les temps calculés
endon

// Vérifier toutes les minutes si la pompe doit rester allumée
On Rules#Timer=1 do
  // Vérifier si l'heure est déjà passée 9h (9 * 3600 = 32400 sec)
  if %unixday_sec% > 32400 and [int#1] = 0
    event,calculateFiltration
  endif
  
  if [Temperature#Piscine]<3  // Si la température < 3°C
    gpio,2,1         // Allumer la pompe (priorité anti-gel)
  else
    if %unixday_sec% > [int#2] and %unixday_sec% < [int#3]
      gpio,2,1           // Garder la pompe allumée
    else
      gpio,2,0           // Éteindre la pompe
    endif
  endif
endon


on calculateFiltration do
  // Calculer la durée de filtration (stockée dans var#1)
  Let,1,5400          // Durée minimale de 5400 sec si T < 10°C
  if [[Temperature#Piscine]] > 10
    Let,1,5400 + ([[Temperature#Piscine]]-10)*1800  // Ajouter 0.5h par degré au-dessus de 10°C
  endif
  
  // Appliquer l'ajustement
  let,1,[adjust#GetLevel] * [int#1]  
  
  // Calculer maintenant l'heure de début et de fin pour le pivot
  // Utiliser la variable %unixday_sec% pour obtenir le nombre de secondes de "aujourd'hui"
  // 14:00 est 3600 * 14 soit 50400 secondes dans la journée actuelle
  let,2,50400 - ([var#1]/2)  // heure de début
  let,3,50400 + ([var#1]/2)  // heure de fin
endon


// Augmenter le multiplicateur de 5% avec le bouton plus
On BoutonPlus#State=1 do
  if [adjust#GetLevel] < 1.45
    Let,10,[adjust#GetLevel]+0.05  // Ajouter 5%
    if [Var#10]>1.5       // Limite maximale : 150%
      Let,10,1.5
    endif
    config,task,adjust,SetLevel,[Var#10] // Sauvegarder le nouveau multiplicateur
  endif
endon

// Diminuer le multiplicateur de 5% avec le bouton moins
On BoutonMoins#State=1 do
  if [adjust#GetLevel] > 0.55
    Let,10,[adjust#GetLevel]-0.05  // Soustraire 5%
    if [Var#10]<0.5       // Limite minimale : 50%
      Let,10,0.5
    endif
    config,task,adjust,SetLevel,[Var#10] // Sauvegarder le nouveau multiplicateur
  endif
endon
I noticed that you set a pivot time at 2 PM. Do you think using a pivot time would be more appropriate than setting a fixed filtration start time? (Considering I have solar panels)

I will try to add some information to the screen because I’m not sure how to test it without information on the screen.
It should also only work in auto mode.

Do I need to create a dummy device?

TD-er
Core team member
Posts: 9884
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Using the DS3231 Module and Other Modules for Time and Relay State Management with ESP-Easy

#70 Post by TD-er » 09 Mar 2025, 21:57

To store the adjustment, you need to create a "Level" task.
However you can start without it, as long as you comment out the lines about the "adjust" in the System#boot and the one line when computing the duration.

I don't know whether it is a better choice to do the filtration around 14h, as I have no clue about pool maintainance.
I just followed your directions in your post.

To be honest, I found it a bit odd to determine the duration around 9am based on the temperature then which may differ quite a lot from the temperature during the rest of the day.
If you want to have the filtration running to consume your PV energy, then I guess it would make more sense to also include the energy output of the solar panels into the equation.
Whether you have the highest PV output in the morning or afternoon or around 12 depends on the orientation of your panels.

Neoseb38
Normal user
Posts: 122
Joined: 02 Dec 2024, 18:48

Re: Using the DS3231 Module and Other Modules for Time and Relay State Management with ESP-Easy

#71 Post by Neoseb38 » 10 Mar 2025, 18:10

Thanks again for your help.

I spent 4 hours yesterday trying your code, but I couldn't get it to work.
I tried displaying some information on my screen to see the plus and minus buttons, but it didn’t work.
It’s also not easy to test over such long periods, so I tried lowering the values.

I’m feeling my way through this, but I got discouraged 😄 because last night, I really felt like giving up.

Regarding the solar panels, as long as the filtration runs during the day (which is necessary to prevent algae growth), there’s no issue (south-facing exposure).

Actually, I didn’t want to determine the duration at 9 AM specifically, but since I don’t know how to code a pivot time, I simply created timers based on the temperature that would start from 9 AM.
But the pivot time seems like a much better approach, especially in case of a power outage—I totally agree with you on that.

I realize I drifted away from the original topic of this post.
I’ll create a new, more detailed post along with your code.

Thanks again for everything! This post is now closed since my PCB is working 😄

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 16 guests