/ioBroker.smartstate

iobroker adapter to create smart states

Primary LanguageJavaScriptMIT LicenseMIT

Logo

ioBroker.smartstate

NPM version Downloads Number of Installations Current version in stable repository

NPM

Tests: Test and Release

smartstate adapter for ioBroker

With this adapter you can create states which are calculated by other states
A good example is when you want to create a state that counts the lights that are on (see examples)
The handling is very easy. Add a new smart state, define it's name and type and add child states which will be used to calculate the states value by the given type (operator)

Getting started

Add a new smartstate by using the left + icon on the top left of the settings page.
Then you can add following parameters.

  • Smartstate settings
    Field Description
    Name The name of the smartstate
    Id The id of the smartstate
    Type Calculation type which defines how the smartstate uses the child to calculate its value
    Path The folder/path where the state should be
    Calc only for ACK values If checked, only state values which are acknowledged will trigger a recalulation
  • Child Settings
    Field Description
    Type the state type will allow a selection of one state
    the pattern type will allow a state selection pattern
    Id/Pattern the state id or the pattern
    Value function a valid javacsript code to change the value for the state before the operator/calculation type is applied eg: return !value
    The value var holds the state value

Important

  • A smartstate can use another smartstate as child state, but please be sure you do not create a recursion (State A has State B as child and State B has State A as child). Those recursions are not caught by the validation and will lead to endless loops and therfore will break the adapter or even the whole system
  • The adapter converts pattern subscription to state subscriptions, so states created in other adapters (after the smartstate adapter was started) which matches a pattern in a state child will not apply to the pattern selection. In this cas a restart of the smartstate adapter is necessary.
  • Using the state selector dialog in the child table may take a while when first opening. I am open for contributions to open a better, newer dialog

Example

Here is an example of a state that counts the lights that are on(in this case kitchen) and another one which indicates if a light in the kitchen is on. image

In the second screenshot you can see that we are using the first smartstate for generating a boolean state which will indicate if a light is on. That can be done by using the or operator image

This one shows the use of a pattern to determine if any dmx light is on image

And here we use a function to count all lights (in this case kitchen) which are off image

Those smart states settings will create following states in the object tree image

Using the "State Info Type"

A smartstate has the ability to create an extra object/state which will include the id's of the "used states" by the smartstate
The behaviour how this works differs from calulation type to calcualtion type

  • For count or and and the states which resolve as true will be filled
  • For sum and avg all the states will be filled
  • For min the state with the minimal value will be filled
  • For max the state with the maximal value will be filled
  • For equals all states which are euqal to the "first state value" in the child list will be filled

The 'State Info Type' will set if, and how the values are beeing presented

  • No info will not create the state info object
  • JSON array will create a json array of the "used states"
  • JSON object will create a json object of the "used states" where the properties reflect the state id's
  • String will create a string which is semicollon seperated

The value which is beeing stored is delivered by the State info type function and will be defaulted to the full id of the state, but the user can change this by changing this function. The function has to be a valid javascript code!
The variable params can be used and it has following properties

Field Description
id The name of the smartstate
stateObject The object of the state
deviceObject This is the object of the parent device for the state (if there is a device), otherwise it's null

The objects (stateObject, stateObjectInfo) are those you can see in the iobroker object list, e.g.: image

So for having the name inserted instead the id you can change te default function string to: image

Changelog

0.0.5 (2023-04-09)

  • (ChriD) Fixed Problem with "AVG" calculation type when using patterns

0.0.4 (2023-02-07)

  • (ChriD) Hotfix adapter crash on startup

0.0.3 (2023-02-07)

  • (ChriD) added option to create a datapoint/state which will show some combined state information values from the states which are used by the smart state
  • (ChriD) fixed multilayer path creation

0.0.2 (2023-01-29)

  • (ChriD) added ability to define a 'value function' which can be used to change the value for the state before the operator is applied

0.0.1 (2023-01-24)

  • (ChriD) initial version

License

MIT License

Copyright (c) 2023 ChriD chris_d85@hotmail.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.