Detects devices in ioBroker for Material, Google home, Homekit, ...
npm install @iobroker/type-detectorThis is not the adapter.
This is 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 used in material adapter to detect devices and to visualize them.
The following code detects devices in some state's tree:
``typescript
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:); ${state.name} => ${state.id}
control.states
.filter((state: DetectorState) => state.id)
.forEach((state: DetectorState) => {
console.log();
});
return { control, id };
}
});
} else {
console.log(Nothing found for ${options.id});`
}
`javascript
// 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:); ${state.name} => ${state.id}
control.states
.filter(state => state.id)
.forEach(state => {
console.log();
});
return { control, id };
}
});
} else {
console.log(Nothing found for ${options.id});`
}
state for the socket device
- (@Garfonso) Allowed timestamp for TIME_SUNRISE
- (@Garfonso) Light effect state for lamps$3
- (@GermanBluefox) Breaking change: added new type percentage
The device with unit=% was detected as slider, now it will be detected as percentage. Developers must implement a new type!$3
- (@GermanBluefox) Added GUI to test the objects
- (@GermanBluefox) windowTilt and window requires now to have "write"=false explicitly to be detected$3
- (@GermanBluefox) Improved detection of devices if the structure has more than one control inside$3
- (@GermanBluefox) Added new flag to detect only in the current channel (one level)$3
- (@GermanBluefox) Correcting detection of states consists only of one state$3
- (@Apollon77) ignore "setting" roles in some cases to ensure correct detection
- (@GermanBluefox) added potential error handling for detection$3
- (@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$3
- (@Apollon77) Added detection option limitTypesToOneOf to define limiting sets of detected types$3
- (@GermanBluefox) Rename type location_one to locationOne$3
- (@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$3
- (@GermanBluefox) Added exported type ExternalPatternControl
- (@GermanBluefox) Updated packages$3
- (@GermanBluefox) Added detection of level.direction
- (@Apollon77) Added door state for device type "lock"
- (@Apollon77) Added default unit for volume states
- (@Apollon77) Added new option ignoreEnums to execute the detection without enums-matching logic
- (@Apollon77) Added 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$3
- (@Apollon77) Fixed default unit for Illuminance to "lux"
- (@Apollon77) Added Low-Battery state for switch to be consistent with other devices$3
- (@Garfonso) Added new device type - illuminance (brightness sensor)
- (@Garfonso) Added battery state
- (@Garfonso) Added the transition time state
- (@Garfonso) Allowed the mixed
device->state and device->channel->state structures
- (@GermanBluefox) Used a new eslint config library
- (@GermanBluefox) Types were slightly changed
- (Apollon77) Removed File state type
- (Apollon77) Adjusted Camera states to remove Binary state and replace by link
- (Apollon77) Fixed role for ACTUAL state for socket$3
- (Apollon77) Fix Electricity states for light type
- (Apollon77) Add Electricity states for more types
- (Apollon77) Internal Refactoring
$3
- (bluefox) Implemented
@iobroker/type-detector as npm module$3
- (bluefox) Removed
valve and url as types (they just a slider and image)$3
- (bluefox) Removed multiple for weather location
$3
- (Garfonso) Changed detection of fire and flood sensors
- (Garfonso) Changed the role of TIME_SUNRISE and TIME_SUNSET
$3
- (Garfonso) Added
rgbwSingle device to types$3
- (bluefox) Added
rgbwSingle device$3
- (bluefox) Removed
rgbOld type from 2018$3
- (bluefox) Fixed creation of the
DEVICES.md
- (bluefox) Fixed the main attribute in package.json
- (bluefox) Better detection of the door devices$3
- (Garfonso) corrected the double states in light devices
- (Garfonso) added CIE color type as equivalent to
rgbSingle type$3
- (Garfonso) blinds: corrected error in the default role for tilt
$3
- (bluefox) Fixed the main attribute in package.json
$3
- (algar42) extend the weather forecast device with
TIME_SUNRISE and TIME_SUNSET
- (Garfonso) added weatherForecast tests$3
- (bluefox) Added chart device
$3
- (bluefox) Changed the air conditioner detection
- (Garfonso) Corrected blind with buttons
$3
- (bluefox) Changed the air conditioner detection
- (Garfonso) Corrected blind with buttons
$3
- (Garfonso) Added buttons to blinds and added THE new type: blinds with only buttons
- (agross) refactoring
- (bluefox) Extend socket and light with electricity parameters
$3
- (bluefox) Added some states to thermostat
$3
- (bluefox) Added new types: gate, camera, flood alarm, current weather.
$3
- (bluefox) Escape chars in IDs.
$3
- (bluefox) Added the vacuum cleaner.
$3
- (bluefox) Added the air conditioner.
$3
- (Garfonso) The switch could have the boolean type
- (Garfonso) Fixed
level.dimspeed issue$3
- (bluefox) Ignore
level.dimspeed for 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 states. For example, in the zigbee-adapter.
- (bluefox) added PRECIPITATION to weather
- (bluefox) added location detection
- (bluefox) initial commit
Copyright (c) 2018-2026 Denis Haev
MIT License