ioBroker / ioBroker.text2command

Convert text into commands
MIT License
29 stars 16 forks source link
iobroker parser smarthome text-parser

Logo

ioBroker.text2command

Number of Installations Number of Installations NPM version Downloads Tests

NPM

Description

This adapter can convert normal sentences, like Switch light in kitchen on to specific command and sets the state adapter.0.device.kitchenLight to true.

This adapter makes no sense to be activated standalone. It should be used with other adapters like telegram or Android app iobroker.vis.

Usage

To execute command, write state text2command.<INSTANCE>.text with sentence. You will always get the answer in text2command.<INSTANCE>.response.

If you define Answer to ID, the answer will be written in this ID too. This is required for e.g. to realise the voice acknowledges.

You can send a message via sendTo from javascript. The answer will come in the message back:

sendTo('text2command', 'Switch light in kitchen on', function (err, response) {
    console.log('Response is: ' + response);
});

Regular expressions can be used, like: /^light\son|^lamp\son/. Regular expressions are always case-insensitive.

To use "Switch on/off by function" you should care of functions.

Keywords work as following:

Following functions will be interpreted as

enum.functions:

enum.functions.light (Licht | Свет):

enum.functions.backlight (Beleuchtung | Подсветка):

enum.functions.blinds/shutter (Rollladen | Жалюзи/окна)

enum.functions.curtain (Vorhänge | Шторы)

enum.functions.heating (Heizung | Отопление/Подогрев)

enum.functions.music (Musik | Музыка)

enum.functions.alarm/security (Alarmanlage / Alarm | Охрана)

enum.functions.lock (Schloß / Schloss | Замок)

Following rooms are supported:

key word in phrase Possible enum.rooms in english in german in russian
everywhere everywhere - -
living livingroom wohnzimmer зал
bedroom bedroom/sleepingroom schlafzimmer спальня
bath bathroom/bath badezimmer/bad ванная
working/office office arbeitszimmer кабинет
kids/child/nursery nursery kinderzimmer детская
guets wc/guest closet guestwc gästewc гостевой туалет
wc/closet wc wc туалет
floor/enter floor diele/gang/flur коридор/прихожая
kitchen kitchen küche/kueche кухня
balcony/terrace/patio terrace balkon/terrasse терраса/балкон
dinning dinningroom esszimmer столовая
garage garage garage гараж
stair stairs trepe/treppenhaus лестница
garden garden garten сад
court/yard court hof двор
guest room guestroom gästezimmer гостевая
attic attic speicher кладовка
roof roof dachstuhl крыша
terminal terminal anschlussraum сени
wash room washroom waschraum прачечная
heat room heatroom heatingroom/heizungsraum котельная
hovel hovel schuppen/scheune сарай
summer house summerhouse gartenhaus теплица

You can use patterns in acknowledgements:

The following commands are supported:

What time is it?

Answer: 14:56 (current time)

What is your name?

Answer is customizable. Default: My name is Alpha

What is the outside temperature?

User must specify the state ID, where to read outside temperature. The answer is customizable. Default: Outside temperature is %s %u %s will be replaced by temperature, rounded to integer. %u will be replaced by units of this state or by system temperature units.

What is the inside temperature?

User must specify the state ID, where to read inside temperature. The answer is customizable. Default: Inside temperature is %s %u %s will be replaced by temperature, rounded to integer. %u will be replaced by units of this state or by system temperature units.

Switch on/off by function

This command reads information from enums. It uses enum.functions to find type of device (e.g., light, alarm, music) and enum.rooms to detect room name.

Example in german: Enums

Keywords to switch on are: switch on, e.g. switch rear light in bath on

Keywords to switch off are: switch off, e.g. switch light in living room off

Answer will be generated automatically if desired: Switch off %function% in %room%, where %function% and %room% will be replaced by found device type and location.

Command accepts the numeric value too. It has priority, e.g. in command switch light off in living room on 15% the light will be set to 15% and not in off state.

You can define default room in []. E.g. switch the light on[sleepingroom]

Open/close blinds

This command reads information from enums. It uses enum.functions.blind to find type blinds or shutter and enum.rooms to detect room name.

Keywords to move blinds up are: blinds up, e.g. set blinds up in sleeping room

Keywords to move blinds down are: blinds down, e.g. move blinds down in office

You can specify the exact position of blind in percent, e.g. move blinds to 40 percent in office

Answer will be generated automatically if desired: in %room%, where %room% will be replaced by found device type and location.

Switch something on/off

User must specify state ID of a device, which must be controlled and value, which must be written.

You should create rule for every position (e.g., for on and for off).

Answer is customizable. Default: Switched on

E.g.:

Deactivate must be first in the list, because it is longer.

You can use float values in the control commands. If some numeric value is in the text, it will be used as a control value and the predefined value will be ignored.

