This is not the adapter. This is a help function to detect devices from ioBroker states and channels.
You can find the description of devices in DEVICES.md.
Test website to test the detection of devices.
You can use this module in Browser and in Node.js projects.
Just now this module is used in material adapter to detect devices and to visualize them.
The following code detects devices in some state's tree:
import ChannelDetector, { type DetectOptions, type Types } from '@iobroker/type-detector';
const detector: ChannelDetector = new ChannelDetector();
const keys = Object.keys(objects); // For optimization
const usedIds: string[] = []; // To not allow using of same ID in more than one device
const ignoreIndicators: string[] = ['UNREACH_STICKY']; // Ignore indicators by name
const allowedTypes: Types[] = ['button', 'rgb', 'dimmer', 'light']; // Supported types. Leave it null if you want to get ALL devices.
const options: DetectOptions = {
objects: this.props.objects,
id: 'hm-rpc.0.LEQ1214232.1', // Channel, device or state, that must be detected
_keysOptional: keys,
_usedIdsOptional: usedIds,
ignoreIndicators,
// allowedTypes,
};
let controls: PatternControl[] = detector.detect(options);
if (controls) {
controls = controls.map((control: PatternControl) => {
const id = control.states.find((state: DetectorState) => state.id).id;
if (id) {
console.log(`In ${options.id} was detected "${control.type}" with following states:`);
control.states
.filter((state: DetectorState) => state.id)
.forEach((state: DetectorState) => {
console.log(` ${state.name} => ${state.id}`);
});
return { control, id };
}
});
} else {
console.log(`Nothing found for ${options.id}`);
}// Legacy
const { ChannelDetector } = require('@iobroker/type-detector');
const detector = new ChannelDetector();
const keys = Object.keys(objects); // For optimization
const usedIds = []; // To not allow using of same ID in more than one device
const ignoreIndicators = ['UNREACH_STICKY']; // Ignore indicators by name
const allowedTypes = ['button', 'rgb', 'dimmer', 'light']; // Supported types. Leave it null if you want to get ALL devices.
const options = {
objects: this.props.objects,
id: 'hm-rpc.0.LEQ1214232.1', // Channel, device or state, that must be detected
_keysOptional: keys,
_usedIdsOptional: usedIds,
ignoreIndicators,
// allowedTypes,
};
let controls = detector.detect(options);
if (controls) {
controls = controls.map(control => {
const id = control.states.find(state => state.id).id;
if (id) {
console.log(`In ${options.id} was detected "${control.type}" with following states:`);
control.states
.filter(state => state.id)
.forEach(state => {
console.log(` ${state.name} => ${state.id}`);
});
return { control, id };
}
});
} else {
console.log(`Nothing found for ${options.id}`);
}- (@GermanBluefox) Allowed mode to be not only a number with states, but also a string with states
- (@Apollon77) Fixed the default role of the wind speed of
weatherCurrent, which carried a regular expression anchor - (@Apollon77) Fixed one object being assigned to two state definitions of the same name, which reported the swing of an air conditioner twice with a conflicting type and role
- (@Apollon77) Added the electricity states to
thermostat,fanandairPurifier - (@Apollon77) Added the optional state
WINDOWtothermostatfor the open window detection of the device - (@Apollon77) Added the optional states
HOME,RUN_MODE,PROGRESSandPHASEand the missingWORKINGtovacuumCleaner - (@Apollon77) A
vacuumCleaneris now detected with either the cleaning mode or the new run mode, instead of requiring the cleaning mode - (@Apollon77) Added the optional end contacts
OPENEDandCLOSEDtogate - (@Apollon77) Added
UNREACHtomedia, so every device type reports reachability the same way.CONNECTED(indicator.reachable) stays onmediafor compatibility but is deprecated, preferUNREACH - (@Apollon77) Added the optional state
RSSIto all device types that describe a radio device - (@Apollon77) Added the optional state
VALVEtothermostatand the optional stateWORKING_MODEtothermostat(value.mode.thermostat) andairCondition(value.mode.airconditioner) - (@Apollon77) Added new device type
electricityfor devices that only measure electricity - (@Apollon77) The feedback state
ACTUALofsocketno longer matches the generic rolestate, andON_ACTUALno longer matches any role that merely ends inswitch - (@Apollon77) Fixed the escaping of object IDs used to build regular expressions, so IDs containing characters like
\,+or*are matched literally - (@Apollon77) Added the optional states
SPEED_LEVEL,AIRFLOW_DIRECTION,FILTER_CONDITION,FILTER_CONDITION_CARBONandFILTER_CHANGEtoairCondition - (@Apollon77) Added the missing shared states
WORKING,LOWBATandBATTERYtoairCondition. They were previously reported as a separateinfodevice - (@Apollon77) Added the optional states
SET_HEATINGandSET_COOLINGtoairConditionandthermostatfor devices that hold a heating and a cooling setpoint at once. One ofSET,SET_HEATINGandSET_COOLINGis now required instead ofSETalone. A device whose only setpoint carries the rolelevel.temperature.heatingorlevel.temperature.coolingis still detected, but that state is now reported asSET_HEATING/SET_COOLINGinstead ofSET - (@Apollon77) Added the optional state
ON_TIMEto the light types,socket,fanandairPurifier - (@Apollon77) Added new device type
coAlarmfor carbon monoxide alarms - (@Apollon77) Added the optional states
CO,SEVERITY,MUTEDandTESTtofireAlarm, so a combined smoke and CO alarm is one device - (@Apollon77) Added new device type
pumpfor pumps (Matter Pump device) - (@Apollon77) Added new device types
pressureandflowfor pressure and flow sensors - (@Apollon77) Added new device type
contactfor generic contact sensors - (@Apollon77) Added the optional states
ONandON_ACTUALtoslider, so a dimmed device that is not a light keeps its on/off in one control - (@Apollon77) The continuous fan speed of
fanandairPurifieruses the existing rolelevel.speedinstead of a new rolelevel.fan - (@Apollon77) Added the state flag
requiredOneOfto require at least one state out of a group instead of one specific state - (@Apollon77) An
airPurifieris now also detected when it reports only the activated carbon filter - (@Apollon77) Added new device type
airPurifierfor air purifiers (Matter Air Purifier device) - (@Apollon77) Fixed states that lost a pattern slot to a better candidate being marked as used, which hid them from the remaining states of the same pattern
- (@Apollon77) Added new device type
fanfor fans (Matter Fan device) - (@Apollon77) Combined the fan states shared by
airCondition,fanandairPurifierinto one definition - (@Apollon77) Added new device type
airQualityfor air quality sensors (Matter Air Quality Sensor / Air Purifier) - (@Apollon77) BREAKING: Renamed the detected state name of the
direction_enumshared pattern fromDIRECTIONtoDIRECTION_ENUMto make it distinguishable from the booleandirectionpattern. Affects the device typesblind,blindButtons,gateandlock.
- (@GermanBluefox) Added tank level to devices
- (@GermanBluefox) Added to export the detection function from roleEnumUtils (used in iot)
- (@GermanBluefox) Media player was extended with player's name and type
- (@Garfonso) Corrected
ACTUALstate for the socket device - (@Garfonso) Allowed timestamp for TIME_SUNRISE
- (@Garfonso) Light effect state for lamps
- (@GermanBluefox) Breaking change: added new type percentage
The device with unit=% was detected as
slider, now it will be detected aspercentage. Developers must implement a new type!
- (@GermanBluefox) Added GUI to test the objects
- (@GermanBluefox) windowTilt and window requires now to have "write"=false explicitly to be detected
- (@GermanBluefox) Improved detection of devices if the structure has more than one control inside
- (@GermanBluefox) Added a new flag to detect only in the current channel (one level)
- (@GermanBluefox) Correcting detection of states consists only of one state
- (@Apollon77) ignore "setting" roles in some cases to ensure correct detection
- (@GermanBluefox) added potential error handling for detection
- (@Apollon77) Enhance detection logic when multiple states are detected in the same pattern-state to favor ID, default-role and number-of-role-levels and not "state" roles
- (@Apollon77) Added detection option
limitTypesToOneOfto define limiting sets of detected types
- (@GermanBluefox) Rename type
location_onetolocationOne
- (@GermanBluefox) Added default role for
image - (@GermanBluefox) Added exported type
ExternalDetectorState - (@Apollon77) Removed "Saturation" states from non-Hue light device types to not block that state for detection
- (@Apollon77) Added default unit "%" to volume definitions
- (@Apollon77) Combined some duplicate state definitions
- (@Apollon77) Adjusted Airconditioner Mode definition
- (@Apollon77) Optimized Detection logic in several places
- (@Apollon77) Consider allowed/excluded types when returning cached results
- (@Apollon77) Added "detectParent" mode to always search up in the objects to a device or channel when detecting
- (@Apollon77) Added "prioritizedTypes" property for options to allow type detection prioritization
- (@GermanBluefox) Improved documentation
- (@GermanBluefox) Added exported type
ExternalPatternControl - (@GermanBluefox) Updated packages
- (@GermanBluefox) Added detection of
level.direction - (@Apollon77) Added door state for device type "lock"
- (@Apollon77) Added default unit for volume states
- (@Apollon77) Added a new option ignoreEnums to execute the detection without enums-matching logic
- (@Apollon77) Added a new option detectAllPossibleDevices to detect multiple devices in one run without checking for already used IDs
- (@Garfonso) Added missing default roles and units for saturation
- (@Apollon77) Fixed the default unit for Illuminance to "lux"
- (@Apollon77) Added Low-Battery state for switch to be consistent with other devices
- (@Garfonso) Added new device type - illuminance (brightness sensor)
- (@Garfonso) Added battery state
- (@Garfonso) Added the transition time state
- (@Garfonso) Allowed the mixed
device->stateanddevice->channel->statestructures - (@GermanBluefox) Used a new eslint config library
- (@GermanBluefox) Types were slightly changed
- (Apollon77) Removed a file state type
- (Apollon77) Adjusted Camera states to remove Binary state and replace by link
- (Apollon77) Fixed role for ACTUAL state for socket
- (Apollon77) Fix Electricity states for light type
- (Apollon77) Add Electricity states for more types
- (Apollon77) Internal Refactoring
- (bluefox) Implemented
@iobroker/type-detectoras npm module
- (bluefox) Removed
valveandurlas types (they just asliderandimage)
- (bluefox) Removed multiple for weather location
- (Garfonso) Changed detection of fire and flood sensors
- (Garfonso) Changed the role of TIME_SUNRISE and TIME_SUNSET
- (Garfonso) Added
rgbwSingledevice to types
- (bluefox) Added
rgbwSingledevice
- (bluefox) Removed
rgbOldtype from 2018
- (bluefox) Fixed creation of the
DEVICES.md - (bluefox) Fixed the main attribute in package.json
- (bluefox) Better detection of the door devices
- (Garfonso) corrected the double states in light devices
- (Garfonso) added CIE color type as equivalent to
rgbSingletype
- (Garfonso) blinds: corrected error in the default role for tilt
- (bluefox) Fixed the main attribute in package.json
- (algar42) extend the weather forecast device with
TIME_SUNRISEandTIME_SUNSET - (Garfonso) added weatherForecast tests
- (bluefox) Added chart device
- (bluefox) Changed the air conditioner detection
- (Garfonso) Corrected blind with buttons
- (bluefox) Changed the air conditioner detection
- (Garfonso) Corrected blind with buttons
- (Garfonso) Added buttons to blinds and added THE new type: blinds with only buttons
- (agross) refactoring
- (bluefox) Extend socket and light with electricity parameters
- (bluefox) Added some states to thermostat
- (bluefox) Added new types: gate, camera, flood alarm, current weather.
- (bluefox) Escape chars in IDs.
- (bluefox) Added the vacuum cleaner.
- (bluefox) Added the air conditioner.
- (Garfonso) The switch could have the boolean type
- (Garfonso) Fixed
level.dimspeedissue
- (bluefox) Ignore
level.dimspeedfor dimmer - (bluefox) Added new type
button.press
- (Garfonso) Added "white" to rgb
- (bluefox) Add default roles
- (bluefox) Fixed search for multiple items.
- (bluefox) Added function "getPatterns".
- (bluefox) Add description to function "detect".
- (kirovilya) In some cases, devices may not have channels but immediately have a state. For example, in the zigbee-adapter.
- (bluefox) added PRECIPITATION to weather
- (bluefox) added location detection
- (bluefox) initial commit
Copyright (c) 2018-2026 Denis Haev dogafox@gmail.com
MIT License