UNPKG

iobroker.zigbee2mqtt

Version:
544 lines (516 loc) 12.6 kB
'use strict'; /*eslint no-unused-vars: ['off']*/ const rgb = require('./rgb.js'); const utils = require('./utils.js'); const colors = require('./colors.js'); /* states for device: id - sysname of state, id name - display name of state prop - attr name of payload object with value of state icon - url of state icon role - state role write, read - allow to write and read state from admin type - type of value isEvent - sign of clearing the value after 300ms isOption - if state is internal setting, not to be sent to device inOptions - if true, value of this state will be included in options argument of other states setter(Opt) getter - result of call is the value of state. if value is undefined - state not apply setter - result of call is the value for publish to zigbee setterOpt - result of call is the options for publish to zigbee setattr - name of converter to zigbee, if it different from "prop" value epname - endpoint name for publish lazy - if true, then the state will not be created until the first event for the specified state arrives */ const nameLookup = { C: 'temperature', '%': 'humidity', m: 'altitude', Pa: 'pressure', ppm: 'quality', psize: 'particle_size', V: 'voltage', A: 'current', Wh: 'energy', W: 'power', Hz: 'frequency', pf: 'power_factor', lx: 'illuminance_lux', }; const unitLookup = { temperature: 'C', humidity: '%', altitude: 'm', pressure: 'Pa', quality: 'ppm', particle_size: 'psize', voltage: 'V', current: 'A', energy: 'Wh', power: 'W', frequency: 'Hz', power_factor: 'pf', illuminance_lux: 'lx', }; const timers = {}; const states = { link_quality: { id: 'link_quality', prop: 'linkquality', name: 'Link quality', icon: undefined, role: 'state', write: false, read: true, type: 'number', def: 0, min: 0, max: 255, }, available: { id: 'available', prop: 'available', name: 'Available', icon: undefined, role: 'indicator.reachable', write: false, read: true, type: 'boolean', def: false, }, last_seen: { id: 'last_seen', prop: 'last_seen', name: 'The date/time of last Zigbee message', icon: undefined, role: 'state', write: false, read: true, type: 'string', def: '', getter: (payload) => { return payload.last_seen.replace('T', ' ').split('+')[0]; }, }, simulated_brightness: { id: 'simulated_brightness', prop: 'brightness', name: 'Simulated brightness', icon: undefined, role: 'level.dimmer', write: true, read: true, type: 'number', def: 0, unit: '%', getter: (payload) => { return utils.bulbLevelToAdapterLevel(payload.brightness); }, }, state: { id: 'state', name: 'Switch state', icon: undefined, role: 'switch', write: true, read: true, type: 'boolean', def: false, getter: (payload) => payload.state === 'ON', setter: (value) => (value ? 'ON' : 'OFF'), }, brightness: { id: 'brightness', name: 'Brightness', options: ['transition'], icon: undefined, role: 'level.dimmer', write: true, read: true, type: 'number', unit: '%', min: 0, max: 100, def: 100, getter: (payload) => { return utils.bulbLevelToAdapterLevel(payload.brightness); }, setter: (value) => { return utils.adapterLevelToBulbLevel(value); }, }, brightness_move: { id: 'brightness_move', prop: 'brightness_move', name: 'Dimming', icon: undefined, role: 'state', write: true, read: false, type: 'number', min: -50, max: 50, def: 0, }, colortemp_move: { id: 'colortemp_move', prop: 'color_temp_move', name: 'Colortemp change', icon: undefined, role: 'state', write: true, read: false, type: 'number', min: -50, max: 50, def: 0, }, transition: { id: 'transition', prop: 'transition', name: 'Transition time overwrite (-1 disabled)', icon: undefined, role: 'state', write: true, read: false, type: 'number', unit: 'sec', min: -1, max: 65535, def: -1, isOption: true, }, send_payload: { id: 'send_payload', name: 'Send a raw json payload', icon: undefined, role: 'json', write: true, read: false, type: 'string', def: '{}', }, voltage: { id: 'voltage', name: 'Voltage', icon: undefined, role: 'value.voltage', write: false, read: true, type: 'number', unit: 'V', def: 0, }, battery_voltage: { id: 'voltage', name: 'Battery voltage', icon: undefined, role: 'battery.voltage', write: false, read: true, type: 'number', unit: 'V', def: 0, }, energy: { id: 'energy', name: 'Sum of consumed energy', icon: undefined, role: 'value.power.consumption', write: false, read: true, type: 'number', unit: 'kWh', def: 0, }, battery: { id: 'battery', prop: 'battery', name: 'Battery percent', icon: undefined, role: 'value.battery', write: false, read: true, type: 'number', unit: '%', min: 0, max: 100, def: 0, }, device_temperature: { id: 'device_temperature', name: 'Temperature of the device', icon: undefined, role: 'value.temperature', write: false, read: true, type: 'number', unit: '°C', def: 0, }, temperature: { id: 'temperature', name: 'Temperature', icon: undefined, role: 'value.temperature', write: false, read: true, type: 'number', unit: '°C', def: 0, }, humidity: { id: 'humidity', name: 'Humidity', icon: undefined, role: 'value.humidity', write: false, read: true, type: 'number', def: 0, unit: '%', min: 0, max: 100, }, pressure: { id: 'pressure', name: 'Pressure', icon: undefined, role: 'value.pressure', write: false, read: true, type: 'number', def: 0, unit: 'hPa', min: 0, max: 10000, }, illuminance: { id: 'illuminance', prop: 'illuminance_lux', name: 'Illuminance', icon: undefined, role: 'value.brightness', write: false, read: true, type: 'number', def: 0, unit: 'lux', }, illuminance_raw: { id: 'illuminance_raw', prop: 'illuminance', name: 'Illuminance raw', icon: undefined, role: 'value.brightness', write: false, read: true, type: 'number', def: 0, unit: '', }, occupancy: { id: 'occupancy', name: 'Occupancy', icon: undefined, role: 'sensor.motion', write: false, read: true, type: 'boolean', def: false, }, contact: { id: 'contact', prop: 'contact', name: 'Contact event', icon: undefined, role: 'state', write: false, read: true, type: 'boolean', def: false, }, opened: { id: 'opened', prop: 'contact', name: 'Is open', icon: undefined, role: 'sensor.window', write: false, read: true, type: 'boolean', def: false, getter: (payload) => !payload.contact, }, tamper: { id: 'tampered', prop: 'tamper', name: 'Is tampered', icon: undefined, role: 'state', write: false, read: true, type: 'boolean', }, water_leak: { id: 'detected', prop: 'water_leak', name: 'Water leak detected', icon: undefined, role: 'indicator.alarm.flood', write: false, read: true, type: 'boolean', def: false, }, batt_low_t_f: { id: 'battery_low', prop: 'battery_low', name: 'Battery Status Low', icon: undefined, role: 'indicator.lowbat', write: false, read: true, type: 'boolean', def: false, }, load_power: { id: 'load_power', prop: 'power', name: 'Load power', icon: undefined, role: 'value.power', write: false, read: true, type: 'number', def: 0, unit: 'W', }, load_current: { id: 'load_current', prop: 'current', name: 'Load current', icon: undefined, role: 'value.current', write: false, read: true, type: 'number', unit: 'A', def: 0, }, temp_calibration: { id: 'temperature_calibration', prop: 'temperature_calibration', name: 'Temperature Calibration Offset', icon: undefined, role: 'value.temperature', write: true, read: true, type: 'number', def: 0, unit: '°C', isOption: true, }, local_temperature: { id: 'local_temperature', prop: 'local_temperature', name: 'Local Temperature', icon: undefined, role: 'value.temperature', write: false, read: true, type: 'number', def: 0, unit: '°C', }, local_temperature_calibration: { id: 'local_temperature_calibration', prop: 'local_temperature_calibration', name: 'Temperature Calibration', icon: undefined, role: 'level', write: true, read: true, type: 'number', def: 0, unit: '°C', }, climate_away_mode: { id: 'away_mode', prop: 'away_mode', name: 'Away', icon: undefined, role: 'state', write: true, read: true, type: 'boolean', isEvent: true, getter: (payload) => (payload.action === 'ON' ? true : false), setter: (value) => (value ? 'ON' : 'OFF'), }, climate_system_mode: { id: 'mode', name: 'Mode', prop: 'system_mode', icon: undefined, role: 'state', write: true, read: true, type: 'string', states: { auto: 'auto', off: 'off', heat: 'heat' }, }, climate_running_mode: { id: 'running_state', name: 'Running Mode', prop: 'running_state', icon: undefined, role: 'state', write: true, read: true, type: 'string', // valid: low, medium, high states: { idle: 'idle', heat: 'heat' }, }, brightness_step: { id: 'brightness_step', prop: 'brightness_step', name: 'Brightness stepping', icon: undefined, role: 'state', write: true, read: false, type: 'number', def: 0, min: -50, max: 50, }, hue_move: { id: 'hue_move', prop: 'hue_move', name: 'Hue change', icon: undefined, role: 'state', write: true, read: false, type: 'number', min: -50, max: 50, def: 0, }, child_lock: { id: 'lock', name: 'Locked', prop: 'child_lock', icon: undefined, role: 'state', write: true, read: true, type: 'boolean', def: false, getter: (payload) => payload.child_lock === 'LOCKED', setter: (value) => (value ? 'LOCKED' : 'UNLOCKED'), }, }; module.exports = { states: states, unitLookup: unitLookup, nameLookup: nameLookup, };