[FIXED] Problem with Rules - Clock#Time event

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
andy
Normal user
Posts: 65
Joined: 26 Jan 2016, 23:07

[FIXED] Problem with Rules - Clock#Time event

#1 Post by andy » 28 Mar 2016, 21:28

Original post:
I'm trying to set up a rule to run on a Clock#Time event. Problem seems to be the time passed is Day,Time, and the event triggers once Day is correct - completely dismisses the Time part. For instance, I have:

Code: Select all

On Clock#Time=Sat,16:30 do
  PCFGPIO,1,0
  timerSet,1,120
endon
The goal is to have a relay on PCFGPIO 1 trigger when the time hits 4:30 pm Saturday and start a 2 hour timer. Problem is, the event triggers when it sees Sat.

What options do I have here?
Okay, here's the fix. Thanks to Martinus and Drum who've been very helpful!

Release 95 now supports triggering on Clock#Time events. You can set a trigger based on *either* day,time or all,time.

If you want a trigger on Saturday at 16:30, you'd put:

Code: Select all

on Clock#Time=sat,16:30 do
If you want a trigger every day at 16:30, you'd put:

Code: Select all

on Clock#Time=all,16:30 do
Works great!
Last edited by andy on 08 Apr 2016, 17:34, edited 3 times in total.

Drum
Normal user
Posts: 300
Joined: 07 Feb 2016, 11:56

Re: Problem with Rules - Clock#Time event

#2 Post by Drum » 29 Mar 2016, 11:25

I am just guessing as I am not seeing what commands are available, or what "events" can be used, but perhaps adding a timer for 16.5 hours between line 1 and 2 would work.
Again no idea, but worth a try... From the Tutorial, you may have to make the second timer "Timer 2", but it appears you can have 2 timers, so I think something like this should work..

Perhaps someone who knows how it should work can chime in?

On Clock#Time=Sat,16:30 do
timerSet,1,990
PCFGPIO,1,0
timerSet,2,120
endon

andy
Normal user
Posts: 65
Joined: 26 Jan 2016, 23:07

Re: Problem with Rules - Clock#Time event

#3 Post by andy » 29 Mar 2016, 18:11

Thanks for the reply, Drum.

You're right, I can set up a second timer. I already have that part working - I have the relay turning on for two seconds, then off for 20 just to test the setup. That part has been flawless for days now.

My issue is I cannot get the thing to trigger automatically based on the time. For instance, I just ran this scenario using only the time as a trigger:

Code: Select all

on Clock#Time=07:58 do /Start Timer 1 at 07:58
 timerSet,1,10
endon

on Rules#Timer=1 do /Once Timer 1 triggers, start Timer 2
 timerSet,2,10
endon

on Rules#Timer=2 do /Once Timer 2 triggers, restart Timer 1
 timerSet,1,10
endon
and here's the log:

Code: Select all

EVENT: Clock#Time=Tue,07:55
WD   : Uptime 62 ConnectFailures 2 FreeMem 27696
WD   : Uptime 63 ConnectFailures 2 FreeMem 27696
EVENT: Clock#Time=Tue,07:56
WD   : Uptime 63 ConnectFailures 2 FreeMem 27456
WD   : Uptime 64 ConnectFailures 2 FreeMem 27456
EVENT: Clock#Time=Tue,07:57
WD   : Uptime 64 ConnectFailures 2 FreeMem 27456
WD   : Uptime 65 ConnectFailures 2 FreeMem 27456
EVENT: Clock#Time=Tue,07:58
WD   : Uptime 65 ConnectFailures 2 FreeMem 27456
Nothing triggered at 07:58.

If I change the rule to trigger at Tue,08:15 (note I included the day this time), I get:

Code: Select all

EVENT: Clock#Time=Tue,08:05
ACT  : timerset,1,10
EVENT: Clock#Time=Tue,08:06
ACT  : timerset,1,10
EVENT: Rules#Timer=1
ACT  : timerset,2,10
Just adding the Tue in front of the time causes the rule to trigger without regard to the actual time. Even adding quotes or double quotes around the Tue,08:15 doesn't stop the event from triggering the action.

andy
Normal user
Posts: 65
Joined: 26 Jan 2016, 23:07

Re: Problem with Rules - Clock#Time event

#4 Post by andy » 29 Mar 2016, 20:34

Does anybody know if it's possible to put modifiers in the Event call? For instance, if I could do something like:

Code: Select all

