Templates can do math
Posted: Wed Mar 25, 2015 9:20 am
The template replacement mechanism in Meteobridge is widely used to send documents with weather data include via email, twitter, ftp, http and so on. Up to now templates could make use of a defined set of variables only, which are replaced by values the moment the template is evaluated and transported by one of the channels mentioned above.
Todays update does also allow to do some math with numerical values inside the template. The math has the same syntax as known from the alarm conditions. The expression to evaluate inside a template is started by {* and ends with *}. As an example, when you want to insert the current wind speed multiplied by 10 in a template, simply say {* [wind0wind-act:0] * 10 *}. The ":0" ending of the variable indicates that "0" should be returned in case the sensor did not show any data. This is done to prevent the computation from breaking because of using non-numerical values. The result will be returned with two decimals. When you want to change number of decimals, you can change the ending of the expression to *0}, which sets number of decimals to zero, which results to a rounded integer.
I think using this is fairly straight forward and does give you additional options. I don't think that these changes break anything. However, when you experience unexpected behavior in your templates, please post into this thread. At the moment there is no debugging of expression evaluation. May be we can add this in the future.
Please find more details here: http://meteobridge.com/wiki/index.php/T ... xpressions
Todays update does also allow to do some math with numerical values inside the template. The math has the same syntax as known from the alarm conditions. The expression to evaluate inside a template is started by {* and ends with *}. As an example, when you want to insert the current wind speed multiplied by 10 in a template, simply say {* [wind0wind-act:0] * 10 *}. The ":0" ending of the variable indicates that "0" should be returned in case the sensor did not show any data. This is done to prevent the computation from breaking because of using non-numerical values. The result will be returned with two decimals. When you want to change number of decimals, you can change the ending of the expression to *0}, which sets number of decimals to zero, which results to a rounded integer.
I think using this is fairly straight forward and does give you additional options. I don't think that these changes break anything. However, when you experience unexpected behavior in your templates, please post into this thread. At the moment there is no debugging of expression evaluation. May be we can add this in the future.
Please find more details here: http://meteobridge.com/wiki/index.php/T ... xpressions