node-red-contrib-boolean-parser
v1.4.6
Published
A Node-RED node to parse and convert several types of on/off, start/stop, true/false values.
Downloads
256
Maintainers
Readme
node-red-contrib-boolean-parser
A Node-RED node to parse, convert and format several types of on/off, start/stop, true/false values.
This packages provides an additional node in parser section. You can use it to transform properties describung boolean states. For example running or stopped (String) to 1 or 0 (int). Input values will be detected automatically.
Install
Webend
Burgermenu on the right -> Manage palette -> Tab Install -> serach for node-red-contrib-boolean-parser -> press install
CLI
Run the following command in your Node-RED user directory - typically ~/.node-red
:
npm install node-red-contrib-boolean-parser
Docker
Running node-red in an docker environment this should do the job:
Enter container:
docker exec -it <containername> /bin/bash
Inside container run the following command in your Node-RED user directory - typically /data
:
npm install node-red-contrib-boolean-parser
Usage
Think of a device stating running and stopped. You want to send string like ON or OFF in MQTT, write values like 1 and 0 to influxDB show messages status like enabled and disabled and following nodes exept boolean values in inverted logic.
To be honest nearly every type tranformation can be realized by multiple switch and change nodes or function nodes having individual code (see example below). But to keep it simple, stable and universal it is easier to have a node handling this and you don't need to blow up your flows.
Nodes can be configured like this:
For detailed description of configuration settings see below.
Input field
A field of the message, which contains the value to be parsed. Sub-properties like msg.payload.state are also valid.
Invert input
The logic can be inverted. An input detected as true
will be handled as false
and vice versa.
Default is false (no inversion).
Strict input
If a value can't be treaten as true
or false
by comparing current input value to available formats
(see [Supportet output formats][]),
- it will be handled as
null
in case of strict input is enabled - it will try to treat to
true
orfalse
automatically, case-insensitive, trimmed. Example: "foo" ->true
, "" ->false
Handle null inputs
Input values like undefined, unknown, invalid, null, NA, not-available, null
, undefined
, {}
, []
, ... will be handled as null
automatically.
If a value can't be treaten as true
or false
, (e.g. null
), it will be handled as defined by Handle null inputs:
- keep as null
- treat as true
- treat as false
- stop flow
Output field
A field of the message, which should be used for output. A existing field will be overwritten. Sub-properties like msg.payload.state are also valid.
Supportet output formats
for boolean true and false
- true / false
- "true" / "false"
- "True" / "False"
- "TRUE" / "FALSE"
- 1 / 0
- "1" / "0"
- "start" / "stop"
- "started" / "stopped"
- "enable" / "disable"
- "enabled" / "disabled"
- "activated" / "deactivated"
- "active" / "inactive"
- "running" / "stopped"
- "run" / "stop"
- "on" / "off"
- "On" / "Off"
- "ON" / "OFF"
Different outputs
There are two ways to send outgoing messages:
- A combined single output sending all messages.
- Three split outputs, sending messages, seperated by
true
,false
,undefined
.
Input formats
All input values which represent a supportet output format are detected automatically. Additionally common rules try to evaluate values to true or false. Examples:
- "foobar" -> true
- "" -> false
- 42 -> true
Output status
The last processed value is displayed as node status:
- Color: true (green), false (red) or null (grey)
- Text:
- input value
>
or!>
for inverted input- output value or
#
if flow was stopped
Examples
Input and output formatsĸ
See JSON for import.
Null handling
See [JSON](examples/Handle Null.json) for import.
Split outputs
See JSON for import.
Known Issues
Contribute
There are several ways to contribute to this project. You can report bugs or ask for new features directly on GitHub. You can also submit your own new features of bug fixes via a pull request.
And of course you can always buy me a beer, coffee, ... via the donation button: