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)
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
thepattern
type will allow a state selection patternId/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
Thevalue
var holds the state value
- A smartstate can use another smartstate as child state, but please be sure you do not create a recursion (
State A
hasState B
as child andState B
hasState 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
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.
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
This one shows the use of a pattern to determine if any dmx light is on
And here we use a function to count all lights (in this case kitchen) which are off
Those smart states settings will create following states in the object tree
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
andand
the states which resolve astrue
will be filled - For
sum
andavg
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 objectJSON 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'sString
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.:
So for having the name inserted instead the id you can change te default function string to:
- (ChriD) Fixed Problem with "AVG" calculation type when using patterns
- (ChriD) Hotfix adapter crash on startup
- (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
- (ChriD) added ability to define a 'value function' which can be used to change the value for the state before the operator is applied
- (ChriD) initial version
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.