Page 3 of 4

Re: ES 6.0: Rules engine for notifications

Posted: Mon Sep 14, 2020 12:53 pm
by Magic919
This looks good -

Code: Select all

CONSOLE DBG-1:2020-09-14,13:50:31 |----> FORK:Shed2 (12), eid:223366 rules: (eid: 223366) -- Processing rule: 1 --
CONSOLE DBG-2:2020-09-14,13:50:31 |----> FORK:Shed2 (12), eid:223366 rules: parsing rule 10:30/22:00 using format:%H:%M
CONSOLE DBG-2:2020-09-14,13:50:31 |----> FORK:Shed2 (12), eid:223366 rules: parsed time from: Thu Jan  1 10:30:00 1970 and to:Thu Jan  1 22:00:00 1970
CONSOLE DBG-2:2020-09-14,13:50:31 |----> FORK:Shed2 (12), eid:223366 rules:(eid: 223366)  seeing if now:13:50 is between:10:30 and 22:00
CONSOLE DBG-2:2020-09-14,13:50:31 |----> FORK:Shed2 (12), eid:223366 rules:(eid: 223366)  seeing if now:Mon is part of:Mon,Tue,Wed,Fri
CONSOLE DBG-1:2020-09-14,13:50:31 |----> FORK:Shed2 (12), eid:223366 rules: (eid: 223366) mute rule matched, not allowing
CONSOLE DBG-2:2020-09-14,13:50:31 |----> FORK:Shed2 (12), eid:223366 rules: Not processing start notifications as rules checks failed
CONSOLE DBG-1:2020-09-14,13:50:35 |----> FORK:Shed2 (12), eid:223366 rules: (eid: 223366) -- Processing rule: 1 --
CONSOLE DBG-2:2020-09-14,13:50:35 |----> FORK:Shed2 (12), eid:223366 rules:(eid: 223366)  seeing if now:13:50 is between:10:30 and 22:00
CONSOLE DBG-2:2020-09-14,13:50:35 |----> FORK:Shed2 (12), eid:223366 rules:(eid: 223366)  seeing if now:Mon is part of:Mon,Tue,Wed,Fri
CONSOLE DBG-1:2020-09-14,13:50:35 |----> FORK:Shed2 (12), eid:223366 rules: (eid: 223366) mute rule matched, not allowing
CONSOLE DBG-2:2020-09-14,13:50:35 |----> FORK:Shed2 (12), eid:223366 rules: Not processing end notifications as rules checks failed for start notification
It 'knows' now is Monday!

Re: ES 6.0: Rules engine for notifications

Posted: Mon Sep 14, 2020 2:26 pm
by asker
sounds good!

Re: ES 6.0: Rules engine for notifications

Posted: Mon Sep 14, 2020 5:40 pm
by Magic919
We are getting there.

Can I ask about 'cause_has'? Is that ready to test? I presume the strict order of these is unimportant.

My first test suggested it was just a mute and no reference to alarm cause. I wanted it to mute if there was a cause 'car'.

Re: ES 6.0: Rules engine for notifications

Posted: Mon Sep 14, 2020 7:05 pm
by asker
"cause_has" is a string or a regular expression that needs to be matched for the rule to kick in.

Code: Select all

For example:
{
   from: "9am",
   to:"6pm",
   cause_has: "cat",
   action:"mute"

}
This means "If the alarm has the word 'cat' inside its cause field and is between 9am - 6pm, don't notify"

It also supports regular expressions, so:

Code: Select all

For example:
{
   from: "9pm",
   to:"4am",
   cause_has: "^(?!.*(person)).*$",
   action:"mute"

}
This means "If the alarm DOES NOT have the word person in it, don't notify between 9pm - 4am".

Re: ES 6.0: Rules engine for notifications

Posted: Mon Sep 14, 2020 8:01 pm
by Magic919
I’ll try that tomorrow and see how I get on. Thanks

Re: ES 6.0: Rules engine for notifications

Posted: Tue Sep 15, 2020 8:25 am
by Magic919
Firstly, it's worth saying that there are no references to 'cause' in this log output, so I'm running blind.

Code: Select all

CONSOLE DBG-1:2020-09-15,09:17:14 |----> FORK:Shed2 (12), eid:223455 rules: (eid: 223455) -- Processing rule: 1 --
CONSOLE DBG-2:2020-09-15,09:17:14 |----> FORK:Shed2 (12), eid:223455 rules: parsing rule 09:15/22:00 using format:%H:%M
CONSOLE DBG-2:2020-09-15,09:17:14 |----> FORK:Shed2 (12), eid:223455 rules: parsed time from: Thu Jan  1 09:15:00 1970 and to:Thu Jan  1 22:00:00 1970
CONSOLE DBG-2:2020-09-15,09:17:14 |----> FORK:Shed2 (12), eid:223455 rules:(eid: 223455)  seeing if now:09:17 is between:09:15 and 22:00
CONSOLE DBG-2:2020-09-15,09:17:14 |----> FORK:Shed2 (12), eid:223455 rules:(eid: 223455)  seeing if now:Tue is part of:
CONSOLE DBG-1:2020-09-15,09:17:14 |----> FORK:Shed2 (12), eid:223455 rules: (eid: 223455) mute rule matched, not allowing
CONSOLE DBG-2:2020-09-15,09:17:14 |----> FORK:Shed2 (12), eid:223455 rules: Not processing start notifications as rules checks failed
CONSOLE DBG-1:2020-09-15,09:17:18 |----> FORK:Shed2 (12), eid:223455 rules: (eid: 223455) -- Processing rule: 1 --
CONSOLE DBG-2:2020-09-15,09:17:18 |----> FORK:Shed2 (12), eid:223455 rules:(eid: 223455)  seeing if now:09:17 is between:09:15 and 22:00
CONSOLE DBG-2:2020-09-15,09:17:18 |----> FORK:Shed2 (12), eid:223455 rules:(eid: 223455)  seeing if now:Tue is part of:
CONSOLE DBG-1:2020-09-15,09:17:18 |----> FORK:Shed2 (12), eid:223455 rules: (eid: 223455) mute rule matched, not allowing
CONSOLE DBG-2:2020-09-15,09:17:18 |----> FORK:Shed2 (12), eid:223455 rules: Not processing end notifications as rules checks failed for start notification
I put 'car' in there and this one was a truck. I only see the time/date part of the rules being assessed.