on right(Clock#Time,5)=10:55 do
then it would ignore all but the 5 rightmost characters. Of course, that doesn't work, but something similar perhaps?

Drum
Normal user
Posts: 300
Joined: 07 Feb 2016, 11:56

Re: Problem with Rules - Clock#Time event

#5 Post by Drum » 29 Mar 2016, 20:49

Oddly it appears to understand the day. How are you getting the time into the ESP? NPT or RTC? Do you know what section of the code deals with this feature? That might give me some insight into how this works.

andy
Normal user
Posts: 65
Joined: 26 Jan 2016, 23:07

Re: Problem with Rules - Clock#Time event

#6 Post by andy » 29 Mar 2016, 21:13

I'm using NTP: us.pool.ntp.org with -8 Timezone Offset and DST enabled.

The Rules section starts around line 1735 in Misc.ino, NTP is line 1670 in the same file. I'm not quite able to tell how the code is working. :oops:

Martinus

Re: Problem with Rules - Clock#Time event

#7 Post by Martinus » 30 Mar 2016, 12:06

Please beware that rules are experimental so this may contain many bugs. I can confirm that the clock event is not handled properly as it expects to compare float values instead of day/time.
This needs to be changed in the code.

andy
Normal user
Posts: 65
Joined: 26 Jan 2016, 23:07

Re: Problem with Rules - Clock#Time event

#8 Post by andy » 30 Mar 2016, 16:25

Thank you, Martinus, I appreciate the reply!

I really like the rules option. In my application it's important for the ESP to control relays based on inputs in case the wifi is lost. Otherwise I would handle it thru MQTT.

I hope 'experimental' doesn't mean they're considered expendable, and work continues on the rules. Fantastic feature.

Martinus

Re: Problem with Rules - Clock#Time event

#9 Post by Martinus » 30 Mar 2016, 17:27

R94 on github should work with clock events and rules.

andy
Normal user
Posts: 65
Joined: 26 Jan 2016, 23:07

Re: Problem with Rules - Clock#Time event

#10 Post by andy » 30 Mar 2016, 17:34

Martinus wrote:R94 on github should work with clock events and rules.
Sweet! I'll compile and load when I get home tonight and see how it goes. Can't wait! :D

andy
Normal user
Posts: 65
Joined: 26 Jan 2016, 23:07

Re: Problem with Rules - Clock#Time event

#11 Post by andy » 07 Apr 2016, 19:13

Okay, that's working now. :D

Is there a way now to test just the time, instead of the day and time combined? For instance, if I want a relay to trigger every day at 08:00 for 4 hours, I currently have to either set up seven rules to trigger on each day at 08:00 with a 4 hour timer, or wait for (say) Sunday, 08:00 and set a timer to trigger it every 24 hours in addition to the off timer at 4 hours.

Drum
Normal user
Posts: 300
Joined: 07 Feb 2016, 11:56

Re: Problem with Rules - Clock#Time event

#12 Post by Drum » 08 Apr 2016, 09:15

Try using "All" instead of the day... Based on below it could work. ;)
String weekDays = F("AllSunMonTueWedThuFriSat");

andy
Normal user
Posts: 65
Joined: 26 Jan 2016, 23:07

Re: Problem with Rules - Clock#Time event

#13 Post by andy » 08 Apr 2016, 17:27

Drum wrote:Try using "All" instead of the day... Based on below it could work. ;)
String weekDays = F("AllSunMonTueWedThuFriSat");
Drum, you're a rockstar! :idea: That worked great.

lacco
New user
Posts: 7
Joined: 19 Mar 2017, 00:46

Re: [FIXED] Problem with Rules - Clock#Time event

#14 Post by lacco » 07 Apr 2017, 13:57

Is it possible to use the time as a condition in a rule, like:

Code: Select all

