Skip to content

BLL Text Recipes

Arie J. Godschalk edited this page Nov 15, 2026 · 4 revisions

Text, messages and matching

Examples · Custom functions · Math.js and Lodash

These examples use JavaScript strings and Lodash inside BLL, not additional BLL-specific methods. Bare expressions belong in Execute BLL-expression (as Tag) or the BLL expression condition. Use {[ ... ]} only when embedding an expression in supported text.

The examples use fixed input so you can test them before inserting Homey tags. Adapted examples are identified below; follow the linked posts for the original Flows and discussion.

Combine text and numeric tags without writing code

A forum discussion about combining two temperatures clarifies the difference between the two tag-producing cards:

  • Execute Text (as Tag) accepts normal text and inserted tags. Enter the first numeric tag, a separator such as to, and the second tag. You do not need JavaScript quotes, concatenation or an expression.
  • Execute BLL-expression (as Tag) evaluates JavaScript. For fixed sample input, 48 + " to " + 52 returns 48 to 52.

Use the text card for simple messages. Use the expression card when you actually need to calculate or transform something.

BLL Execute Text as Tag card from the community explanation

Community screenshot: ordinary text and inserted Flow tokens are combined in the text result.

Pick a random greeting

This Dutch forum solution uses Lodash's _.sample to choose a bedtime message. An English adaptation is:

_.sample(["Good night!", "Sweet dreams!", "Sleep well!"])

Use Execute BLL-expression (as Tag) and pass the text result to a notification action. Alternatively, the variable-setting expression card can save the selection for later use.

Community Flow choosing a random bedtime message with BLL

Community Flow screenshot: a Lodash sample expression selects a greeting before the notification action.

Each evaluation makes a new selection; repeats are possible. Evaluate once and reuse the result tag if several actions should use the same message. Keep the candidate list non-empty.

Check whether text contains a word or phrase

The contains discussion gives this exact Lodash example:

_.includes("abcd", "bc")

It returns true. These related adaptations can be used in a BLL condition:

Expression Result
"Garden door open".indexOf("door") > -1 true
_.includes("Garden door open", "window") false
_.includes("Garden door open".toLowerCase(), "GARDEN".toLowerCase()) true
!_.includes("Kitchen ready", "Away") && !_.includes("Kitchen ready", "Asleep") true

Matching is case-sensitive unless you normalize both inputs. These are substring tests, not whole-word searches: door also matches outdoor. Do not use "text".contains(...); it is not a standard JavaScript string method. The working forum alternatives are indexOf and _.includes.

Extract a person's first name

In this solved name-extraction example, Homey's person-name tag contains a full name. The expression uses substring and indexOf to extract everything before the first space. With fixed sample input:

"Alex Smith".substring(0, "Alex Smith".indexOf(" "))

This returns Alex, but returns an empty string if no space exists. An adaptation that also handles a single name, leading spaces and repeated whitespace is:

"  Alex   Smith  ".trim().split(/\s+/)[0]

It returns Alex. This takes the first word, not necessarily a person's complete given name.

When adapting the original expression, insert the actual name tag, not its visible label. The forum fix included quoting the inserted text and removing $value, which is not an ordinary expression-card parameter. Text containing quotes or backslashes needs escaping; use controlled input or a JSON-capable workflow rather than inserting arbitrary text into JavaScript source.

Split a pipe-separated message into fields

The resolved JSON Handler discussion splits a message at | and returns named arrays. Save this as a custom function named splitPipe:

(function (s) {
  const parts = s.split("|");
  return { words: parts, splits: [parts[0], parts[1]] };
})

Then evaluate:

JSON.stringify(splitPipe("Kitchen|21.5"))

The result is:

{"words":["Kitchen","21.5"],"splits":["Kitchen","21.5"]}

Select words[0] and words[1], or splits[0] and splits[1], in a compatible JSON reader. The follow-up post explains that either structure works; the selected paths must match what the function actually returns. Both values are text. Validate the number of fields and convert a value explicitly if a later calculation requires a number.

Reuse a central message-formatting Flow

In this shared message-formatting technique, several Flows send text containing BLL coding to one central Flow, which processes it using BLL's text-setting card.

For example, the trusted template:

Report at {[ date("HH:mm") ]}: temperature {[ number(21.45, 1) ]}

can be decoded once in that central Flow and then sent as a notification. This sample template is an adaptation, not the exact text from the post. It can keep formatting in one place instead of adding formatting cards to every caller.

Pass the message as a Flow argument where your workflow supports that. A single shared text variable can be overwritten by overlapping Flow runs. Only decode templates you control: BLL coding is executable JavaScript, not an escaping mechanism for untrusted messages.

Clone this wiki locally