Re: ES 6.0: Rules engine for notifications

Posted: Tue Sep 15, 2020 12:36 pm
by asker
The chances are the event that is being checked does not have the cause you are expecting (sometimes they are written later, if you are using machine learning)

I've added a log so we can see what the cause is. Please update and lets look at the logs.

Re: ES 6.0: Rules engine for notifications

Posted: Tue Sep 15, 2020 12:53 pm
by Magic919
Thanks for your reply. That makes sense.

I'll update and we can see what occurs.

At some point I need to tackle the question of why ES doesn't 'catch' some ZM alerts. I've made sure they are all at least 15 seconds long and have the polling at 5 seconds. Maybe you have additional things I could check my end.

Re: ES 6.0: Rules engine for notifications

Posted: Tue Sep 15, 2020 12:59 pm
by Magic919

Code: Select all

 seeing if cause_has:car is part of :
Seems like it doesn't have my cause. Here's a bit of my json.

Code: Select all

                                "rules": [{
                                                "comment": "Be careful with dates, no leading spaces, etc",
                                                "time_format": "%H:%M",
                                                "from": "09:15",
                                                "to": "22:00",
                                                "action": "mute",
                                                "cause_has": "car"
                                        }

Re: ES 6.0: Rules engine for notifications

Posted: Tue Sep 15, 2020 1:51 pm
by asker
So that means the alarm that is coming through in ZM does not have a "detected: car" in it. Do you see "detected: car" in the event when you go to ZM?

Re: ES 6.0: Rules engine for notifications

Posted: Tue Sep 15, 2020 2:02 pm
by Magic919
Without it detecting as a car it shouldn't mute then.

It does mute. ZM for the last 4 alerts says

Code: Select all

[a] detected:car:99%  Motion: All

Re: ES 6.0: Rules engine for notifications

Posted: Tue Sep 15, 2020 2:13 pm
by Magic919
In terms of the log, the logic (to me) is different on cause based on your last message.

Code: Select all

seeing if now:15:04 is between:09:15 and 22:00
seeing if now:Tue is part of:
seeing if cause_has:car is part of :
mute rule matched, not allowing
LHS is the found or derived data (actual time, day), RHS is the defined data from the JSON.

Shouldn't the cause_has be ZM on LHS and JSON defined on RHS to match this. Not the other way around.

Re: ES 6.0: Rules engine for notifications

Posted: Tue Sep 15, 2020 3:33 pm
by asker
As it turns out there was a typo in the matching logic. Could you try again after updating?

Re: ES 6.0: Rules engine for notifications

Posted: Tue Sep 15, 2020 4:03 pm
by Magic919
Will do. Will let you know how it goes. Thanks.

Re: ES 6.0: Rules engine for notifications

Posted: Tue Sep 15, 2020 4:37 pm
by Magic919
I changed it to mute on truck, as it sees more cars here. That gave an alert.

Logs says -

Code: Select all

CONSOLE DBG-1:2020-09-15,17:32:32 |----> FORK:Shed2 (12), eid:223516 rules: (eid: 223516) -- Processing rule: 1 --
CONSOLE DBG-2:2020-09-15,17:32:32 |----> FORK:Shed2 (12), eid:223516 rules:(eid: 223516)  seeing if now:17:32 is between:09:15 and 22:00
CONSOLE DBG-2:2020-09-15,17:32:32 |----> FORK:Shed2 (12), eid:223516 rules:(eid: 223516)  seeing if now:Tue is part of:
CONSOLE DBG-2:2020-09-15,17:32:32 |----> FORK:Shed2 (12), eid:223516 rules:(eid: 223516)  seeing if cause_has:truck is part of :
CONSOLE DBG-1:2020-09-15,17:32:32 |----> FORK:Shed2 (12), eid:223516 rules: (eid: 223516) Skipping this rule as truck does not pattern match 
CONSOLE DBG-1:2020-09-15,17:32:32 |----> FORK:Shed2 (12), eid:223516 rules: (eid: 223516) Found rule for  (12) but no conflicts. Allowing.
CONSOLE DBG-1:2020-09-15,17:32:32 |----> FORK:Shed2 (12), eid:223516 Matching alarm to connection rules...