2018-11-16 12:23:11 -07:00
|
|
|
const zigbeeShepherdConverters = require('zigbee-shepherd-converters');
|
|
|
|
const settings = require('../util/settings');
|
|
|
|
const logger = require('../util/logger');
|
2018-12-07 15:17:29 -07:00
|
|
|
const zigbee2mqttVersion = require('../../package.json').version;
|
2018-04-25 11:54:41 -07:00
|
|
|
|
|
|
|
const configurations = {
|
2018-04-23 09:29:35 -07:00
|
|
|
// Binary sensor
|
|
|
|
'binary_sensor_occupancy': {
|
|
|
|
type: 'binary_sensor',
|
|
|
|
object_id: 'occupancy',
|
|
|
|
discovery_payload: {
|
2018-04-23 12:44:06 -07:00
|
|
|
payload_on: true,
|
|
|
|
payload_off: false,
|
2018-04-23 09:29:35 -07:00
|
|
|
value_template: '{{ value_json.occupancy }}',
|
|
|
|
device_class: 'motion',
|
2018-05-17 08:20:46 -07:00
|
|
|
},
|
2018-04-23 09:29:35 -07:00
|
|
|
},
|
2018-10-31 09:10:28 -07:00
|
|
|
'binary_sensor_presence': {
|
|
|
|
type: 'binary_sensor',
|
|
|
|
object_id: 'presence',
|
|
|
|
discovery_payload: {
|
|
|
|
payload_on: true,
|
|
|
|
payload_off: false,
|
|
|
|
value_template: '{{ value_json.presence }}',
|
|
|
|
device_class: 'presence',
|
|
|
|
},
|
|
|
|
},
|
2018-04-23 12:44:06 -07:00
|
|
|
'binary_sensor_contact': {
|
2018-04-23 09:29:35 -07:00
|
|
|
type: 'binary_sensor',
|
2018-04-23 12:44:06 -07:00
|
|
|
object_id: 'contact',
|
2018-04-23 09:29:35 -07:00
|
|
|
discovery_payload: {
|
2018-04-23 12:44:06 -07:00
|
|
|
payload_on: false,
|
|
|
|
payload_off: true,
|
|
|
|
value_template: '{{ value_json.contact }}',
|
2018-04-23 09:29:35 -07:00
|
|
|
device_class: 'door',
|
2018-05-17 08:20:46 -07:00
|
|
|
},
|
2018-04-23 09:29:35 -07:00
|
|
|
},
|
|
|
|
'binary_sensor_water_leak': {
|
|
|
|
type: 'binary_sensor',
|
|
|
|
object_id: 'water_leak',
|
|
|
|
discovery_payload: {
|
|
|
|
payload_on: true,
|
|
|
|
payload_off: false,
|
|
|
|
value_template: '{{ value_json.water_leak }}',
|
|
|
|
device_class: 'moisture',
|
2018-05-17 08:20:46 -07:00
|
|
|
},
|
2018-04-23 09:29:35 -07:00
|
|
|
},
|
2018-05-16 11:15:50 -07:00
|
|
|
'binary_sensor_smoke': {
|
|
|
|
type: 'binary_sensor',
|
|
|
|
object_id: 'smoke',
|
|
|
|
discovery_payload: {
|
|
|
|
payload_on: true,
|
|
|
|
payload_off: false,
|
|
|
|
value_template: '{{ value_json.smoke }}',
|
|
|
|
device_class: 'smoke',
|
2018-05-17 08:20:46 -07:00
|
|
|
},
|
2018-05-16 11:15:50 -07:00
|
|
|
},
|
2018-08-30 09:06:52 -07:00
|
|
|
'binary_sensor_gas': {
|
|
|
|
type: 'binary_sensor',
|
|
|
|
object_id: 'gas',
|
|
|
|
discovery_payload: {
|
|
|
|
payload_on: true,
|
|
|
|
payload_off: false,
|
|
|
|
value_template: '{{ value_json.gas }}',
|
|
|
|
device_class: 'gas',
|
|
|
|
},
|
|
|
|
},
|
2018-05-17 09:03:54 -07:00
|
|
|
'binary_sensor_router': {
|
|
|
|
type: 'binary_sensor',
|
|
|
|
object_id: 'router',
|
|
|
|
discovery_payload: {
|
|
|
|
payload_on: true,
|
|
|
|
payload_off: false,
|
|
|
|
value_template: '{{ value_json.state }}',
|
|
|
|
device_class: 'connectivity',
|
|
|
|
},
|
|
|
|
},
|
2018-04-23 09:29:35 -07:00
|
|
|
|
|
|
|
// Sensor
|
|
|
|
'sensor_illuminance': {
|
|
|
|
type: 'sensor',
|
|
|
|
object_id: 'illuminance',
|
|
|
|
discovery_payload: {
|
|
|
|
unit_of_measurement: 'lx',
|
2018-10-24 12:10:42 -07:00
|
|
|
device_class: 'illuminance',
|
2018-04-23 09:29:35 -07:00
|
|
|
value_template: '{{ value_json.illuminance }}',
|
2018-11-05 11:39:36 -07:00
|
|
|
json_attributes: ['linkquality', 'battery', 'voltage'],
|
2018-05-17 08:20:46 -07:00
|
|
|
},
|
2018-04-23 09:29:35 -07:00
|
|
|
},
|
|
|
|
'sensor_humidity': {
|
|
|
|
type: 'sensor',
|
|
|
|
object_id: 'humidity',
|
|
|
|
discovery_payload: {
|
|
|
|
unit_of_measurement: '%',
|
2018-10-24 12:10:42 -07:00
|
|
|
device_class: 'humidity',
|
2018-04-23 09:29:35 -07:00
|
|
|
value_template: '{{ value_json.humidity }}',
|
2018-11-05 11:39:36 -07:00
|
|
|
json_attributes: ['linkquality', 'battery', 'voltage'],
|
2018-05-17 08:20:46 -07:00
|
|
|
},
|
2018-04-23 09:29:35 -07:00
|
|
|
},
|
|
|
|
'sensor_temperature': {
|
|
|
|
type: 'sensor',
|
|
|
|
object_id: 'temperature',
|
|
|
|
discovery_payload: {
|
|
|
|
unit_of_measurement: '°C',
|
2018-10-24 12:10:42 -07:00
|
|
|
device_class: 'temperature',
|
2018-04-23 09:29:35 -07:00
|
|
|
value_template: '{{ value_json.temperature }}',
|
2018-11-05 11:39:36 -07:00
|
|
|
json_attributes: ['linkquality', 'battery', 'voltage'],
|
2018-05-17 08:20:46 -07:00
|
|
|
},
|
2018-04-23 09:29:35 -07:00
|
|
|
},
|
|
|
|
'sensor_pressure': {
|
|
|
|
type: 'sensor',
|
|
|
|
object_id: 'pressure',
|
|
|
|
discovery_payload: {
|
2018-10-24 12:10:42 -07:00
|
|
|
unit_of_measurement: 'hPa',
|
|
|
|
device_class: 'pressure',
|
2018-04-23 09:29:35 -07:00
|
|
|
value_template: '{{ value_json.pressure }}',
|
2018-11-05 11:39:36 -07:00
|
|
|
json_attributes: ['linkquality', 'battery', 'voltage'],
|
2018-05-17 08:20:46 -07:00
|
|
|
},
|
2018-04-23 09:29:35 -07:00
|
|
|
},
|
2018-05-08 11:13:01 -07:00
|
|
|
'sensor_click': {
|
2018-04-23 09:29:35 -07:00
|
|
|
type: 'sensor',
|
2018-05-08 11:13:01 -07:00
|
|
|
object_id: 'click',
|
2018-04-23 09:29:35 -07:00
|
|
|
discovery_payload: {
|
|
|
|
icon: 'mdi:toggle-switch',
|
|
|
|
value_template: '{{ value_json.click }}',
|
2018-11-05 11:39:36 -07:00
|
|
|
json_attributes: ['linkquality', 'battery', 'voltage', 'action', 'duration'],
|
2018-07-26 12:17:09 -07:00
|
|
|
force_update: true,
|
2018-05-17 08:20:46 -07:00
|
|
|
},
|
2018-04-23 09:29:35 -07:00
|
|
|
},
|
2018-04-23 13:36:30 -07:00
|
|
|
'sensor_power': {
|
|
|
|
type: 'sensor',
|
|
|
|
object_id: 'power',
|
|
|
|
discovery_payload: {
|
|
|
|
unit_of_measurement: 'Watt',
|
|
|
|
icon: 'mdi:flash',
|
|
|
|
value_template: '{{ value_json.power }}',
|
2018-11-05 11:39:36 -07:00
|
|
|
json_attributes: ['linkquality', 'voltage', 'temperature', 'consumption', 'current', 'power_factor'],
|
2018-05-17 08:20:46 -07:00
|
|
|
},
|
2018-04-23 13:36:30 -07:00
|
|
|
},
|
2018-05-08 11:20:57 -07:00
|
|
|
'sensor_action': {
|
|
|
|
type: 'sensor',
|
|
|
|
object_id: 'action',
|
|
|
|
discovery_payload: {
|
2018-07-10 09:43:31 -07:00
|
|
|
icon: 'mdi:gesture-double-tap',
|
2018-05-08 11:20:57 -07:00
|
|
|
value_template: '{{ value_json.action }}',
|
2018-09-20 13:26:02 -07:00
|
|
|
json_attributes: [
|
2018-11-05 11:39:36 -07:00
|
|
|
'linkquality', 'battery', 'voltage', 'angle', 'side', 'from_side', 'to_side', 'brightness',
|
2018-09-20 13:26:02 -07:00
|
|
|
'angle_x_absolute', 'angle_y_absolute', 'angle_z', 'angle_y', 'angle_x', 'unknown_data',
|
|
|
|
],
|
2018-08-24 14:58:44 -07:00
|
|
|
force_update: true,
|
2018-05-17 08:20:46 -07:00
|
|
|
},
|
2018-05-08 11:20:57 -07:00
|
|
|
},
|
2018-06-08 11:34:34 -07:00
|
|
|
'sensor_brightness': {
|
|
|
|
type: 'sensor',
|
|
|
|
object_id: 'brightness',
|
|
|
|
discovery_payload: {
|
|
|
|
unit_of_measurement: 'brightness',
|
|
|
|
icon: 'mdi:brightness-5',
|
|
|
|
value_template: '{{ value_json.brightness }}',
|
2018-11-05 11:39:36 -07:00
|
|
|
json_attributes: ['linkquality'],
|
2018-06-08 11:34:34 -07:00
|
|
|
},
|
|
|
|
},
|
2018-09-18 13:24:17 -07:00
|
|
|
'sensor_lock': {
|
|
|
|
type: 'sensor',
|
|
|
|
object_id: 'lock',
|
|
|
|
discovery_payload: {
|
|
|
|
icon: 'mdi:lock',
|
|
|
|
value_template: '{{ value_json.inserted }}',
|
2018-11-05 11:39:36 -07:00
|
|
|
json_attributes: ['linkquality', 'forgotten', 'keyerror'],
|
2018-09-18 13:24:17 -07:00
|
|
|
},
|
|
|
|
},
|
2018-11-19 12:43:23 -07:00
|
|
|
'sensor_battery': {
|
|
|
|
type: 'sensor',
|
|
|
|
object_id: 'battery',
|
|
|
|
discovery_payload: {
|
|
|
|
device_class: 'battery',
|
|
|
|
value_template: '{{ value_json.battery }}',
|
|
|
|
json_attributes: ['linkquality', 'voltage', 'action', 'sensitivity'],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'sensor_linkquality': {
|
|
|
|
type: 'sensor',
|
|
|
|
object_id: 'linkquality',
|
|
|
|
discovery_payload: {
|
|
|
|
value_template: '{{ value_json.linkquality }}',
|
|
|
|
json_attributes: ['description', 'type', 'rssi'],
|
|
|
|
},
|
|
|
|
},
|
2018-04-23 09:29:35 -07:00
|
|
|
|
|
|
|
// Light
|
2018-11-16 12:23:11 -07:00
|
|
|
'light_brightness_colortemp_colorxy': {
|
2018-04-23 09:29:35 -07:00
|
|
|
type: 'light',
|
|
|
|
object_id: 'light',
|
|
|
|
discovery_payload: {
|
|
|
|
brightness: true,
|
|
|
|
color_temp: true,
|
|
|
|
xy: true,
|
|
|
|
platform: 'mqtt_json',
|
2018-05-17 08:20:46 -07:00
|
|
|
command_topic: true,
|
|
|
|
},
|
2018-04-23 09:29:35 -07:00
|
|
|
},
|
2018-11-16 12:23:11 -07:00
|
|
|
'light_brightness_colorxy': {
|
2018-06-01 13:05:49 -07:00
|
|
|
type: 'light',
|
|
|
|
object_id: 'light',
|
|
|
|
discovery_payload: {
|
|
|
|
brightness: true,
|
|
|
|
xy: true,
|
|
|
|
platform: 'mqtt_json',
|
|
|
|
command_topic: true,
|
|
|
|
},
|
|
|
|
},
|
2018-04-23 09:29:35 -07:00
|
|
|
'light_brightness_colortemp': {
|
|
|
|
type: 'light',
|
|
|
|
object_id: 'light',
|
|
|
|
discovery_payload: {
|
|
|
|
brightness: true,
|
|
|
|
color_temp: true,
|
|
|
|
platform: 'mqtt_json',
|
2018-05-17 08:20:46 -07:00
|
|
|
command_topic: true,
|
|
|
|
},
|
2018-04-23 09:29:35 -07:00
|
|
|
},
|
2018-05-06 09:08:10 -07:00
|
|
|
'light_brightness': {
|
|
|
|
type: 'light',
|
|
|
|
object_id: 'light',
|
|
|
|
discovery_payload: {
|
|
|
|
brightness: true,
|
|
|
|
platform: 'mqtt_json',
|
2018-05-17 08:20:46 -07:00
|
|
|
command_topic: true,
|
|
|
|
},
|
2018-05-06 09:08:10 -07:00
|
|
|
},
|
2018-04-23 13:36:30 -07:00
|
|
|
|
|
|
|
// Switch
|
|
|
|
'switch': {
|
|
|
|
type: 'switch',
|
|
|
|
object_id: 'switch',
|
|
|
|
discovery_payload: {
|
2018-04-24 10:03:09 -07:00
|
|
|
payload_off: 'OFF',
|
|
|
|
payload_on: 'ON',
|
2018-04-23 13:36:30 -07:00
|
|
|
value_template: '{{ value_json.state }}',
|
2018-05-17 08:20:46 -07:00
|
|
|
command_topic: true,
|
|
|
|
},
|
2018-04-24 10:30:56 -07:00
|
|
|
},
|
2018-08-04 11:05:34 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
const switchWithPostfix = (postfix) => {
|
|
|
|
return {
|
2018-04-29 05:09:49 -07:00
|
|
|
type: 'switch',
|
2018-08-04 11:05:34 -07:00
|
|
|
object_id: `switch_${postfix}`,
|
2018-04-29 05:09:49 -07:00
|
|
|
discovery_payload: {
|
|
|
|
payload_off: 'OFF',
|
|
|
|
payload_on: 'ON',
|
2018-08-04 11:05:34 -07:00
|
|
|
value_template: `{{ value_json.state_${postfix} }}`,
|
2018-04-29 05:09:49 -07:00
|
|
|
command_topic: true,
|
2018-08-04 11:05:34 -07:00
|
|
|
command_topic_prefix: postfix,
|
2018-11-05 11:39:36 -07:00
|
|
|
json_attributes: ['linkquality', `button_${postfix}`],
|
2018-05-17 08:20:46 -07:00
|
|
|
},
|
2018-08-04 11:05:34 -07:00
|
|
|
};
|
2018-04-23 09:29:35 -07:00
|
|
|
};
|
|
|
|
|
2018-05-16 10:40:05 -07:00
|
|
|
// Map homeassitant configurations to devices.
|
|
|
|
const mapping = {
|
|
|
|
'WXKG01LM': [configurations.sensor_click],
|
|
|
|
'WXKG11LM': [configurations.sensor_click],
|
2018-05-29 10:12:45 -07:00
|
|
|
'WXKG12LM': [configurations.sensor_click],
|
2018-05-16 10:40:05 -07:00
|
|
|
'WXKG03LM': [configurations.sensor_click],
|
|
|
|
'WXKG02LM': [configurations.sensor_click],
|
|
|
|
'QBKG04LM': [configurations.switch],
|
2018-08-04 11:05:34 -07:00
|
|
|
'QBKG03LM': [switchWithPostfix('left'), switchWithPostfix('right')],
|
2018-05-16 10:40:05 -07:00
|
|
|
'WSDCGQ01LM': [configurations.sensor_temperature, configurations.sensor_humidity],
|
|
|
|
'WSDCGQ11LM': [configurations.sensor_temperature, configurations.sensor_humidity, configurations.sensor_pressure],
|
2018-11-19 12:43:23 -07:00
|
|
|
'RTCGQ01LM': [configurations.binary_sensor_occupancy, configurations.sensor_battery],
|
2018-11-19 12:49:25 -07:00
|
|
|
'RTCGQ11LM': [
|
|
|
|
configurations.binary_sensor_occupancy, configurations.sensor_illuminance,
|
|
|
|
configurations.sensor_battery,
|
|
|
|
],
|
2018-11-19 12:43:23 -07:00
|
|
|
'MCCGQ01LM': [configurations.binary_sensor_contact, configurations.sensor_battery],
|
|
|
|
'MCCGQ11LM': [configurations.binary_sensor_contact, configurations.sensor_battery],
|
|
|
|
'SJCGQ11LM': [configurations.binary_sensor_water_leak, configurations.sensor_battery],
|
2018-05-16 10:40:05 -07:00
|
|
|
'MFKZQ01LM': [configurations.sensor_action],
|
|
|
|
'ZNCZ02LM': [configurations.switch, configurations.sensor_power],
|
|
|
|
'QBCZ11LM': [configurations.switch, configurations.sensor_power],
|
|
|
|
'LED1545G12': [configurations.light_brightness_colortemp],
|
|
|
|
'LED1623G12': [configurations.light_brightness],
|
2018-05-21 02:11:24 -07:00
|
|
|
'LED1622G12': [configurations.light_brightness],
|
2018-05-16 10:40:05 -07:00
|
|
|
'LED1537R6': [configurations.light_brightness_colortemp],
|
|
|
|
'LED1650R5': [configurations.light_brightness],
|
|
|
|
'LED1536G5': [configurations.light_brightness_colortemp],
|
2018-11-16 12:23:11 -07:00
|
|
|
'7299760PH': [configurations.light_brightness_colorxy],
|
|
|
|
'7146060PH': [configurations.light_brightness_colortemp_colorxy],
|
2018-05-16 10:52:44 -07:00
|
|
|
'F7C033': [configurations.light_brightness],
|
2018-11-19 12:43:23 -07:00
|
|
|
'JTYJ-GD-01LM/BW': [configurations.binary_sensor_smoke, configurations.sensor_battery],
|
2018-05-21 04:21:18 -07:00
|
|
|
'PLUG EDP RE:DY': [configurations.switch, configurations.sensor_power],
|
2018-11-19 12:43:23 -07:00
|
|
|
'CC2530.ROUTER': [configurations.binary_sensor_router, configurations.sensor_linkquality],
|
2018-05-26 02:00:56 -07:00
|
|
|
'AA70155': [configurations.light_brightness_colortemp],
|
2018-11-16 12:23:11 -07:00
|
|
|
'4058075816718': [configurations.light_brightness_colortemp_colorxy],
|
|
|
|
'AA69697': [configurations.light_brightness_colortemp_colorxy],
|
2018-05-27 08:16:01 -07:00
|
|
|
'HALIGHTDIMWWE27': [configurations.light_brightness],
|
2018-05-28 11:01:28 -07:00
|
|
|
'AB3257001NJ': [configurations.switch],
|
2018-05-31 10:21:31 -07:00
|
|
|
'8718696449691': [configurations.light_brightness],
|
2018-11-16 12:23:11 -07:00
|
|
|
'RB 185 C': [configurations.light_brightness_colortemp_colorxy],
|
|
|
|
'9290012573A': [configurations.light_brightness_colortemp_colorxy],
|
|
|
|
'LED1624G9': [configurations.light_brightness_colorxy],
|
2018-06-05 11:27:36 -07:00
|
|
|
'73742': [configurations.light_brightness_colortemp],
|
|
|
|
'73740': [configurations.light_brightness_colortemp],
|
|
|
|
'22670': [configurations.light_brightness],
|
2018-06-08 11:34:34 -07:00
|
|
|
'ICTC-G-1': [configurations.sensor_brightness],
|
2018-06-13 11:23:26 -07:00
|
|
|
'ICPSHC24-30EU-IL-1': [configurations.light_brightness],
|
2018-06-12 12:02:24 -07:00
|
|
|
'45852GE': [configurations.light_brightness],
|
|
|
|
'E11-G13': [configurations.light_brightness],
|
2018-06-13 11:23:26 -07:00
|
|
|
'LED1649C5': [configurations.light_brightness],
|
2018-06-15 16:43:51 -07:00
|
|
|
'ICPSHC24-10EU-IL-1': [configurations.light_brightness],
|
2018-06-16 13:17:01 -07:00
|
|
|
'LED1546G12': [configurations.light_brightness_colortemp],
|
|
|
|
'L1527': [configurations.light_brightness_colortemp],
|
|
|
|
'L1529': [configurations.light_brightness_colortemp],
|
|
|
|
'L1528': [configurations.light_brightness_colortemp],
|
|
|
|
'RB 165': [configurations.light_brightness],
|
|
|
|
'RB 175 W': [configurations.light_brightness],
|
|
|
|
'RS 125': [configurations.light_brightness],
|
|
|
|
'RB 145': [configurations.light_brightness],
|
|
|
|
'PL 110': [configurations.light_brightness],
|
|
|
|
'ST 110': [configurations.light_brightness],
|
|
|
|
'UC 110': [configurations.light_brightness],
|
|
|
|
'DL 110 N': [configurations.light_brightness],
|
|
|
|
'DL 110 W': [configurations.light_brightness],
|
|
|
|
'SL 110 N': [configurations.light_brightness],
|
|
|
|
'SL 110 M': [configurations.light_brightness],
|
|
|
|
'SL 110 W': [configurations.light_brightness],
|
2018-06-17 08:15:43 -07:00
|
|
|
'AA68199': [configurations.light_brightness_colortemp],
|
|
|
|
'QBKG11LM': [configurations.switch, configurations.sensor_power],
|
2018-08-04 11:05:34 -07:00
|
|
|
'QBKG12LM': [switchWithPostfix('left'), switchWithPostfix('right'), configurations.sensor_power],
|
2018-11-16 12:23:11 -07:00
|
|
|
'K2RGBW01': [configurations.light_brightness_colortemp_colorxy],
|
2018-06-25 13:06:11 -07:00
|
|
|
'9290011370': [configurations.light_brightness],
|
2018-06-27 12:31:00 -07:00
|
|
|
'DNCKATSW001': [configurations.switch],
|
2018-06-30 00:48:21 -07:00
|
|
|
'Z809A': [configurations.switch, configurations.sensor_power],
|
2018-06-30 10:56:13 -07:00
|
|
|
'NL08-0800': [configurations.light_brightness],
|
2018-11-16 12:23:11 -07:00
|
|
|
'915005106701': [configurations.light_brightness_colortemp_colorxy],
|
2018-06-30 14:47:51 -07:00
|
|
|
'AB32840': [configurations.light_brightness_colortemp],
|
2018-11-16 12:23:11 -07:00
|
|
|
'8718696485880': [configurations.light_brightness_colortemp_colorxy],
|
2018-07-07 14:39:30 -07:00
|
|
|
'8718696598283': [configurations.light_brightness_colortemp],
|
2018-10-17 09:25:33 -07:00
|
|
|
'8718696695203': [configurations.light_brightness_colortemp],
|
2018-11-16 12:23:11 -07:00
|
|
|
'73693': [configurations.light_brightness_colortemp_colorxy],
|
2018-07-10 09:43:31 -07:00
|
|
|
'324131092621': [configurations.sensor_action],
|
2018-08-29 00:11:41 -07:00
|
|
|
'9290012607': [
|
|
|
|
configurations.binary_sensor_occupancy, configurations.sensor_temperature,
|
2018-11-19 12:43:23 -07:00
|
|
|
configurations.sensor_illuminance, configurations.sensor_battery,
|
2018-08-29 00:11:41 -07:00
|
|
|
],
|
2018-11-16 12:23:11 -07:00
|
|
|
'GL-C-008': [configurations.light_brightness_colortemp_colorxy],
|
2018-11-19 12:43:23 -07:00
|
|
|
'STSS-MULT-001': [configurations.binary_sensor_contact, configurations.sensor_battery],
|
2018-10-29 13:12:37 -07:00
|
|
|
'E11-G23/E11-G33': [configurations.light_brightness],
|
2018-11-16 12:23:11 -07:00
|
|
|
'AC03645': [configurations.light_brightness_colortemp_colorxy],
|
2018-07-22 09:49:45 -07:00
|
|
|
'AC03641': [configurations.light_brightness],
|
2018-07-31 12:50:04 -07:00
|
|
|
'FB56+ZSW05HG1.2': [configurations.switch],
|
2018-07-31 13:04:22 -07:00
|
|
|
'72922-A': [configurations.switch],
|
2018-08-04 11:05:34 -07:00
|
|
|
'AC03642': [configurations.light_brightness_colortemp],
|
|
|
|
'DNCKATSW002': [switchWithPostfix('left'), switchWithPostfix('right')],
|
|
|
|
'DNCKATSW003': [switchWithPostfix('left'), switchWithPostfix('right'), switchWithPostfix('center')],
|
|
|
|
'DNCKATSW004': [
|
|
|
|
switchWithPostfix('bottom_left'), switchWithPostfix('bottom_right'),
|
|
|
|
switchWithPostfix('top_left'), switchWithPostfix('top_right'),
|
|
|
|
],
|
2018-08-09 09:10:22 -07:00
|
|
|
'BY 165': [configurations.light_brightness],
|
2018-08-10 15:57:21 -07:00
|
|
|
'ZLED-2709': [configurations.light_brightness],
|
2018-08-13 11:37:01 -07:00
|
|
|
'8718696548738': [configurations.light_brightness_colortemp],
|
2018-11-16 12:23:11 -07:00
|
|
|
'4052899926110': [configurations.light_brightness_colortemp_colorxy],
|
2018-08-15 12:10:19 -07:00
|
|
|
'Z01-CIA19NAE26': [configurations.light_brightness],
|
2018-11-16 12:23:11 -07:00
|
|
|
'E11-N1EA': [configurations.light_brightness_colortemp_colorxy],
|
2018-08-24 15:11:42 -07:00
|
|
|
'74283': [configurations.light_brightness],
|
2018-11-19 12:43:23 -07:00
|
|
|
'JTQJ-BF-01LM/BW': [configurations.binary_sensor_gas, configurations.sensor_battery],
|
2018-09-11 09:01:48 -07:00
|
|
|
'50045': [configurations.light_brightness],
|
2018-11-19 12:43:23 -07:00
|
|
|
'AV2010/22': [configurations.binary_sensor_occupancy, configurations.sensor_battery],
|
2018-09-11 09:01:48 -07:00
|
|
|
'3210-L': [configurations.switch],
|
2018-12-04 12:40:47 -07:00
|
|
|
'3320-L': [configurations.binary_sensor_contact],
|
|
|
|
'3326-L': [configurations.binary_sensor_occupancy, configurations.sensor_temperature],
|
2018-11-16 12:23:11 -07:00
|
|
|
'7299355PH': [configurations.light_brightness_colorxy],
|
2018-09-20 13:23:12 -07:00
|
|
|
'45857GE': [configurations.light_brightness],
|
2018-09-18 13:24:17 -07:00
|
|
|
'A6121': [configurations.sensor_lock],
|
|
|
|
'433714': [configurations.light_brightness],
|
|
|
|
'3261030P7': [configurations.light_brightness_colortemp],
|
2018-09-20 13:26:02 -07:00
|
|
|
'DJT11LM': [configurations.sensor_action],
|
2018-09-29 12:21:35 -07:00
|
|
|
'E1603': [configurations.switch],
|
2018-11-16 12:23:11 -07:00
|
|
|
'7199960PH': [configurations.light_brightness_colorxy],
|
2018-09-29 14:04:50 -07:00
|
|
|
'74696': [configurations.light_brightness],
|
2018-11-16 12:23:11 -07:00
|
|
|
'AB35996': [configurations.light_brightness_colortemp_colorxy],
|
2018-09-29 14:04:50 -07:00
|
|
|
'AB401130055': [configurations.light_brightness_colortemp],
|
2018-10-01 07:39:23 -07:00
|
|
|
'74282': [configurations.light_brightness_colortemp],
|
2018-10-17 12:16:06 -07:00
|
|
|
'RS 128 T': [configurations.light_brightness_colortemp],
|
2018-10-19 13:20:11 -07:00
|
|
|
'53170161': [configurations.light_brightness_colortemp],
|
2018-11-16 12:23:11 -07:00
|
|
|
'4058075036147': [configurations.light_brightness_colortemp_colorxy],
|
2018-10-19 13:26:14 -07:00
|
|
|
'KS-SM001': [configurations.switch],
|
2018-10-25 11:43:31 -07:00
|
|
|
'MG-AUWS01': [switchWithPostfix('left'), switchWithPostfix('right')],
|
2018-11-16 12:23:11 -07:00
|
|
|
'9290002579A': [configurations.light_brightness_colortemp_colorxy],
|
2018-10-29 13:34:48 -07:00
|
|
|
'4256251-RZHAC': [configurations.switch, configurations.sensor_power],
|
2018-11-19 12:43:23 -07:00
|
|
|
'STS-PRS-251': [configurations.binary_sensor_presence, configurations.sensor_battery],
|
2018-11-14 10:32:02 -07:00
|
|
|
'4058075816794': [configurations.light_brightness_colortemp],
|
|
|
|
'4052899926158': [configurations.light_brightness],
|
2018-11-16 12:23:11 -07:00
|
|
|
'4058075036185': [configurations.light_brightness_colortemp_colorxy],
|
|
|
|
'50049': [configurations.light_brightness_colorxy],
|
|
|
|
'915005733701': [configurations.light_brightness_colortemp_colorxy],
|
|
|
|
'RB 285 C': [configurations.light_brightness_colortemp_colorxy],
|
2018-11-14 10:32:02 -07:00
|
|
|
'3216331P5': [configurations.light_brightness_colortemp],
|
2018-11-16 14:00:09 -07:00
|
|
|
'AC08562': [configurations.light_brightness],
|
2018-11-27 13:19:53 -07:00
|
|
|
'900008-WW': [configurations.light_brightness],
|
|
|
|
'Mega23M12': [configurations.light_brightness_colortemp_colorxy],
|
2018-11-30 10:35:54 -07:00
|
|
|
'PSS-23ZBS': [configurations.switch],
|
2018-11-30 15:39:04 -07:00
|
|
|
'HS1SA': [configurations.binary_sensor_smoke],
|
|
|
|
'Z01-A19NAE26': [configurations.light_brightness_colortemp],
|
2018-12-06 13:09:21 -07:00
|
|
|
'AC01353010G': [configurations.binary_sensor_occupancy, configurations.sensor_temperature],
|
2018-05-16 10:40:05 -07:00
|
|
|
};
|
|
|
|
|
2018-11-16 12:23:11 -07:00
|
|
|
/**
|
|
|
|
* This extensions handles integration with HomeAssistant
|
|
|
|
*/
|
|
|
|
class HomeAssistant {
|
|
|
|
constructor(zigbee, mqtt, state, publishDeviceState) {
|
|
|
|
this.zigbee = zigbee;
|
|
|
|
this.mqtt = mqtt;
|
|
|
|
this.state = state;
|
|
|
|
this.publishDeviceState = publishDeviceState;
|
2018-04-25 11:54:41 -07:00
|
|
|
|
2018-11-16 12:23:11 -07:00
|
|
|
// A map of all discoverd devices
|
|
|
|
this.discovered = {};
|
2018-04-25 11:54:41 -07:00
|
|
|
|
2018-11-16 12:23:11 -07:00
|
|
|
if (!settings.get().advanced.cache_state) {
|
|
|
|
logger.warn('In order for HomeAssistant integration to work properly set `cache_state: true');
|
|
|
|
}
|
|
|
|
}
|
2018-04-25 11:54:41 -07:00
|
|
|
|
2018-11-16 12:23:11 -07:00
|
|
|
onMQTTConnected() {
|
|
|
|
this.mqtt.subscribe('hass/status');
|
2018-04-25 11:54:41 -07:00
|
|
|
|
2018-11-16 12:23:11 -07:00
|
|
|
// MQTT discovery of all paired devices on startup.
|
|
|
|
this.zigbee.getAllClients().forEach((device) => {
|
2018-12-07 15:17:29 -07:00
|
|
|
const mappedModel = zigbeeShepherdConverters.findByZigbeeModel(device.modelId);
|
|
|
|
if (mappedModel) {
|
|
|
|
this.discover(device.ieeeAddr, mappedModel, true);
|
2018-11-16 12:23:11 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2018-06-24 05:21:56 -07:00
|
|
|
|
2018-12-07 15:17:29 -07:00
|
|
|
discover(ieeeAddr, mappedModel, force=false) {
|
2018-11-16 12:23:11 -07:00
|
|
|
// Check if already discoverd and check if there are configs.
|
|
|
|
const discover = force || !this.discovered[ieeeAddr];
|
2018-12-07 15:17:29 -07:00
|
|
|
if (!discover || !mapping[mappedModel.model] || !settings.getDevice(ieeeAddr)) {
|
2018-11-16 12:23:11 -07:00
|
|
|
return;
|
2018-06-24 05:21:56 -07:00
|
|
|
}
|
2018-04-25 11:54:41 -07:00
|
|
|
|
2018-11-16 12:23:11 -07:00
|
|
|
const friendlyName = settings.getDevice(ieeeAddr).friendly_name;
|
|
|
|
|
2018-12-07 15:17:29 -07:00
|
|
|
mapping[mappedModel.model].forEach((config) => {
|
2018-11-16 12:23:11 -07:00
|
|
|
const topic = `${config.type}/${ieeeAddr}/${config.object_id}/config`;
|
|
|
|
const payload = {...config.discovery_payload};
|
|
|
|
payload.state_topic = `${settings.get().mqtt.base_topic}/${friendlyName}`;
|
|
|
|
payload.availability_topic = `${settings.get().mqtt.base_topic}/bridge/state`;
|
|
|
|
|
2018-12-07 15:13:20 -07:00
|
|
|
// Set (unique) name
|
|
|
|
payload.name = `${friendlyName}_${config.object_id}`;
|
2018-11-16 12:23:11 -07:00
|
|
|
|
2018-12-07 15:09:15 -07:00
|
|
|
// Set unique_id
|
|
|
|
payload.unique_id = `${ieeeAddr}_${config.object_id}_${settings.get().mqtt.base_topic}`;
|
2018-11-16 12:23:11 -07:00
|
|
|
|
2018-12-07 15:17:29 -07:00
|
|
|
// Attributes for device registry
|
|
|
|
payload.device = {
|
|
|
|
identifiers: `zigbee2mqtt_${ieeeAddr}`,
|
|
|
|
name: friendlyName,
|
|
|
|
sw_version: `Zigbee2mqtt ${zigbee2mqttVersion}`,
|
|
|
|
model: `${mappedModel.description} (${mappedModel.model})`,
|
|
|
|
manufacturer: mappedModel.vendor,
|
|
|
|
};
|
|
|
|
|
2018-11-16 12:23:11 -07:00
|
|
|
if (payload.command_topic) {
|
|
|
|
payload.command_topic = `${settings.get().mqtt.base_topic}/${friendlyName}/`;
|
2018-04-29 05:09:49 -07:00
|
|
|
|
2018-11-16 12:23:11 -07:00
|
|
|
if (payload.command_topic_prefix) {
|
|
|
|
payload.command_topic += `${payload.command_topic_prefix}/`;
|
|
|
|
}
|
|
|
|
|
|
|
|
payload.command_topic += 'set';
|
2018-04-29 05:09:49 -07:00
|
|
|
}
|
|
|
|
|
2018-11-16 12:23:11 -07:00
|
|
|
this.mqtt.publish(topic, JSON.stringify(payload), {retain: true, qos: 0}, null, 'homeassistant');
|
|
|
|
});
|
|
|
|
|
|
|
|
this.discovered[ieeeAddr] = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
onMQTTMessage(topic, message) {
|
|
|
|
if (!topic === 'hass/status') {
|
|
|
|
return false;
|
2018-04-25 11:54:41 -07:00
|
|
|
}
|
|
|
|
|
2018-11-16 12:23:11 -07:00
|
|
|
if (message.toString().toLowerCase() === 'online') {
|
|
|
|
const timer = setTimeout(() => {
|
|
|
|
// Publish all device states.
|
|
|
|
this.zigbee.getAllClients().forEach((device) => {
|
|
|
|
if (this.state.exists(device.ieeeAddr)) {
|
|
|
|
this.publishDeviceState(device, this.state.get(device.ieeeAddr), false);
|
|
|
|
}
|
|
|
|
});
|
2018-04-25 11:54:41 -07:00
|
|
|
|
2018-11-16 12:23:11 -07:00
|
|
|
clearTimeout(timer);
|
|
|
|
}, 20000);
|
|
|
|
}
|
2018-04-25 11:54:41 -07:00
|
|
|
|
2018-11-16 12:23:11 -07:00
|
|
|
return true;
|
2018-06-09 03:27:04 -07:00
|
|
|
}
|
|
|
|
|
2018-12-07 15:17:29 -07:00
|
|
|
onZigbeeMessage(message, device, mappedModel) {
|
|
|
|
if (device && mappedModel) {
|
|
|
|
this.discover(device.ieeeAddr, mappedModel);
|
2018-11-16 12:23:11 -07:00
|
|
|
}
|
|
|
|
}
|
2018-06-09 03:27:04 -07:00
|
|
|
|
2018-11-16 12:23:11 -07:00
|
|
|
// Only for homeassistant.test.js
|
|
|
|
_getMapping() {
|
|
|
|
return mapping;
|
|
|
|
}
|
2018-06-09 03:27:04 -07:00
|
|
|
}
|
|
|
|
|
2018-11-16 12:23:11 -07:00
|
|
|
module.exports = HomeAssistant;
|