E.G. for rule:

If command is like Set light level to 50%, so into the hm-rpc.0.light.STATE will be written 50 and answer will be Level set to 50%.

If command is like Set light level, so into the hm-rpc.0.light.STATE will be written 10 and answer will be Level set to 10%.

Ask about something

User must specify state ID of a device, which value will be read. This template will answer with information from some state.

E.g.:

Send text to state

You can write some text into state. User must specify state ID to write text into it.

E.g. rule: email [to] wife, Object ID: javascript.0.emailToWife, Acknowledge: Email sent Text: Send email to my wife: I will be late. Adapter looks for the last word from keywords (in this case wife), extracts text from the next word (in this case I will be late) and writes this text into javascript.0.emailToWife. Word to is not required to trigger the rule, but will be removed from a text.

You are good (Just for fun)

The answer is customizable. Default: Thank you or You are welcome

Thank you (Just for fun)

The answer is customizable. Default: No problem or You are welcome

Create answer

You can generate answer with bindings {objectId} in acknowledgement. Used for alexa.

E.g.:

You can read more about bindings here: (Bindings of objects)[https://github.com/ioBroker/ioBroker.vis#bindings-of-objects]

Additionally, you can get time until now by {hm-rpc.0.light.STATE.lc;dateinterval} (2 minutes and 12 seconds) or {hm-rpc.0.light.STATE.lc;dateinterval(true)} (2 minutes and 12 seconds ago)

External rules with javascript

There is a possibility to use javascript engine to process commands in text2command. To do that, you must specify some state in "Processor state ID" (Advanced settings) and to listen to this state in some JS or Blockly script. You can create some state manually in admin or in script. Processing script can look like this one:

createState("textProcessor", '', function () {
    // text2command writes the value with ack=false. Change "any" is important too, to process repeated commands.
    on({id: "javascript.0.textProcessor", ack: false, change: 'any'}, function (obj) {
         var task = JSON.parse(obj.state.val);
         // value looks like
         // {
         //     "command":      "text to process", // command that was received by text2command
         //     "language":     "en",              // language in command or system language
         //     "withLanguage": false              // indicator if language was defined in command (true) or used default language (false)
         // }
         // response to text2command with ack=true
         if (task.command === 'switch light on') {
            setState("hm-rpc.0.light", true);
            setState("javascript.0.textProcessor", 'light is on', true);
         } else {
            // let it process with predefined rules
            setState("javascript.0.textProcessor", '', true);
         }
    });
});

Set in settings of text2command Processor state ID as javascript.0.textProcessor to let this example work.

The first, the command will be processed with your javascript, and if javascript answers with '' or not answer in predefined time (1 second by default) the command will be processed by rules.

Option: Write to response by every command

If activated so by every command (no matter if the request came via state or sendTo) the text2command.X.response will be written with the answer.

ToDo

Changelog

3.0.3 (2023-12-18)

3.0.2 (2023-02-27)

3.0.1 (2023-02-21)

2.3.1 (2023-02-03)

2.2.2 (2022-06-17)

2.2.1 (2022-02-21)

2.1.6 (2022-02-16)

2.1.4 (2022-02-16)

2.1.2 (2022-02-13)

2.1.1 (2021-06-15)

2.1.0 (2021-05-24)

2.0.7 (2020-12-12)

2.0.6 (2020-12-03)

2.0.5 (2020-09-5)

2.0.3 (2020-07-14)

2.0.2 (2020-07-13)

2.0.1 (2020-07-08)

2.0.0 (2020-07-06)

1.3.1 (2019-07-18)

1.3.0 (2019-07-18)

1.2.5 (2019-02-12)

1.2.4 (2018-05-05)

1.2.3 (2018-05-01)

1.2.0 (2018-04-23)

1.1.7 (2018-04-04)

1.1.6 (2017-10-05)

1.1.5 (2017-08-14)

1.1.4 (2017-03-27)

1.1.3 (2016-08-30)

1.1.2 (2016-08-29)

1.1.1 (2016-08-19)

1.1.0 (2016-08-16)

1.0.2 (2016-07-22)

1.0.1 (2016-06-01)

1.0.0 (2016-05-05)

0.1.10 (2016-03-20)

0.1.9 (2016-03-20)

0.1.8 (2016-03-15)

0.1.7 (2016-03-12)

0.1.6 (2016-02-24)

0.1.5 (2016-02-23)

0.1.4 (2016-02-22)

0.1.3 (2016-02-21)

0.1.2 (2016-02-21)

0.1.1 (2016-02-19)

0.1.0 (2016-02-19)

0.0.3 (2016-02-14)

0.0.2 (2016-02-10)

0.0.1 (2016-02-09)

License

The MIT License (MIT)

Copyright (c) 2014-2023, bluefox dogafox@gmail.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.