Switch/Case (or equivalent) in an Automation Rule

Tips and Techniques for using MLServer's Automation Rules
Seajeff
Newbie
Newbie
Posts: 10
Joined: Wed Dec 05, 2007 10:41 pm
Contact:

Switch/Case (or equivalent) in an Automation Rule

Postby Seajeff » Wed Apr 29, 2009 10:59 pm

Hi-
I would like to monitor the status of many (simliarly named) server variables and take (similar) action based on when they change.

Here's my specific case: The Elk security system plugin is sucessfully updating the variables whenever an activity occurs. This is working well.

When I open door in zone 20, then:
mlelkm1_zone_020_statusval = 9
mlelkm1_zone_020_statusmsg = Violated - Open

From this I have created an automation rule that runs a command map when the statusval changes:

Whenever mlelkm1_zone_020_statusval changes value
Then Macro|SetVariable|Securityzonealert~020!Security.Mail


Here's the rub:
I have many zones...

So, is there anyway around having to manually duplicate the automation rules like so:
Rule 1:
Whenever mlelkm1_zone_001_statusval changes value
Then Macro|SetVariable|Securityzonealert~001!Security.Mail

Rule 2:
Whenever mlelkm1_zone_002_statusval changes value
Then Macro|SetVariable|Securityzonealert~002!Security.Mail

Rule 3:
Whenever mlelkm1_zone_003_statusval changes value
Then Macro|SetVariable|Securityzonealert~003!Security.Mail
....
Rule 20:
Whenever mlelkm1_zone_020_statusval changes value
Then Macro|SetVariable|Securityzonealert~020!Security.Mail


I have about a hundred zones. Entering them once is OK, but it seems it would make maintenance more difficult. Is there a way to use a switch/case or something similar to refactor? Or is there method to export/import the automation rules to edit in an interface which is more friendly to bulk updates like this?

Many thanks,
Jeff

User avatar
CinemarDave
Site Admin
Site Admin
Posts: 10535
Joined: Fri Feb 07, 2003 8:56 am
Location: Planet Earth
Contact:

Postby CinemarDave » Thu Apr 30, 2009 12:41 pm

There is no easy way to add all those rules today. If you have Microsoft Excel you could import the Access table into Excel. Add the rows and then store them back into Access. If you want to send me your Controls.mdb file I'll take a stab at adding the rules.

User avatar
Fonceur
Expert
Expert
Posts: 583
Joined: Sun Sep 09, 2007 10:18 am
Contact:

Postby Fonceur » Thu Apr 30, 2009 2:01 pm

CinemarDave wrote:There is no easy way to add all those rules today.

So would it be possible to add some kind of wild card to those rules, or the way it's handled internally just couldn't be adapted for that? Something like:

Code: Select all

Whenever mlelkm1_zone_<Var>_statusval changes value
Then Macro|SetVariable|Securityzonealert~<Var>!Security.Mail


or

Code: Select all

Whenever mlelkm1_zone_statusval_* changes value
Then Macro|SetVariable|Securityzonealert~*!Security.Mail
MLComDevice: Control serial/TCP device (ASCII/hex) - MLSchedule: Alternative to MLScheduler
MLBeyondTV and MLSageTV: PVR support - TChanger: Sony BDP-CX7000ES 400 disc Bluray changer
TRadio: Sirius/HD/XM radio - TChart: Chart from variable Wiki

Seajeff
Newbie
Newbie
Posts: 10
Joined: Wed Dec 05, 2007 10:41 pm
Contact:

Postby Seajeff » Fri May 01, 2009 11:18 pm

CinemarDave wrote:There is no easy way to add all those rules today. If you have Microsoft Excel you could import the Access table into Excel. Add the rows and then store them back into Access. If you want to send me your Controls.mdb file I'll take a stab at adding the rules.


Thanks Dave- that did work fine. Thanks for confirming there wasn't an easier way to do it.

-Jeff

User avatar
jjjukebox
Is there life beyond Cinemar?
Is there life beyond Cinemar?
Posts: 1024
Joined: Sat May 22, 2004 9:54 pm
Location: Toronto
Contact:

Postby jjjukebox » Sat May 02, 2009 9:10 am

Depending on how often Automation Rules cycles:

Whenever mlelkm1_zone_{{CurrentZoneMask}}_statusval changes value
Then Macro|SetVariable|Securityzonealert~{{CurrentZoneMask}}!Security.Mail

Set Up a Timer that increments every second like: MLTimer|SetTimer~SecurityZoneCycle~1~Security.ZoneMask


Security.ZoneMask
Macro|MLMath|Add~CurrentZone~{{CurrentZone}}~1!MLConditional|IsEqual##{{CurrentZone}}##100(or highest zone number)##SetVariable|CurrentZone~1!MLStrings|Len~CurrentZoneLen~{{CurrentZone}}!MLConditional|IsEqual##{{CurrentZoneLen}}##1##SetVariable|CurrentZoneMask~00{{CurrentZone}}##DoNothing!MLConditional|IsEqual##{{CurrentZoneLen}}##2##SetVariable|CurrentZoneMask~0{{CurrentZone}}##DoNothing

Something like this would cycle through 100 zones in 100 seconds or so.

Just a thought
Last edited by jjjukebox on Sat May 02, 2009 11:51 pm, edited 1 time in total.
J.J. Jukebox
Member

Seajeff
Newbie
Newbie
Posts: 10
Joined: Wed Dec 05, 2007 10:41 pm
Contact:

Postby Seajeff » Sat May 02, 2009 10:05 am

That is a very intersting approach. I doubt the loop would affect the CPU but I imagine it would add some "noise" to the event logs. Also, with 100 individual rules I still get pretty close to realtime notification instead of possibly waiting 100 seconds for a full cycle (worse case, but you pointed this out).

I do like the creative approach though- I'm going to experiment with this.

Thanks JJ!

User avatar
ronsatter
Is there life beyond Cinemar?
Is there life beyond Cinemar?
Posts: 1304
Joined: Mon Dec 04, 2006 1:40 am
Location: San Leandro, CA
Contact:

Postby ronsatter » Sat May 02, 2009 6:58 pm

JJ,

Excellent solution! Will certainly work for someone with just a few zones. I'm constantly amazed at your expertise with ML!

Mario ... hire this guy! :wink:

Ron
If it ain't broke ... don't fix it!

User avatar
jjjukebox
Is there life beyond Cinemar?
Is there life beyond Cinemar?
Posts: 1024
Joined: Sat May 22, 2004 9:54 pm
Location: Toronto
Contact:

Postby jjjukebox » Sat May 02, 2009 10:23 pm

Thanx Ron. You are too kind.

Just goes to show that the folks at Cinemar have povided us an excellent set of tools that makes just about anything possible.

Wish I had an Elk installed to see just what variables are provided.

Later
J.J. Jukebox

Member

incoronado
Newbie
Newbie
Posts: 7
Joined: Wed Apr 13, 2011 7:05 pm
Contact:

Re: Switch/Case (or equivalent) in an Automation Rule

Postby incoronado » Wed Apr 20, 2011 4:40 pm

I have just read this post because I'm trying to do just this. I think I'm going to opt to use VBS as an alternative to multiple Server Rules or a loop. Server Rule will be triggered on a change to a variable and run a MLScript with case or if Else If statements. Just seems cleaner to me. Any downside to this? Are there any implication to fast variables.


Return to “Automation Rules”

Who is online

Users browsing this forum: No registered users and 1 guest