ImperiHome comes with a Unit Configuration module available in the configuration contextual menu of sensors (temperature, wind, hydrometry, electricity ...).
This module allows you to set two optional properties that can be configured independently one from the other:
- A formula that will be applied on the value received from the system.
- The unit that will be displayed right after the value.
While the unit is only plain text that will be displayed as is, the formula is an expression that will be evaluated by the system and thus has to respect a syntax.
This feature relies on exp4j which allows following operators and supports parenthesis:
- Addition: +
- Subtraction: -
- Multiplication: *
- Division: /
- Exponentiation: ^
- Modulo: %
- absolute value: abs
- arc cosine: acos
- arc sine: asin
- arc tangent: atan
- cubic root: cbrt
- nearest upper integer: ceil
- cosine: cos
- hyperbolic cosine: cosh
- euler's number raised to the power (e^x): exp
- nearest lower integer: floor
- logarithmus naturalis (base e): log
- sine: sin
- hyperbolic sine: sinh
- square root: sqrt
- tangent: tan
- hyperbolic tangent: tanh
To use the raw value retrieved from the system inside the formula, the keyword val must be used.
- Celsius to Fahrenheit formula: ((val * 9) / 5) + 32
Once a formula defined, it will be used each time the value from this sensor needs to be displayed (list view, dashboard view, graph ...)
If the formula is erroneous, it won't be recorded and a toast message will be displayed to inform you.
If the retrieved value from the system is not a double (a string for instance for custom sensor), and if a formula has been defined, ImperiHome will first try to convert the value to a double. If it fails, then the raw value will be used.
You can always erase a formula and retrieved default unit by pressing the "Reset" button in the dialog box.