Howto setup Pimatic and Homeduino
String Expressions and String Functions for Variables & Rules

This “how to” article is to give some insights on using String Expressions and Functions with pimatic variable and rule definitions. For now, only the subString and date functions are covered. More content for other functions will be added soon.

String Expressions

String Expression can be used for variables of type “Expression” and as parameters for some rule predicates and actions.
String Expressions may be one of the following:

variable references, e.g., $someVar plain string, e.g., "ABC" function calls, e.g., subString($someVar, "BB") string with embedded expressions, "AA$someVar"

In some cases it is required to surround an embedded expression with curly brackets to get parsed properly, e.g. "{$someVar}BB". This way, it is also possible to embed function calls, e.g., "AA{subString($someText, "BB")}"

The subString function

subString(<string expression>, <regular expression>[, <flags>])

This function returns the substring of a given string expression matching the regular expression and flags where the latter may be provided optionally. The function uses Javascript regular expressions which are provided without the surrounding slashes and flags. Simply provide the regular expression as a string, e.g., "\D+". The flags may be optionally provided as a separate string.

Note, some special characters of regular expressions need to be escaped with a preceding backslash. Otherwise, they would be interpreted as pimatic special characters for string expressions or variable references. Use:

\{ and \} instead of { and } to specify occurrences of the preceding sub expression \$ instead of $ to end of the string expression

In the following, some usage examples are provided which use a global variable $someVar set to the value "AABBCCC". If you wish to trial the example, define another global variable, e.g. $subText and set its type to “Expression”

subString($someVar, "BB") results in BB. It matches the first occurrence of the letter sequence BB in $someVar

subString($someVar, "B\{2\}") results in BB and is equivalent to expression above. Note, the curly braces need to be quoted with a backslash as the brace would be interpreted as an embedded pimatic expression otherwise

subString($someVar, "[A-Z]\{5\}") results in AABBC. Returns the first occurrence of five characters where each character is contained in the set “A to Z”

subString($someVar, "c", "gi") results in CCC. It concatenates all occurrences (flag g for global matching) of the letter c or C (flag i for case insensitive)

subString($someVar, "A|B", "g") results in AABB. It concatenates all occurrences (flag g for global matching) of the letters A or B

subString($someVar, ".\$") results in C. It matches the last character of $someVar. Note the dollar sign needs to be quoted with a backslash as the dollar sign would be interpreted variable reference start symbol, otherwise

Function calls can also be embedded into a string. To get it parsed properly the function is surrounded by brackets: "XX{subString($someVar, "..(..)")}" results in XXBB

It is also possible to nest function calls: subString(subString($someVar, "A|B", "g"), ".\$") results in B. The inner function yields all caracters A or B, i.e., AABB. The outer function yields the last character.

The following gives an example of using the function as part of a rule definition:

WHEN subString("$someVar", "A", "g") equals "AA" THEN toggle denon-avr-power The date function

date([<format string>])

Outputs the current date using an optionally provided format string. If no format string is provided the format "YYYY-MM-DD hh:mm:ss" is used.
For the date formatting the date-format-lite package is used. See supported syntax below.

Y - A two digit representation of a year without leading zeros. Examples: 99 or 3 YY - A two digit representation of a year. Examples: 99 or 03 YYYY - A full numeric representation of a year, 4 digits. Examples: 1999 or 2003 M - Numeric representation of a month, without leading zeros. 1 through 12 MM - Numeric representation of a month, with leading zeros. 01 through 12 MMM - A short textual representation of a month, three letters. Jan through Dec MMMM - A full textual representation of a month, such as January or March. January through December D - Day of the month without leading zeros. 1 to 31 DD - Day of the month, 2 digits with leading zeros. 01 to 31 DDD - A textual representation of a day, three letters. Mon through Sun DDDD - A full textual representation of the day of the week. Sunday through Saturday H - 12-hour format of an hour without leading zeros. 1 through 12 HH - 12-hour format of an hour with leading zeros. 01 through 12 h - 24-hour format of an hour without leading zeros. 0 through 23 hh - 24-hour format of an hour with leading zeros. 00 through 23 m - Minutes without leading zeros. 0 through 59 mm - Minutes with leading zeros. 00 to 59 s - Seconds without leading zeros. 0 through 59 ss - Seconds with leading zeros. 00 to 59 S - Milliseconds without leading zeros. 0 through 999 SS - Milliseconds with leading zeros. 000 to 999 u - Milliseconds since the Unix Epoch (January 1 1970 00:00:00 GMT) U - Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT) A - Ante meridiem and Post meridiem. AM or PM "text" - text, quotes should be escaped, eg ‘“a \“quoted text\”” YYYY’ Time zone designators Z - Time offsets from UTC in the form ±hh[:mm] Examples: +02, +02:30 ZZ - Time offsets from UTC in the form ±hh[mm] Examples: +02, +0230 ZZZ - Time offsets from UTC in the form ±hh:mm Examples: +02:00, +02:30 ZZZZ - Time offsets from UTC in the form ±hhmm Examples: +0200, +0230 ISO-8601 w - Day of the week. 1 (for Monday) through 7 (for Sunday) W - Week number of year, first week is the week with 4 January in it o - ISO-8601 year number. This has the same value as YYYY,
except that if the ISO week number (W) belongs to the previous or next year, that year is used instead

read more
Howto setup specific hardware or devices
Update notification and changelog for pimatic and homeduino

for the homeduino version request and comparison you need to change the following things (already did above!!)

shellsensor in part #3

{ "id": "homeduino-version-git", "name": "homeduino Version Request", "class": "ShellSensor", "attributeName": "versionrequest", "attributeType": "string", "command": "curl -s https://github.com/pimatic/pimatic-homeduino/blob/v0.9.x/package.json | grep version | grep span | awk -F\\> {'print $11'} | awk -F\\< {'print $1'}\n", "interval": 21600000 }

and the rule in part #8

{ "id": "homeduino-changelog-request", "name": "homeduino changelog request", "rule": "if $homeduino-version-git.versionrequest gets updated then execute \"sudo github-changes -o pimatic -r pimatic-homeduino -b v0.9.x -f /home/pi/CHANGELOG-HOMEDUINO.md && head -23 /home/pi/CHANGELOG-HOMEDUINO.md | tail -20 | awk '-F)' \\{'print \\$2'\\} | sed 's/(//g' > /home/pi/homeduino-changelog.log\"", "active": true, "logging": true }

read more

Looks like your connection to pimatic forum was lost, please wait while we try to reconnect.