On pir#Motion do
  if [pir#Motion]=1                   // Motion detected:
    if [Clock#Time]>All,17:00   // On any day after 17:00
      PWM,1,800,3000             // fade leds on
      timerSet 1,25                   // start timer
    endif
  endif
endon

on Rules#Timer=1 do
  PWM,1,0,3000                     // fade leds off
endon
?

Drum
Normal user
Posts: 300
Joined: 07 Feb 2016, 11:56

Re: [FIXED] Problem with Rules - Clock#Time event

#15 Post by Drum » 07 Apr 2017, 17:19

I have never tried it, but if I remember correctly, yes. Only way to really find out is to try it. I have no idea how reliable it is.

If you have NodeRed there is a "Big Timer" which has dusk and dawn, based on date and location, but then it is not an independent unit.

User avatar
toffel969
Normal user
Posts: 469
Joined: 03 Jan 2017, 10:58
Location: Germany

Re: [FIXED] Problem with Rules - Clock#Time event

#16 Post by toffel969 » 08 Apr 2017, 21:37

lacco wrote: 07 Apr 2017, 13:57 Is it possible to use the time as a condition in a rule, like:

Code: Select all

On pir#Motion do
  if [pir#Motion]=1                   // Motion detected:
    if [Clock#Time]>All,17:00   // On any day after 17:00
      PWM,1,800,3000             // fade leds on
      timerSet 1,25                   // start timer
    endif
  endif
endon

on Rules#Timer=1 do
  PWM,1,0,3000                     // fade leds off
endon
?
Yes this is possible but you must be %systime% instead of clock time. Also nesting is not possible (no second if before endif) you can work around by using several events
Domoticz on Raspi 2 -- 14 ESP units (hacked Sonoff,NodeMCUs, Wemos, self-built units) running with RC140- Mega 2.0.0 dev8

lacco
New user
Posts: 7
Joined: 19 Mar 2017, 00:46

Re: [FIXED] Problem with Rules - Clock#Time event

#17 Post by lacco » 12 Apr 2017, 19:28

Thanks! It does work now with:

Code: Select all

On pir#Motion do            // Motion detected:

  if %systime% > 17:00   // After 17:00
    PWM,1,800,3000        // fade leds on
    timerSet 1,25              // start timer
  endif

  if %systime% < 10:00   // Before 10:00
    PWM,1,800,3000        // fade leds on
    timerSet 1,20              // start timer
  endif

endon

on Rules#Timer=1 do
  PWM,1,0,10000            // fade leds off
endon

Carlini
Normal user
Posts: 16
Joined: 09 Apr 2017, 17:45
Location: Brazil

Re: [FIXED] Problem with Rules - Clock#Time event

#18 Post by Carlini » 23 Jul 2017, 19:12

Hi

Could you help me ? I am trying to use the rules below, but it is not working. I enable the NTP, but it not solved. The comparision is not working between %systime% and 16:30

Am I wrong something ?


On RelayA#state do
if %systime% > 16:10
Gpio,0,0
Endif
EndOn

ewaldharmsen
Normal user
Posts: 66
Joined: 16 Feb 2017, 09:23

Re: [FIXED] Problem with Rules - Clock#Time event

#19 Post by ewaldharmsen » 22 Oct 2018, 09:05

I have a similar problem, I want to have an action every work day at 7:30 but in the weekend at 9:30.
Is this possible in an easy way?

O should I create 7 if statements?

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: [FIXED] Problem with Rules - Clock#Time event

#20 Post by grovkillen » 22 Oct 2018, 09:55

Check weekday number first and then send it to an custom event.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

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

Re: [FIXED] Problem with Rules - Clock#Time event

#21 Post by TD-er » 22 Oct 2018, 10:35

We can also add a "%weekday%" parameter, which returns 0...6 That makes these rules a lot simpler

Edit: There is already a %sysweekday%
So it should be as simple as >=2 and <= 6 for determine if it is not a weekend.
or the other way around, < 2 or > 6 for weekend. (not sure if it starts at 0 or 1, I find "2" strange for Monday)

ewaldharmsen
Normal user
Posts: 66
Joined: 16 Feb 2017, 09:23

Re: [FIXED] Problem with Rules - Clock#Time event

#22 Post by ewaldharmsen » 23 Oct 2018, 09:07

Good one I fixed it like so:

Code: Select all

On Clock#Time=All,7:30
   If %sysweekday% >1 and %sysweekday% < 7
      gpio,13,0
   endif
endon
Thanks!

raceboy
New user
Posts: 9
Joined: 20 Jun 2017, 18:16

Re: [FIXED] Problem with Rules - Clock#Time event

#23 Post by raceboy » 29 Jul 2019, 10:23

how is code for days included Wed to Sun ?

I tried:

Code: Select all

If %sysweekday% >= 4 and %sysweekday% <= 8
but because Sun is int 1 ...can't work.

so i tried like this:

Code: Select all

If %sysweekday% >= 4 and %sysweekday_s% <= Sun
is this correct ? will it work like this ?

thanks (sorry for english)

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 29 guests