Rule Dilemma =; use of multiple "and"

Tips and Techniques for using MLServer's Automation Rules
Art Dustman
Expert
Expert
Posts: 576
Joined: Fri Nov 10, 2006 3:22 pm
Location: NJ
Contact:

Rule Dilemma =; use of multiple "and"

Postby Art Dustman » Wed Feb 11, 2015 10:30 am

What I want: Only when security_123 = 0 (It's night)
and only if it's after 4pm in the evening (currenthourmilitary >=16)
and only if I'm not home (security_127 = 0)
and upon the trigger of security_129 becoming 1 (wife arrives home)
Then turn on appropriate lights

What I get, no matter if I use security_129 (trigger) as "equals" or "becomes" is the lights turn on every hour on the hour - which is more of a while loop.


Of course I could simplify a bit and not care if it's after 4pm, however I found the lights turning on "randomly" while I'm sleeping quite annoying (no idea why that happens, but I know the home/away binaries did NOT change)
2/4/2015 12:42:53 AM Server Finished Local Images Backups
2/4/2015 2:51:19 AM Automation Event Event Triggered for Whenever security_127_present equals 1 (i was testing, so both of us were "home")
And security_129_present equals 1
And security_123_status equals 0
Then Macro|Lighting|118~on!Lighting|117~on!Lighting|112~on!Lighting|111~on!Lighting|106~on
2/4/2015 2:51:19 AM Push [0] Macro|Lighting|118~on!Lighting|117~on!Lighting|112~on!Lighting|111~on!Lighting|106~on
2/4/2015 2:51:19 AM Pop [0] Macro|Lighting|118~on!Lighting|117~on!Lighting|112~on!Lighting|111~on!Lighting|106~on
2/4/2015 2:51:19 AM MLProcess Primary [1] (1) [Macro|Lighting|118~on!Lighting|117~on!Lighting|112~on!Lighting|111~on!Lighting|106~on] from []




<b>Other than using a single trigger and running a mlconditional, is there another way to do this?</b>

2/10/2015 11:00:00 PM Automation Event Event Triggered for Whenever security_127_present equals 0
And security_129_present becomes 1
And security_123_status equals 0
And currenthourmilitary is greater than or equal 16
Then Macro|Lighting|118~on!Lighting|117~on!Lighting|112~on!Lighting|111~on!Lighting|106~on

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

Re: Rule Dilemma =; use of multiple "and"

Postby CinemarDave » Wed Feb 11, 2015 11:43 am

Put the bulk of the logic into the server command

Whenever security_129 changes value

If|IsEqual##{{security_129}}{{security_123}}{{security_127}}##100##If|IsGE@@{{currenthourmilitary}}@@16@@Turn on the appropriate lights on@@##

Art Dustman
Expert
Expert
Posts: 576
Joined: Fri Nov 10, 2006 3:22 pm
Location: NJ
Contact:

Re: Rule Dilemma =; use of multiple "and"

Postby Art Dustman » Wed Feb 11, 2015 3:44 pm

Wait, I can evaluate three variables simultaneously?
How does it know the difference between 100 and 1,0,0 ?

If|IsEqual##{{security_129}}{{security_123}}{{security_127}}##100##If|IsGE@@{{currenthourmilitary}}@@16@@Turn on the appropriate lights on@@##

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

Re: Rule Dilemma =; use of multiple "and"

Postby CinemarDave » Wed Feb 11, 2015 3:55 pm

Yes all you are doing in concatenating the three server variables into one string and then evaluating the resultant string. Since all three variables are either 0 or 1 there is only one condition where they will equal 100.

mzn
New Member
New Member
Posts: 49
Joined: Wed Dec 25, 2013 7:40 pm
Contact:

Re: Rule Dilemma =; use of multiple "and"

Postby mzn » Thu May 07, 2015 8:57 am

I would like to build-in a human presence detection system using my motion detectors on my alarm system. Say I have 10 motion detectors and would like to turn off the lights via a Macro if NONE of the 10 detectors are activate for a set period of time, e.g. 10 min.
How would I then do the following:
Whenever Security_Zone_100 changes OR Security_Zone_101 changes OR Security_Zone_102 changes . . . . . (for all 10 zones), reset timer to 0, else Macro|Turn off all the lights.
I know I can write 10 separate Automation events for each zone, but is there a more effiient method to do this?
From a logic standpoint, AND can be coded by concatenating the variables (If zone1 AND zone2 = OffOff, then . . .), but for OR I can only think of writing the Automation event multiple times, which gets very messy since there no commenting of the Rules is possible, and renumbering the Automation Rules to try to group them is also not possible (at least to my knowledge).
Thanks.

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

Re: Rule Dilemma =; use of multiple "and"

Postby CinemarDave » Thu May 07, 2015 11:04 am

Assuming that the 10 room sensors have values of 1 meaning occupied and 0 meaning unoccupied then I see it like

For each of the 10 sensors there is an automation rule
Whenever {{security_zone_100_state}} changes value
call system macro SetSensor|1~{{security_zone_100_state}} <== change the parameter for each of the sensors. the first parameter is the sensor # and the 2nd its value

The system macro SetSensor is
Macro|
?|If the zone becomes occupied then reset the variable holding the last occupied time!!
if|IsEqual##<P2>##1##SetVariable|OccupiedTime~{{currentdaysecs}}##!!

?|The variables z1 to z10 will hold the current state!!
SetVariable|z<P1>~<P2>!!

?|see if we are unoccupied and for at least 10 minutes!!
If|IsEqual##{{z1}}{{z2}}{{z3}}{{z4}}{{z5}}{{z6}}{{z7}}{{z8}}{{z9}}{{z10}}##0000000000##
Macro|
Math|Subtract|delta~{{currentdaysecs}}~{{occupiedtime}}!
If|IsGE@@{{delta}}@@600@@Turn Off The Lights@@
##

This should logically be close. Some additional logic would have to be implemented if midnight crossings are a concern.


Return to “Automation Rules”

Who is online

Users browsing this forum: No registered users and 1 guest