relay on/off every minute

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
bledad
Normal user
Posts: 82
Joined: 23 Nov 2020, 10:57
Location: France

relay on/off every minute

#1 Post by bledad » 19 Jul 2022, 18:50

hello,
i want use the relay on/off every minute and do not block the rules with wait
but no work

Code: Select all

Let,1,0
Let,2,0
on Clock#Time=All,**:** do

//relais 1 pin 13 bassin

  if  %syssec_d% > 25200 and %syssec_d% < 79200 //de 7h a 22h
         if %v1% = 0
         Let,2,(%syssec_d%+60)// add 60s 
         gpio,13,0
         Let,1,1
      
      if  %v2% = %syssec_d%  and %v1% = 1 // if v2 = second and v1 = 1
         Let,3,20
         Let,2,(%syssec_d%+60)
         gpio,13,1
      endif
      if %v2% = %syssec_d%  and %v1% = 1
         Let,3,30
         Let,2,(%syssec_d%+60)
         gpio,13,0
      endif

  endif
endon         
  
please can you help
thank

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

Re: relay on/off every minute

#2 Post by TD-er » 19 Jul 2022, 19:18

Do you mean something like this?

Code: Select all

on Clock#Time=All,**:** do
  //relais 1 pin 13 bassin
  if  %syssec_d% > 25200 and %syssec_d% < 79200 //de 7h a 22h
    gpiotoggle,13  // see: https://espeasy.readthedocs.io/en/latest/Plugin/P000_Relay.html?highlight=toggle#commands
  else
    gpio,13,0  // Turn off
  endif
endon         
Another approach can be to use the looptimer, if you want another interval duration.
Then you enable the loop timer at 7 am and set the looptimer to 0 at 22h.

bledad
Normal user
Posts: 82
Joined: 23 Nov 2020, 10:57
Location: France

Re: relay on/off every minute

#3 Post by bledad » 19 Jul 2022, 19:29

thank you for toggle ,
but how to have a space of time on the toggle ?
gpio,13,0 > 1 minute > gpio,13,1 > 1 minute > gpio,13,0 > 1 minute > gpio,13,1 > 1 minute .......
between 7h , 22h
and no sleep, waiting ...
because i use other rules for other relays

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

Re: relay on/off every minute

#4 Post by chromo23 » 19 Jul 2022, 19:36

Code: Select all

deleted 
the code TD-er wrote should do exactly what you asked for

bledad
Normal user
Posts: 82
Joined: 23 Nov 2020, 10:57
Location: France

Re: relay on/off every minute

#5 Post by bledad » 19 Jul 2022, 19:54

ok , I've found with Longpulse

Code: Select all

on Clock#Time=All,**:** do

//relais 1 pin 13 bassin

  if  %syssec_d% > 25200 and %syssec_d% < 79200 //de 7h a 22h
         if %v1%=0
         LongPulse,13,0,60
         Let,1,1 
         else
         LongPulse,13,1,60
         Let,1,0
         endif
         
  endif
endon         

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

Re: relay on/off every minute

#6 Post by chromo23 » 19 Jul 2022, 20:00

That´s another valid approach but the one TD-er suggested is much shorter and works the same way...

edit:
This is triggered every minute

Code: Select all

on Clock#Time=All,**:** do
That’s why the gpio is also toggled every minute with "GPIOToggle"

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

Re: relay on/off every minute

#7 Post by TD-er » 19 Jul 2022, 20:12

bledad wrote: 19 Jul 2022, 19:54 ok , I've found with Longpulse

Code: Select all

on Clock#Time=All,**:** do

//relais 1 pin 13 bassin

  if  %syssec_d% > 25200 and %syssec_d% < 79200 //de 7h a 22h
         if %v1%=0
         LongPulse,13,0,60
         Let,1,1 
         else
         LongPulse,13,1,60
         Let,1,0
         endif
         
  endif
endon         
This will not work as you might expect.
Problem is that the longpulse will schedule itself to switch the state back after set interval.
But there might be some jitter between handling these scheduled actions of longpulse and event handling.
So after a while a new longpulse may be started right after the previous one has ended, resulting in very short interval flipping the GPIO pin.

bledad
Normal user
Posts: 82
Joined: 23 Nov 2020, 10:57
Location: France

Re: relay on/off every minute

#8 Post by bledad » 20 Jul 2022, 17:46

