Using Counters

counters-sq

Counters are memory locations (often called flags) that can be set, incremented, decremented, or compared by an automation rule to track an event or keep up with how many times an event has occurred.  There are a total of 64 counters.  Each can be programmed with a 12 character description, making it easy to reference in an automation rule.  This article will illustrate some practical applications in which counters can be used.

Reminder that a door has been left open

Counters can be set to an initial value and then incremented or decremented.  Then, a particular action can be activated when the counter reaches a certain value.  In this example, if the back door is left open for more than 30 seconds, the M1 will announce a reminder message.  When the door is opened, a counter is set to a value of 30, as shown in the rule below.

WHENEVER Back Door (Zn 1) BECOMES NOT SECURE
THEN SET Close Door (Counter 1) TO 30

For every second that the back door is open, the counter will be decremented by 1.

WHENEVER EVERY 1 SECONDS
AND Back Door (Zn 1) IS NOT SECURE
THEN SUBTRACT 1 FROM Close Door (Counter 1)

If the counter ever reaches a value of 0 (meaning the door has been left open for 30 seconds), the M1 will announce “The back door is open” which has been programmed as Miscellaneous 1 (vm239).  Also, the counter is set back to a value of 30.  This will allow the system to announce the message again if the back door continues to be left open.  The message will repeat every 30 seconds until the back door is closed.

WHENEVER Close Door (Counter 1) CHANGES TO 0
THEN ANNOUNCE Miscellaneous 1 (vm 239)
THEN SET Close Door (Counter 1) TO 30

Activate/Deactivate Sequence

Counters can be toggled between 0 and 1, providing an on/off or true/false ‘flag’.  In this example, on Monday through Friday, when it is time to wake up in the morning, the M1 turns the lights on, and announces the outside temperature.  There may be times when you would like to temporarily deactivate this automatic sequence.  Using an F key and a counter, we can activate and deactivate the morning sequence.

The rule below toggles the counter when the F key is pressed.

WHENEVER F5 KEY ON ANY KEYPAD ACTIVATES
THEN TOGGLE Morning (Counter 2) BETWEEN 0 AND 1

This rule turns on the lights and announces the outside temperature at 7:00am on Monday through Friday, but only if counter 2 is equal to zero.

WHENEVER THE TIME IS 7:00AM
AND THE DAY(S) OF THE WEEK IS/ARE –MTWTF-
AND Morning (Counter 2) IS EQUAL TO 0
THEN TURN Bedroom Lights [1(A1)] ON
THEN ANNOUNCE TEMPERATURE READING OF Outside (Zn 16)

If the counter is not equal to zero, the system could do nothing, or a different sequence could be activated by writing a rule or set of rules that activate when the counter is equal to one.

Display the Day’s High Temperature

Counters can be used to remember a number that can then be used for a comparison, and/or displayed on the keypad.  In this example, a counter will be used to remember the day’s high temperature which is then displayed on the keypad.

The following rule will compare the current temperature of the outdoor temperature sensor to the “High” counter every 5 minutes.  If the current temperature is higher than the counter’s value then the counter will be set to the current temperature and the new high will be displayed on the keypad.

WHENEVER EVERY 5 MINUTES
AND Outdoor Temp (Zn16) ACTUAL TEMPERATURE IS GREATER THAN High (Counter 3)
THEN SET High (Counter 3) TO TEMPERATURE OF Outdoor Temp (Zn 16)
THEN DISPLAY “High = |%CTR3%|” IN Area 1 (Area 1) INDEFINITELY, (*) CLEARS

A text string is required to display the “High” counter value on the keypad.  To do this click on text, under Automation in ElkRP.  Here you will be able to type a text message. In this example, “High =” is typed manually.  Then, the “Insert” drop down boxes are used to enter the counter value.  In the first drop down box select “Counter Value”.  In the second drop down box choose the counter you wish to display (Counter 3 in this example).  The text message will be available when “Send Text to Keypad” is selected from the THEN menu in the rules.

The rule below will reset the counter to 0 at midnight .

WHENEVER THE TIME IS 12:00 AM
THEN SET High (Counter 3) TO 0

The day’s low temperature could be displayed by comparing the temperature to a different counter and setting the counter to the current temperature if it is less than the counter value.  The “Low” counter should be reset to a high value (like 200) at noon.

Temperature Comparison

This example turn on an attic fan when the attic temperature is 10° hotter than the outside temperature.  At the desired interval, a counter is set to the value of the outside temperature sensor.  Two seconds later (delay created by a phantom output) a value of 10 is added to the counter value.  After another 2 second delay, the attic temperature is compared to the counter value (outside temperature + 10).  If the attic temperature is greater than the counter value, the attic fan is turned on for the desired length of time.

WHENEVER EVERY 2 MINS
THEN SET Temp (Counter 4) TO TEMPERATURE OF Outside (Zn 10)
THEN TURN OUTPUT 200 ON FOR 2 SECS

WHENEVER OUTPUT 200 STATE IS TURNED OFF
THEN ADD 10 TO Temp (Counter 4)
THEN TURN OUTPUT 201 ON FOR 2 SECS

WHENEVER OUTPUT 201 STATE IS TURNED OFF
AND Attic (Zn 11) ACTUAL TEMPERATURE IS GREATER THAN Temp (Counter 4)
THEN TURN Attic Fan (Out 3) ON FOR 10 MINS

Scroll to Top