Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
ezeio2:expref:start [2020-09-18 18:27] – andreh | ezeio2:expref:start [2022-11-16 23:50] (current) – [Field expressions] andreh | ||
---|---|---|---|
Line 1: | Line 1: | ||
===== Expressions ===== | ===== Expressions ===== | ||
- | {{indexmenu_n> | + | {{indexmenu_n> |
Within the configuration of an ezeio, mathematical expressions are used to produce a value/ | Within the configuration of an ezeio, mathematical expressions are used to produce a value/ | ||
Line 18: | Line 18: | ||
Enter the following in the " | Enter the following in the " | ||
- | '' | + | '' |
</ | </ | ||
Line 50: | Line 50: | ||
If left blank, the field value is not updated by the system, and will simply remain the same until changed by the user manually or by a script using the SetField function. | If left blank, the field value is not updated by the system, and will simply remain the same until changed by the user manually or by a script using the SetField function. | ||
+ | |||
+ | The most common field expression simply takes the value of a register and applies it to the field. | ||
+ | <code javascript> | ||
+ | |||
+ | A single expression can reference other fields and registers. | ||
+ | <code javascript> | ||
+ | r(1,1) * 100 - 50 // multiply the value of register 1 on device 1 with 100 and subtract 50 | ||
+ | abs(f(10)-f(12)) | ||
+ | Uptime()/ | ||
+ | </ | ||
The Data Expression is evaluated at a fixed rate of 10 times per second (100ms interval). This can be used to create counters and accumulators. | The Data Expression is evaluated at a fixed rate of 10 times per second (100ms interval). This can be used to create counters and accumulators. | ||
Line 58: | Line 68: | ||
Field #2 Data expression: | Field #2 Data expression: | ||
- | < | + | < |
Starting with the condition '' | Starting with the condition '' | ||
Line 71: | Line 81: | ||
Field #2 Data expression: | Field #2 Data expression: | ||
- | < | + | < |
We simply add 1/10th of the value of the momentary flow to our accumulator f(2). | We simply add 1/10th of the value of the momentary flow to our accumulator f(2). | ||
Line 80: | Line 90: | ||
Field #2 Data expression: | Field #2 Data expression: | ||
- | < | + | < |
Since we are looking for kW-hours, we need to divide the momentary power with 36000 (3600 seconds in an hour, and we are re-evaluating 10 times per second). | Since we are looking for kW-hours, we need to divide the momentary power with 36000 (3600 seconds in an hour, and we are re-evaluating 10 times per second). | ||
+ | |||
+ | === Example: Signal filter === | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | <code javascript> | ||
+ | |||
+ | Knowing that the expression evaluated 10 times per second, we are keeping 99% of the value, and adding 1% from the signal every 100ms. Thus the response time for this filter is about 7s for a 3dB (50%) response. | ||
+ | ==== Reverse expressions ==== | ||
+ | |||
+ | The reverse expression on the field is only relevant if the register referenced in the Data Expression is writable. | ||
+ | |||
+ | In most cases, the reverse expression can be left blank, and the ezeio will use the value from the field unchanged to write back to the register. Note also that the " | ||
+ | |||
+ | The reverse expression can be useful if there is math to scale the register value in the Data Expression. For example if we have a read & writable register with a temperature scaled x100 (so 4567 is 45.67 degrees), we would have a data expression like this: | ||
+ | < | ||
+ | Now if the user want to set the temperature, | ||
+ | < | ||
+ | The macro " | ||
+ | |||
+ | === Example: Simple control with Reverse expression === | ||
+ | |||
+ | In combination with the " | ||
+ | |||
+ | When Continuous Write is checked, the reverse expression is evaluated every 100ms (10 times per second). | ||
+ | |||
+ | Assuming the Field is tied to a relay output in the Data Expression, we can use this to implement a simple control function by using the following expression: | ||
+ | < | ||
+ | This expression will look at field #1, and if it's larger than 40, it returns 100. If 40 or less, it returns 0. The result will directly control the relay, actuating it if the value of field 1 exceeds 40. | ||