Page 1 of 1

How to disable rule at a specific time ?

Posted: 22 Aug 2018, 19:02
by DaveS
Hi All,

How can I disable the rule below every saturday from 16:00 till 23:00 only,every other day rule must be active.

on Pir_Sensor#Pir=1 do
if [LDR#Analog]<500
Publish RGB/0017F169/color/set,200,200,200
Publish RGB/0017F169/brightness/set,200
else
Publish RGB/0017F169/brightness/set,0
endif
endon

NTP has been setup and has synched with internet time server.

Thanks to all the devs for this brilliant firmware,have many nodes running espeasy and all are rock solid !

Thanks

Dave

Re: How to disable rule at a specific time ?

Posted: 23 Aug 2018, 02:19
by TD-er
Maybe this entry on the wiki can be helpful for you?
https://www.letscontrolit.com/wiki/inde ... Rules#Time

Re: How to disable rule at a specific time ?

Posted: 23 Aug 2018, 17:59
by DaveS
I saw that but it details how to enable a rule or some operation,not disabling a rule.
I understand the day and time configuration but do not know how to implement the disabling of the rule between the 2 times
I will search further then.

Re: How to disable rule at a specific time ?

Posted: 23 Aug 2018, 18:19
by grovkillen
Can't you use a dummy variable and a if statement that will execute the rule of the dummy variable is set to zero?

Re: How to disable rule at a specific time ?

Posted: 23 Aug 2018, 18:50
by TD-er
DaveS wrote:
23 Aug 2018, 17:59
I saw that but it details how to enable a rule or some operation,not disabling a rule.
I understand the day and time configuration but do not know how to implement the disabling of the rule between the 2 times
I will search further then.
Can't you use a "else" part?
Like "if <sunday> do... else ..." ?
I am not really familiar in the rules language.

Re: How to disable rule at a specific time ?

Posted: 24 Aug 2018, 08:46
by papperone
I think the rules are ok for simple timing setup, when it comes to more complex and/or weekly I prefer to move out from ESPeasy as it's not as flexible as needed and the rules can becaome way too complex and probably cosume lots of CPU.
As well without nested IFs the overall setup of combined criteria is as well not somethign easy to write and maintain.

PS: having all my devices communicating via MQTT setup on my RaspPi, I installed as well NodeRed and with this last one creating complex rules is a piece of cake !

Re: How to disable rule at a specific time ?

Posted: 24 Aug 2018, 09:45
by toffel969
grovkillen wrote:
23 Aug 2018, 18:19
Can't you use a dummy variable and a if statement that will execute the rule of the dummy variable is set to zero?
I agree that's a viable route

Lets assume a dummy device on Task 8, called Sat#dummy


Code: Select all


On Clock#Time=Sat,16:00 do 
Taskvalueset,8,1,1
Endon

On Clock#Time=Sat,23:00 do 
Taskvalueset,8,1,0
Endon


on Pir_Sensor#Pir=1 do
if [LDR#Analog]<500 AND [Sat#dummy]=0
Publish RGB/0017F169/color/set,200,200,200
Publish RGB/0017F169/brightness/set,200 
else
Publish RGB/0017F169/brightness/set,0 
endif
endon

Re: How to disable rule at a specific time ?

Posted: 24 Aug 2018, 17:35
by DaveS
Thank you Toffel969,
That is exactly what I want to achieve.
Will try it.
Regards
Dave

Re: How to disable rule at a specific time ?

Posted: 24 Aug 2018, 20:01
by papperone
it works as far as the module does not reboot for any given reason on saturday between 16:00 and 23:00 :|

Re: How to disable rule at a specific time ?

Posted: 24 Aug 2018, 20:21
by grovkillen
I would do a check right on system#boot and set the dummy accordingly.

Re: How to disable rule at a specific time ?

Posted: 24 Aug 2018, 22:53
by toffel969
papperone wrote:
24 Aug 2018, 20:01
it works as far as the module does not reboot for any given reason on saturday between 16:00 and 23:00 :|
Agreed, thats a flaw.

Re: How to disable rule at a specific time ?

Posted: 24 Aug 2018, 23:04
by grovkillen
toffel969 wrote:
24 Aug 2018, 22:53
papperone wrote:
24 Aug 2018, 20:01
it works as far as the module does not reboot for any given reason on saturday between 16:00 and 23:00 :|
Agreed, thats a flaw.

Code: Select all

On System#Boot do
 TaskValueSet,8,2,[%sysweekday%][%syshour%]
 Event,SetDummy
EndOn

On SetDummy do
 If [Set#Dummy2]<116 OR [Set#Dummy2]>123
  TaskValueSet,8,2,1
 Else
  TaskValueSet,8,2,0
 EndIf
EndOn

Re: How to disable rule at a specific time ?

Posted: 24 Aug 2018, 23:14
by grovkillen
Maybe change system#boot to

Code: Select all

Time#Initialized
?

Re: How to disable rule at a specific time ?

Posted: 24 Aug 2018, 23:16
by toffel969
grovkillen wrote:
24 Aug 2018, 23:04
toffel969 wrote:
24 Aug 2018, 22:53
papperone wrote:
24 Aug 2018, 20:01
it works as far as the module does not reboot for any given reason on saturday between 16:00 and 23:00 :|
Agreed, thats a flaw.

Code: Select all

On System#Boot do
 TaskValueSet,8,2,[%sysweekday%]
 TaskValueSet,8,3,[%syshour%]
 TaskValueSet,8,4,[Sat#Dummy2][Sat#Dummy3]
 Event,SetDummy
EndOn

On SetDummy do
 If [Set#Dummy]<716 AND [Set#Dummy]>723
  TaskValueSet,8,2,1
 Else
  TaskValueSet,8,2,0
 EndIf
EndOn
Isn't that only triggered on boot ? So you need this rule in addition to the before mentioned. Also I think the taskvalueset should be 8,1,1/0

Other than that it makes the setup a lot more robust. It's an elegant way to achieve reboot proof behaviour. I was thinking about a clock#time=Sat,**:** combined with systime check to set the dummy.... " ESP on Saturdays you must check every minute if it's between 7 or 23 o clock and set the dummy :mrgreen: :ugeek:

Re: How to disable rule at a specific time ?

Posted: 24 Aug 2018, 23:17
by grovkillen
I updated the post and suggested the Time#Initialized event instead :)

Re: How to disable rule at a specific time ?

Posted: 24 Aug 2018, 23:18
by grovkillen
And it's a add on to your splendid rule that you suggested. Thumbs up!

Re: How to disable rule at a specific time ?

Posted: 24 Aug 2018, 23:29
by grovkillen
And please bear in mind that this is me "coding" a rule on my phone on a Friday evening after two beers down :P

Re: How to disable rule at a specific time ?

Posted: 24 Aug 2018, 23:31
by toffel969
grovkillen wrote:
24 Aug 2018, 23:29
And please bear in mind that this is me "coding" a rule on my phone on a Friday evening after two beers down :P
:-) almost the same here. Just have a check on the taskvalueset,8,2,1 at the and. I'm almost sure it must be 8,1,1

Re: How to disable rule at a specific time ?

Posted: 24 Aug 2018, 23:32
by toffel969
grovkillen wrote:
24 Aug 2018, 23:18
And it's a add on to your splendid rule that you suggested. Thumbs up!
As splendid as sophisticated :lol:

Re: How to disable rule at a specific time ?

Posted: 25 Aug 2018, 07:47
by grovkillen

Code: Select all

On Time#Initialized do
 TaskValueSet,8,2,[%sysweekday%][%syshour%][%sysmin%]
 Event,SetDummy
EndOn

On SetDummy do
 If [Set#Dummy2]<71600 OR [Set#Dummy2]>72300
  TaskValueSet,8,1,1
 Else
  TaskValueSet,8,1,0
 EndIf
EndOn

On Clock#Time=Sat,16:00 do 
 Taskvalueset,8,1,1
Endon

On Clock#Time=Sat,23:00 do 
 Taskvalueset,8,1,0
Endon

on Pir_Sensor#Pir=1 do
 if [LDR#Analog]<500 AND [Sat#dummy]=0
  Publish RGB/0017F169/color/set,200,200,200
  Publish RGB/0017F169/brightness/set,200 
 else
  Publish RGB/0017F169/brightness/set,0 
 endif
endon
That would be the entire rule set? :)

Re: How to disable rule at a specific time ?

Posted: 25 Aug 2018, 09:49
by toffel969
grovkillen wrote:
25 Aug 2018, 07:47

Code: Select all

On Time#Initialized do
 TaskValueSet,8,2,[%sysweekday%][%syshour%][%sysmin%]
 Event,SetDummy
EndOn

On SetDummy do
 If [Set#Dummy2]<71600 OR [Set#Dummy2]>72300
  TaskValueSet,8,1,1
 Else
  TaskValueSet,8,1,0
 EndIf
EndOn

On Clock#Time=Sat,16:00 do 
 Taskvalueset,8,1,1
Endon

On Clock#Time=Sat,23:00 do 
 Taskvalueset,8,1,0
Endon

on Pir_Sensor#Pir=1 do
 if [LDR#Analog]<500 AND [Sat#dummy]=0
  Publish RGB/0017F169/color/set,200,200,200
  Publish RGB/0017F169/brightness/set,200 
 else
  Publish RGB/0017F169/brightness/set,0 
 endif
endon
That would be the entire rule set? :)
Looks perfect to me.

Re: How to disable rule at a specific time ?

Posted: 27 Aug 2018, 17:56
by DaveS

Code: Select all

On Clock#Time=Sat,16:00 do
TaskValueSet 3, 1, 1
endon

On Clock#Time=Sat,22:00 do
TaskValueSet 3, 1, 0
endon


on Pir_Sensor#Pir=1 do
   if [LDR#Analog]>1000 AND [Saturday#Inhibit]=0
     Publish RGB/0017F169/color/set,200,200,200
     Publish RGB/0017F169/brightness/set,200      
   endif
 endon

on Pir_Sensor#Pir=0 do
   if [LDR#Analog]>1000 AND [Saturday#Inhibit]=0
      Publish RGB/0017F169/state/set,OFF
  endif
endon
The rule above is working,good point regarding the node rebooting,will sort that.
Edited original rule a bit as I need to publish Publish RGB/0017F169/state/set,OFF when the PIR timed out after no motion detected.
This rule publishes all the time whether PIR state is 0 or 1
Can this constant spamming of the broker cause slower response time or is that not going to be a problem ?
There are 3 other nodes that publish frequently on my network also.
Thanks for the advise.

Re: How to disable rule at a specific time ?

Posted: 27 Aug 2018, 23:52
by toffel969
DaveS wrote:
27 Aug 2018, 17:56

Code: Select all

On Clock#Time=Sat,16:00 do
TaskValueSet 3, 1, 1
endon

On Clock#Time=Sat,22:00 do
TaskValueSet 3, 1, 0
endon


on Pir_Sensor#Pir=1 do
   if [LDR#Analog]>1000 AND [Saturday#Inhibit]=0
     Publish RGB/0017F169/color/set,200,200,200
     Publish RGB/0017F169/brightness/set,200      
   endif
 endon

on Pir_Sensor#Pir=0 do
   if [LDR#Analog]>1000 AND [Saturday#Inhibit]=0
      Publish RGB/0017F169/state/set,OFF
  endif
endon
The rule above is working,good point regarding the node rebooting,will sort that.
Edited original rule a bit as I need to publish Publish RGB/0017F169/state/set,OFF when the PIR timed out after no motion detected.
This rule publishes all the time whether PIR state is 0 or 1
Can this constant spamming of the broker cause slower response time or is that not going to be a problem ?
There are 3 other nodes that publish frequently on my network also.
Thanks for the advise.
What is the delay setting on the PIR switch device? If it is not 0, thats what will happen.

Re: How to disable rule at a specific time ?

Posted: 28 Aug 2018, 17:50
by DaveS
The PIR delay is set to 1 as I wanted a quick response once motion is detected.
Will this constant publishing slow broker response down at all ?
Openhab and mosquitto broker is running on a Pi 2.
Thanks again for the help chaps !

Re: How to disable rule at a specific time ?

Posted: 28 Aug 2018, 17:53
by grovkillen
The publishing will not be a problem for the broker. BUT if you set the delay to 0 (i.e. disable) will make the unit publish a change instantaneous.

Re: How to disable rule at a specific time ?

Posted: 29 Aug 2018, 07:48
by toffel969
DaveS wrote:
28 Aug 2018, 17:50
The PIR delay is set to 1 as I wanted a quick response once motion is detected.
Will this constant publishing slow broker response down at all ?
Openhab and mosquitto broker is running on a Pi 2.
Thanks again for the help chaps !
Ya just set that delay to 0 and the unit will behave the way you want.

Re: How to disable rule at a specific time ?

Posted: 28 Sep 2018, 20:08
by DaveS

Code: Select all

on Pir_Sensor#Pir=1 do
     if [LDR#Analog]>1000 AND [Saturday#Inhibit]=0
     Publish RGB/0017F169/color/set,200,200,200
     Publish RGB/0017F169/brightness/set,200      
   endif
 endon

on Pir_Sensor#Pir=0 do
      if [LDR#Analog]>1000 AND [Saturday#Inhibit]=0
      Publish RGB/0017F169/state/set,OFF
  endif
endon

These rules are working well but publish all the time to broker.
Is there a way to change the rules so that ESP easy will only publish once on Pir_Sensor state change ?
Thanks

Re: How to disable rule at a specific time ?

Posted: 28 Sep 2018, 21:19
by grovkillen
You could use a dummy and toggle that one only if the pir changes from 1->0 or 0->1. So prior to publish check that dummy and if it is 1 publish and then set it to 0.

Re: How to disable rule at a specific time ?

Posted: 01 Oct 2018, 17:45
by DaveS
Good idea,will set it up like that.
Thank you