tank cooler

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Guepin
New user
Posts: 6
Joined: 31 May 2021, 10:15

tank cooler

#1 Post by Guepin » 31 May 2021, 21:59

Hello everyone I need help with the rules to create a tank cooler.

I would like :
- if temperature> 27 ° C (including 28, 29, 30, 31, ...)
- Then activate relays 1 and 2
- Wait 30 seconds
- relay 1 remains activated and relay 2 must deactivate

this opens an electric water valve.

Once the tank temperature <22 ° C, you must:
- Relay 1 must be deactivated
- Relay 2 activated
- Wait 30 seconds
- deactivate relay 2 and relay 1 too

If anyone can help me write the rules
Capture d’écran 2021-05-31 à 10.39.59.png
Capture d’écran 2021-05-31 à 10.39.59.png (148 KiB) Viewed 11475 times

Thank you

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

Re: tank cooler

#2 Post by TD-er » 01 Jun 2021, 00:38

First of all the most important link:
https://espeasy.readthedocs.io/en/lates ... Rules.html

- TimerSet command: https://espeasy.readthedocs.io/en/lates ... html#timer

You should trigger on the task value update event.
E.g. if you use a temp sensor on a task named "tank" with value name "temp", you get something like this in the rules:

Code: Select all

on tank#temp do
  if %eventvalue1% > 27
    if [int#2] = 0
      let,2,1  // Set flag to prevent resetting the timer
      // Activate relay1  (e.g. using "Gpio" command)
      // Activate relay2  (e.g. using "Gpio" command)
      timerSet,2,30 // Set timer #2 for 30 sec to deactivate relay 2  
    endif
  endif
  if %eventvalue1% < 22
    if [int#1] = 0
      let,1,1  // Set flag to prevent resetting the timer
      // Deactivate relay 1  (e.g. using "Gpio" command)
      // Activate relay 2  (e.g. using "Gpio" command)
      timerSet,1,30    // Set timer #1 for 30 sec to deactivate both relays
    endif
  endif
endon

On Rules#Timer=1 do
      let,1,0  // clear the flag
    // Deactivate relay 1  (e.g. using "Gpio" command)
    // Deactivate relay 2  (e.g. using "Gpio" command)
endon

On Rules#Timer=2 do
      let,2,0  // clear the flag
    // deactivate relay 2  (e.g. using "Gpio" command)
endon
However, you must realize that the temperature may fluctuate and also that it may take a while for a temperature to drop.
So I added flags to prevent the timer to be restarted on every read of the temperature sensor.

But it may not be sufficient yet as the temperature may fluctuate and thus restart the timer.
You have to think for yourself if that's what you need to happen.
Last edited by TD-er on 01 Jun 2021, 11:52, edited 1 time in total.
Reason: Clearing the flag....

User avatar
chromo23
Normal user
Posts: 821
Joined: 10 Sep 2020, 16:02
Location: germany

Re: tank cooler

#3 Post by chromo23 » 01 Jun 2021, 09:50

@TD-er: You didn´t clear the flag.... ;)

It should be: let,1,0 and let,2,0

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

Re: tank cooler

#4 Post by TD-er » 01 Jun 2021, 11:52

chromo23 wrote: 01 Jun 2021, 09:50 @TD-er: You didn´t clear the flag.... ;)

It should be: let,1,0 and let,2,0
Sure I do now ;)
Thanks... Wasn't clear in my head anymore I guess.

Guepin
New user
Posts: 6
Joined: 31 May 2021, 10:15

Re: tank cooler

#5 Post by Guepin » 01 Jun 2021, 22:04

Thanks for your help. I tried to adapt the code with the name of my sensors.
I pasted the code but it doesn't work.
I modified
"on tank#temp" do by "on sonde#temp do"
"if %eventvalue1% > 27" by "if %sonde#temp% > 27

"if [int#2] = 0 " do we need to change?
" let,2,1" do we need to change?

Sorry I am really a beginner and even reading the manual I do not understand anything

Here is the code modified :

Code: Select all

on sonde#temp do
   if %sonde#temp% > 27
         if [int#2] = 0
               let,2,1  // Set flag to prevent resetting the timer
                gpio,12,0 // Activate relay1  (e.g. using "Gpio" command)
                gpio,13,0 // Activate relay2  (e.g. using "Gpio" command)
               timerSet,2,5 // Set timer #2 for 30 sec to deactivate relay 2  
          endif
     endif
  if %sonde#temp% < 25
    if [int#1] = 0
      let,1,1  // Set flag to prevent resetting the timer
      gpio,12,0 // Deactivate relay 1  (e.g. using "Gpio" command)
      gpio,13,1 // Activate relay 2  (e.g. using "Gpio" command)
      timerSet,1,5    // Set timer #1 for 30 sec to deactivate both relays
    endif
  endif
endon

On Rules#Timer=1 do
      let,1,0  // clear the flag
  gpio,12,0  // Deactivate relay 1  (e.g. using "Gpio" command)
  gpio,13,0  // Deactivate relay 2  (e.g. using "Gpio" command)
endon

On Rules#Timer=2 do
      let,2,0  // clear the flag
   gpio,13,0 // deactivate relay 2  (e.g. using "Gpio" command)
endon

User avatar
Ath
Normal user
Posts: 3418
Joined: 10 Jun 2018, 12:06
Location: NL

Re: tank cooler

#6 Post by Ath » 01 Jun 2021, 22:30

Guepin wrote: 01 Jun 2021, 22:04 "if %eventvalue1% > 27" by "if %sonde#temp% > 27
That change should be reverted, as %eventvalue1% is the correct variable, the first argument passed on to the event.

Also, you seem to try to both activate and de-activate a relay by setting the gpio to 0, I assume that de-activating should be done by setting the gpio to 1, for example:

Code: Select all

On Rules#Timer=2 do
      let,2,0  // clear the flag
   gpio,13,1 // deactivate relay 2  by setting the gpio to 1 (it seems setting it to 0 activates it?)
endon
/Ton (PayPal.me)

Guepin
New user
Posts: 6
Joined: 31 May 2021, 10:15

Re: tank cooler

#7 Post by Guepin » 03 Jun 2021, 09:58

Thanks you.
The program does not work correctly, relay 1 flashes when the temperature > 27 degrees et < 22 degrees
I give a diagram to make it easier to understand what I need

Image

At start-up : Relay 1 = 1 (for 30s while the valve closes)
Relay 2 = 0
If temperature > 27 : Relay 1 = 1 (for 30s while the valve is opening)
Relay 2 = 1
If temperature < 22 : Relay 1 = 1 (for 30s while the valve closes)
Relay 2 = 0
to simplify the program, relay 1 must be activated for 30 seconds at each change of state of relay 2 and at start-up

if water leak at the water valve, I want to cut the 220v to remove the danger with the water. that's why I want a 30 second timeout
Maybe it's not possible to create ? or that you have another idea

Thank you
Attachments
IMG_8746.jpg
IMG_8746.jpg (685.12 KiB) Viewed 11392 times

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

Re: tank cooler

#8 Post by TD-er » 03 Jun 2021, 10:45

Just one thing to watch out for... the "on" state for both relays differs.
This is something that's very easy to overlook when debugging. Especially for relay 2, it is the inverse of what you would expect.

Guepin
New user
Posts: 6
Joined: 31 May 2021, 10:15

Re: tank cooler

#9 Post by Guepin » 03 Jun 2021, 20:32

Okay, can you change the existing code?
thank you so much

Post Reply

Who is online

Users browsing this forum: No registered users and 18 guests