An AlphaMon Expression is an instruction that tells your AlphaMon how to read and control external devices. Think of it as a “rule” that AlphaMon constantly evaluates, up to 20 times a second, to keep your system running in perfect balance.
When the AlphaMon is used in Renewable Energy systems the Expressions that you write control your battery, inverter and external loads to ensure stability. least cost and efficiency in a process often referred to as “Demand Management“. Demand Management basically means keeping your energy generation from solar panels, batteries and/or other sources in balance with the electrical loads places on the system to ensure there are no blackouts or brown-outs (a less severe forms of a blackout).
1. The Anatomy of an Expression
The general form of an AlphaMon expression has three parts, as follows:
Target = Logic
- The Target (LHS): Located on the Left-Hand Side of the equals sign (=). This is a reference to an update-able or writable device or variable you want to change (e.g., a Relay or a Generator Start signal).
- The Assignment Operator (=): The equals sign, or alternatively “EQ”, is the Assignment Operator. It tells your AlphaMon: “Take the result from the RHS and apply it to the device or register on the LHS of the expression.”
- The Logic (RHS): Located on the Right-Hand Side. This is the calculation or “IF” statement that determines the result.
However, sometimes you may only want to only display the result of an expression rather than switching something on or off. You can do that by drafting only the RHS of the expression, thus completely omitting the LHS and the Assignment Operator. This causes the AlphaMon to periodically display the calculated result of your expression in the log and also on the OLED display. For example, to monitor the grid voltage, without actually doing anything, you could write an expression such as DDS6619:Volts, where DDS6619 is a reference to an external, Modbus-enabled smart meter which has been configured to monitor power drawn from or exported to the grid.
2. Standard Syntax Rules
To ensure the AlphaMon Syntax Checker (SC) accepts your expression, follow these simple rules:
- Case Doesn’t Matter:
BATTSOC,battsoc, andBattSocare all seen as the same word or reference. - Use Aliases for speed and clarity: An AlphaMon Alias is a user-friendly reference to a device or sensor connected to your system. You can read more about Aliases here.
- Spaces are Flexible: You can write
TEMP>20or TEMP > 20. AlphaMon ignores extra spaces. - The “One-Way” Rule: When you draft an Assignment Expression you can only put a Writable Aliases on the Left-Hand Side (LHS) of your expression syntax. For example, you can’t “assign” a value to a sensor with an expression such as VOLTS = 240, because will cause a syntax error. That’s because the Alias “VOLTS” can only ever represent a measurement and never the result or output of your expression.
- Comments: You can use double forward slashes “
//"to add notes to yourself. AlphaMon ignores everything after the slashes.Example: GEN_START = ON // Manual override for testing
3. Understanding Logic Results (True vs. False)
AlphaMon is designed to be user-friendly. When you write an Expression to control a switch or a relay, AlphaMon automatically translates your various words into a simple binary/boolean On (1) and Off (0) values:
- To turn something ON: You can use
ON, YES, TRUE,HIGH,or 1, interchangeably. - To turn something OFF: You can use OFF, NO, FALSE, LOW, or 0, to best suit your intended context.
4. Using Parentheses (The Order of Operations)
AlphaMon follows standard math rules (it multiplies before it adds). To make sure your logic is processed in the right order, use parentheses ( ). You can read more about Functions, Operators And Precedence here.
- Unclear: TEMP + 10 * 2 (This Expression multiplies 10 by 2 first, and only then adds the Temp).
- Clear: (TEMP + 10) * 2 (This Expression adds 10 to the Temp first, then multiplies the whole thing by 2).
Rule of Thumb: If your expression has more than one operator, use parentheses to be safe!
5. Combining Multiple Conditions
You can make complex decisions by using AND and OR operators.
- AND: Both parts must be true. Example:
(TEMP > 30 AND BATTSOC < 20) - OR: Only one part needs to be true. Example: (MANUAL_SWITCH == ON OR AUTO_TRIGGER == ON)
Important Note: The “==” operator means “is the LHS equal to the RHS?”. It does NOT mean “set the LHS equal to the RHS”. To avoid confusion you may prefer to use the “EQ” operator which means the same thing as “==“. For example: MANUAL_SWITCH EQ ON. See here for a full list of Operators and Functions.
Pro-Tip: The “Syntax Error” Message
If you write an expression that AlphaMon doesn’t understand, it will tell you in the Boot Log. For example, the error message might say “LHS Target is R/O,” which means you tried to “write” to a “read-only” sensor. Always check your logs after adding or modifying an expression!