between 2 hours

Moderators: grovkillen, Stuntteam, TD-er

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

between 2 hours

#1 Post by bledad » 29 Nov 2020, 10:41

hello,
howto do between 2 hours ??

Code: Select all

On Ldr#Analog do
 if [Ldr#Analog] >  840 and %v1% = 1
   gpio,4,0
 endif
 if [Ldr#Analog] <  840 and %v1% = 1
   gpio,4,1
 endif
endon
On Clock#Time>=All,7:30 and Clock#Time <=All,19:30 do
  Let,1,1
  gpio,4,1
endon
Thank you

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

Re: between 2 hours

#2 Post by Ath » 29 Nov 2020, 10:56

Events don't use 'and', AFAIK, so you'd have to use 2 events, 1 for turning the state to 'on' and another to go to the 'off' state:

Code: Select all

on Clock#Time=All,7:30 do
  Let,1,1
  Gpio,4,1
endon

on Clock#Time=All,19:30 do
  Let,1,0
  Gpio,4,0
endon
/Ton (PayPal.me)

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

Re: between 2 hours

#3 Post by bledad » 29 Nov 2020, 11:00

yes , but if i start the esp at 10h , I have to wait for the next day 7:30 am

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

Re: between 2 hours

#4 Post by TD-er » 29 Nov 2020, 11:19

You can also convert the time of day into an integer which can be used to compare.
This way you could trigger on every minute event to test it.

See %syssec_d% on the system variables page on the ESP.
This represents the number of seconds of the current day (assuming the time has been set)

This does make sure you are evaluating it right regardless of the moment of the day you turn on the ESP (or when it reboots)

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

Re: between 2 hours

#5 Post by bledad » 29 Nov 2020, 11:33

ok , if i understand
for 7h30 = 27000 seconds and 19h30 = 70200 seconds

Code: Select all

on %syssec_d% >= 27000 and %syssec_d% <= 70200 do
   Let,1,1
  Gpio,4,1
endon 
Right ?

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

Re: between 2 hours

#6 Post by bledad » 29 Nov 2020, 11:55

i try

Code: Select all

On Clock#Time do
   if  %syssec_d% >= 27000 and %syssec_d% <= 70200
     Let,1,1
     event RelayOn
   endif
endon 
no work
and

Code: Select all

on %syssec_d% >= 27000 and %syssec_d% <= 70200 do
   Let,1,1
  Gpio,4,1
endon 
no work

an idea ?

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

Re: between 2 hours

#7 Post by Ath » 29 Nov 2020, 13:47

bledad wrote: 29 Nov 2020, 11:55

Code: Select all

On Clock#Time do
   if  %syssec_d% >= 27000 and %syssec_d% <= 70200
     Let,1,1
     event RelayOn
   endif
endon 
Clock#Time needs a time to compare to, so if you need an event every minute, then it should be using a wildcard time like this:

Code: Select all

On Clock#Time=All,**:** do
   if  %syssec_d% >= 27000 and %syssec_d% <= 70200
     Let,1,1
     //event RelayOn
   else
     Let,1,0
     //event RelayOff
   endif
endon 
As I wrote above, events don't have 'and' logic, so this is not going to work:
bledad wrote: 29 Nov 2020, 11:55

Code: Select all

on %syssec_d% >= 27000 and %syssec_d% <= 70200 do
   Let,1,1
  Gpio,4,1
endon 
What is unclear to me is why you would want to turn the relay on, independent of the value of the LDR, IMHO, only the 'Let,1,1' / 'Let,1,0' should be in that event, the on/off logic should only be controlled by the comparison rule you had before
/Ton (PayPal.me)

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

Re: between 2 hours

#8 Post by bledad » 29 Nov 2020, 14:08

thank you,
what I want to do , of 7h30 at 19h30 led lighting (relay ) and if the daylight exists stop led lighting (relay )
stop led lighting (relay ) 19h31 at 7h29

sorry for my english

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

Re: between 2 hours

#9 Post by Ath » 29 Nov 2020, 14:15

Once you have put it all together, can you share your rules? Just to verify that you picked the correct parts (as you seem to understand the 'programming' concept available in rules, but your syntax was a bit off before)
/Ton (PayPal.me)

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

Re: between 2 hours

#10 Post by bledad » 29 Nov 2020, 14:17

its ok

Code: Select all

On Ldr#Analog do
 if [Ldr#Analog] >  840 and %v1% = 1
   event RelayOff
 endif
 if [Ldr#Analog] <  840 and %v1% = 1
   event RelayOn
 endif
endon

on RelayOff do
  gpio,4,0
endon

on RelayOn do
  gpio,4,1
endon

On Clock#Time=All,**:** do
   if  %systime% > 07:30:00
     Let,1,1
     event RelayOn
   endif
   if  %systime% > 19:30:00
     Let,1,0
     event RelayOff
   endif
endon 
with my english I need to understand the meaning of "On do"

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

Re: between 2 hours

#11 Post by bledad » 29 Nov 2020, 14:18

Ath wrote: 29 Nov 2020, 14:15 Once you have put it all together, can you share your rules? Just to verify that you picked the correct parts (as you seem to understand the 'programming' concept available in rules, but your syntax was a bit off before)
i am used to python

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

Re: between 2 hours

#12 Post by Ath » 29 Nov 2020, 14:42

bledad wrote: 29 Nov 2020, 14:17

Code: Select all

On Clock#Time=All,**:** do
   if  %systime% > 07:30:00
     Let,1,1
     event RelayOn
   endif
   if  %systime% > 19:30:00
     Let,1,0
     event RelayOff
   endif
endon 
with my english I need to understand the meaning of "On do"
The On ... Do construct are the events that are fired by the system when appropriate, read all about the standard events here: https://espeasy.readthedocs.io/en/lates ... vents.html

Your current code will turn on the lights every minute, even if the LDR says it's light enough, so you should probably change this part:
The %systime% values aren't parsed correctly for comparison, so the %syssec_d% should be used

Code: Select all

On Clock#Time=All,**:** do
   if  %syssec_d% > 27000 and %syssec_d% < 70200
     Let,1,1
   else
     Let,1,0
   endif
endon
Every time the value for the LDR changes, an event is fired and handled by the 'on Ldr#Analog do' event handler. If the condition meets then the relay will be switched on there.
Maybe you would want to build in a little hysteresis, to avoid the relay/light flipping on/off if the LDR value is just fluctuating on/off 840, it would then be something like this:

Code: Select all

On Ldr#Analog do
 if [Ldr#Analog] >  842 and %v1% = 1
   event RelayOff
 endif
 if [Ldr#Analog] <  838 and %v1% = 1
   event RelayOn
 endif
endon
edit: Fixed %systime% to %syssec_d%
/Ton (PayPal.me)

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

Re: between 2 hours

#13 Post by TD-er » 29 Nov 2020, 22:13

If you need to rely on sunrise and sunset, you can also set your GPS location and use the %sunrise% and %sunset% variables.
These even support adding/subtracting some minutes.

See system variables page (or readthedocs documentation) for more.

Code: Select all

%sunset%	18:50
%sunset-1h%	17:50
%sunrise%	6:43
%sunrise+10m%	6:53
And some sample rules using sunrise/sunset and some time notations:

Code: Select all

	
on Clock#Time=All,12:00 do //will run once a day at noon
 GPIO,2,1
endon

on Clock#Time=All,**:30 do //will run half past every hour
 GPIO,2,1
endon

on Clock#Time=All,%sunrise% do //will run at sunrise  (%sunset% is also available)
 GPIO,2,1
endon

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

Re: between 2 hours

#14 Post by bledad » 30 Nov 2020, 08:45

thank Ath for
The %systime% values aren't parsed correctly for comparison, so the %syssec_d% should be used
and hysteresis

thank TD-er for sunset and sunrise gps , I remember, but no need for the moment

i use it for plant light , and if there is sun the leds go out , I must now adapt the brightness with the ldr

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

Re: between 2 hours

#15 Post by bledad » 01 Dec 2020, 08:35

the module esp work , this morning the relay is on at 7h30 ,

but i cannot acces a web page !!!

did I forget to check something ?

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

Re: between 2 hours

#16 Post by Ath » 01 Dec 2020, 09:41

Well, you could 'check' the WiFi signal (2.4 GHz) at the location of the ESP, because poor WiFi signal is the most common cause of not being able to access the web page. There are free Android apps available for checking that (Wifi Analyzer is a well known one).

If the device is connected to a computer via USB, you can also check the serial log (connect to the com port of the device with a terminal program, like Putty using Telnet protocol, at 115200/No parity/8 databits/1 stopbit) to see if there is something obvious in the log.
/Ton (PayPal.me)

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

Re: between 2 hours

#17 Post by TD-er » 01 Dec 2020, 09:49

If the ESP cannot connect to an access point, it will start an AP itself.
So you may also try to connect to that one to see what is happening. (default password = "configesp")

A few things to try, all on Tools => Advanced page at the bottom:
https://espeasy.readthedocs.io/en/lates ... e-wifi-b-g
- Enable Periodical send Gratuitous ARP
- Disable Eco mode
- Force WiFi B/G

Very likely you need to restart the ESP now to get it to reconnect to the AP.

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

Re: between 2 hours

#18 Post by bledad » 01 Dec 2020, 13:26

ok , thank's

Ath
my WiFi signal (2.4 GHz) at the location of the ESP = -66%

TD-er

- Enable Periodical send Gratuitous ARP ( not found)
- Disable Eco mode
- Force WiFi B/G
esp.jpg
esp.jpg (70.85 KiB) Viewed 11774 times

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

Re: between 2 hours

#19 Post by TD-er » 01 Dec 2020, 13:46

Hmm, indeed the "Send Gratuitous ARP" is no longer present.
I will make sure to add it ASAP again.

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

Re: between 2 hours

#20 Post by bledad » 01 Dec 2020, 14:29

thank's , i will try

Post Reply

Who is online

Users browsing this forum: No registered users and 71 guests