hi,
I was happy, but now less so , since I added another function
the gpio 14 does not stay at 900 s (15minutes)
how to do it
thank you
301903: WD : Uptime 5 ConnectFailures 0 FreeMem 18624 WiFiStatus WL_CONNECTED 3 ESPeasy internal wifi status: Conn. IP Init
314347: EVENT: Clock#Time=Wed,17:40
314351: Cache rules event: rules1.txt pos: 67 on Clock#Time=All,**:** do
314376: ACT : LongPulse,14,0,900
314379: GPIO : port 14. Pulse set for 900000 ms
314381: ACT : Let,1,1
314397: ACT : gpio,12,0
314399: GPIO : port#12: set to 0
314410: ACT : gpio,13,0
314412: GPIO : port#13: set to 0
331902: WD : Uptime 6 ConnectFailures 0 FreeMem 18504 WiFiStatus WL_CONNECTED 3 ESPeasy internal wifi status: Conn. IP Init
361902: WD : Uptime 6 ConnectFailures 0 FreeMem 18800 WiFiStatus WL_CONNECTED 3 ESPeasy internal wifi status: Conn. IP Init
374347: EVENT: Clock#Time=Wed,17:41
374368: ACT : LongPulse,14,1,900
374371: GPIO : port 14. Pulse set for 900000 ms
374372: ACT : Let,1,0
374386: ACT : gpio,12,0
374388: GPIO : port#12: set to 0
374399: ACT : gpio,13,0
374401: GPIO : port#13: set to 0
391902: WD : Uptime 7 ConnectFailures 0 FreeMem 18968 WiFiStatus WL_CONNECTED 3 ESPeasy internal wifi status: Conn. IP Init
421903: WD : Uptime 7 ConnectFailures 0 FreeMem 18968 WiFiStatus WL_CONNECTED 3 ESPeasy internal wifi status: Conn. IP Init
434347: EVENT: Clock#Time=Wed,17:42
434365: ACT : LongPulse,14,0,900
434368: GPIO : port 14. Pulse set for 900000 ms
434370: ACT : Let,1,1
434386: ACT : gpio,12,0
434388: GPIO : port#12: set to 0
434400: ACT : gpio,13,0
434401: GPIO : port#13: set to 0
451903: WD : Uptime 8 ConnectFailures 0 FreeMem 18992 WiFiStatus WL_CONNECTED 3 ESPeasy internal wifi status: Conn. IP Init
481902: WD : Uptime 8 ConnectFailures 0 FreeMem 18992 WiFiStatus WL_CONNECTED 3 ESPeasy internal wifi status: Conn. IP Init
494347: EVENT: Clock#Time=Wed,17:43
494368: ACT : LongPulse,14,1,900
494372: GPIO : port 14. Pulse set for 900000 ms
494374: ACT : Let,1,0
494388: ACT : gpio,12,0
494390: GPIO : port#12: set to 0
494402: ACT : gpio,13,0
494403: GPIO : port#13: set to 0

Code: Select all

on Clock#Time=All,**:** do

//relais 3 pin 14 bassin

  if  %syssec_d% > 25200 and %syssec_d% < 79200 //de 7h a 22h
         if %v1%=0
         LongPulse,14,0,900
         Let,1,1 
         else
         LongPulse,14,1,900
         Let,1,0
         endif
   else
       gpio,14,1
         
  endif

//relais 2 pin 12 fontaine

   if  %syssec_d% > 39600 and %syssec_d% < 72000 //de 11h a 20h
     gpio,12,0
   else
     gpio,12,1
   endif

//relais 1 pin 13 sonette
   if  %syssec_d% > 28800 and %syssec_d% < 72000 //de 7h a 20h
     gpio,13,0
   else
     gpio,13,1
   endif
    
endon         

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

Re: relay on/off every minute

#9 Post by TD-er » 20 Jul 2022, 17:56

You reset the longpulse counter each time you call this function (which is every minute)

Why don't you use a timer instead of running on each minute timer event?

bledad
Normal user
Posts: 82
Joined: 23 Nov 2020, 10:57
Location: France

Re: relay on/off every minute

#10 Post by bledad » 20 Jul 2022, 18:04

i not understand
Why don't you use a timer instead of running on each minute timer event?
this ??
minut.jpg
minut.jpg (19.67 KiB) Viewed 3225 times

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

Re: relay on/off every minute

#11 Post by chromo23 » 20 Jul 2022, 18:05

Use a loop timer as suggested.

Code: Select all

On System#Boot Do
	LoopTimerSet,1,900
Endon

On Rules#Timer=1 Do
	If [Var#1]=1
		GPIOToggle,14
    	Else
    		GPIO,14,1
    	Endif
Endon

On Clock#Time=All,**:** Do
  	If  %syssec_d% > 25200 and %syssec_d% < 79200 //de 7h a 22h
        	Let,1,1 
   	Else
        	Let,1,0       
  	Endif

//relais 2 pin 12 fontaine

   if  %syssec_d% > 39600 and %syssec_d% < 72000 //de 11h a 20h
     gpio,12,0
   else
     gpio,12,1
   endif

//relais 1 pin 13 sonette
   if  %syssec_d% > 28800 and %syssec_d% < 72000 //de 7h a 20h
     gpio,13,0
   else
     gpio,13,1
   endif
    
endon     
Last edited by chromo23 on 20 Jul 2022, 18:15, edited 1 time in total.

bledad
Normal user
Posts: 82
Joined: 23 Nov 2020, 10:57
Location: France

Re: relay on/off every minute

#12 Post by bledad » 20 Jul 2022, 18:10

ok ,thank you , i try , I don't know all the functions yet

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

Re: relay on/off every minute

#13 Post by chromo23 » 20 Jul 2022, 18:14

The code is actually quite simple if you know the commands.
You should have a look here for a better understanding : https://espeasy.readthedocs.io/en/lates ... Rules.html

Edit: i forgot an endif in the code...just corrected it

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

Re: relay on/off every minute

#14 Post by TD-er » 20 Jul 2022, 21:11

bledad wrote: 20 Jul 2022, 18:04 i not understand
Why don't you use a timer instead of running on each minute timer event?
this ??
minut.jpg
LOL :lol:

Yep, something like that, but then in software :)

Post Reply

Who is online

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