UNPKG

iobroker.shelly

Version:
1,566 lines (1,513 loc) 223 kB
'use strict'; const shellyHelper = require('../shelly-helper'); /** * Naming convention (for new entries) * * devices are named like shelly components, i.e. Light, EM, PM1, ... * id follows componentname without seperator if component does not end with a number (Light - Light0, EM - EM0, ...) * id follows componentname with seperator ':' if component ends with a number (EM1 - EM1:0, ...) */ /** * Component Cover * https://shelly-api-docs.shelly.cloud/gen2/ComponentsAndServices/Cover * * Adds a generic cover definition for Gen 2+ devices * * @param deviceObj * @param coverId * @param hasSlat */ function addCover(deviceObj, coverId, hasSlat) { deviceObj[`Cover${coverId}.InitialState`] = { device_mode: 'cover', mqtt: { http_publish: `/rpc/Cover.GetConfig?id=${coverId}`, http_publish_funct: value => (value ? JSON.parse(value).initial_state : undefined), mqtt_cmd: '<mqttprefix>/rpc', mqtt_cmd_funct: (value, self) => { return JSON.stringify({ id: self.getNextMsgId(), src: 'iobroker', method: 'Cover.SetConfig', params: { id: coverId, config: { initial_state: value } }, }); }, }, common: { name: { en: 'Initial State', de: 'Initialer Zustand', ru: 'Начальное состояние', pt: 'Estado Inicial', nl: 'Initiële staat', fr: 'État initial', it: 'Stato iniziale', es: 'Estado inicial', pl: 'Stan początkowy', uk: 'Початковий стан', 'zh-cn': '初始状态', }, type: 'string', role: 'state', read: true, write: true, states: { open: 'open', closed: 'closed', stopped: 'stopped', }, }, }; deviceObj[`Cover${coverId}.ChannelName`] = { device_mode: 'cover', mqtt: { http_publish: `/rpc/Cover.GetConfig?id=${coverId}`, http_publish_funct: async (value, self) => { return value ? await shellyHelper.setChannelName(self, `Cover${coverId}`, JSON.parse(value).name) : undefined; }, mqtt_cmd: '<mqttprefix>/rpc', mqtt_cmd_funct: (value, self) => { return JSON.stringify({ id: self.getNextMsgId(), src: 'iobroker', method: 'Cover.SetConfig', params: { id: coverId, config: { name: value } }, }); }, }, common: { name: { en: 'Channel name', de: 'Kanalname', ru: 'Имя канала', pt: 'Nome do canal', nl: 'Kanaalnaam', fr: 'Nom du canal', it: 'Nome del canale', es: 'Nombre del canal', pl: 'Channel imię', 'zh-cn': '姓名', }, type: 'string', role: 'text', read: true, write: true, def: `cover_${coverId}`, }, }; deviceObj[`Cover${coverId}.Duration`] = { device_mode: 'cover', mqtt: { http_publish: `/rpc/Cover.GetConfig?id=${coverId}`, http_publish_funct: async (value, self) => { return await shellyHelper.getSetDuration(self, `Cover${coverId}.Duration`); }, }, common: { name: { en: 'Duration', de: 'Dauer', ru: 'Продолжительность', pt: 'Duração', nl: 'Vertaling:', fr: 'Durée', it: 'Durata', es: 'Duración', pl: 'Duracja', 'zh-cn': '期间', }, type: 'number', role: 'level.timer', read: true, write: true, def: 0, unit: 's', }, }; deviceObj[`Cover${coverId}.Open`] = { device_mode: 'cover', mqtt: { mqtt_cmd: '<mqttprefix>/rpc', mqtt_cmd_funct: async (value, self) => { const duration = await shellyHelper.getSetDuration(self, `Cover${coverId}.Duration`, 0); if (duration > 0) { return JSON.stringify({ id: self.getNextMsgId(), src: 'iobroker', method: 'Cover.Open', params: { id: coverId, duration: duration }, }); } return JSON.stringify({ id: self.getNextMsgId(), src: 'iobroker', method: 'Cover.Open', params: { id: coverId }, }); }, }, common: { name: { en: 'Open', de: 'Öffnen', ru: 'Открыть', pt: 'Abrir', nl: 'Open', fr: 'Ouvrir', it: 'Aprire', es: 'Abierto', pl: 'Otwarte', uk: 'ВІДЧИНЕНО', 'zh-cn': '打开', }, type: 'boolean', role: 'button', read: false, write: true, }, }; deviceObj[`Cover${coverId}.Stop`] = { device_mode: 'cover', mqtt: { mqtt_cmd: '<mqttprefix>/rpc', mqtt_cmd_funct: (value, self) => { return JSON.stringify({ id: self.getNextMsgId(), src: 'iobroker', method: 'Cover.Stop', params: { id: coverId }, }); }, }, common: { name: { en: 'Stop', de: 'Stoppen', ru: 'Останавливаться', pt: 'Parar', nl: 'Stop', fr: 'Arrêt', it: 'Fermare', es: 'Detener', pl: 'Zatrzymywać się', uk: 'СТІЙ', 'zh-cn': '停止', }, type: 'boolean', role: 'button', read: false, write: true, }, }; deviceObj[`Cover${coverId}.Close`] = { device_mode: 'cover', mqtt: { mqtt_cmd: '<mqttprefix>/rpc', mqtt_cmd_funct: async (value, self) => { const duration = await shellyHelper.getSetDuration(self, `Cover${coverId}.Duration`, 0); if (duration > 0) { return JSON.stringify({ id: self.getNextMsgId(), src: 'iobroker', method: 'Cover.Close', params: { id: coverId, duration: duration }, }); } return JSON.stringify({ id: self.getNextMsgId(), src: 'iobroker', method: 'Cover.Close', params: { id: coverId }, }); }, }, common: { name: { en: 'Close', de: 'Schließen', ru: 'Закрывать', pt: 'Fechar', nl: 'Dichtbij', fr: 'Fermer', it: 'Vicino', es: 'Cerca', pl: 'Zamknąć', uk: 'Закрити', 'zh-cn': '关闭', }, type: 'boolean', role: 'button', read: false, write: true, }, }; deviceObj[`Cover${coverId}.Calibrate`] = { device_mode: 'cover', mqtt: { mqtt_cmd: '<mqttprefix>/rpc', mqtt_cmd_funct: (value, self) => { return JSON.stringify({ id: self.getNextMsgId(), src: 'iobroker', method: 'Cover.Calibrate', params: { id: coverId }, }); }, }, common: { name: { en: 'Calibrate', de: 'Kalibrieren', ru: 'Калибровать', pt: 'Calibrar', nl: 'Kalibreren', fr: 'Étalonner', it: 'Calibrare', es: 'Calibrar', pl: 'Kalibrować', uk: 'Відкалібрувати', 'zh-cn': '校准', }, type: 'boolean', role: 'button', read: false, write: true, }, }; deviceObj[`Cover${coverId}.InputSwap`] = { device_mode: 'cover', mqtt: { http_publish: `/rpc/Cover.GetConfig?id=${coverId}`, http_publish_funct: value => (value ? JSON.parse(value).swap_inputs : undefined), mqtt_cmd: '<mqttprefix>/rpc', mqtt_cmd_funct: (value, self) => { return JSON.stringify({ id: self.getNextMsgId(), src: 'iobroker', method: 'Cover.SetConfig', params: { id: coverId, config: { swap_inputs: value } }, }); }, }, common: { name: { en: 'Input Swap', de: 'Eingang tauschen', ru: 'Входной обмен', pt: 'Troca de entrada', nl: 'Invoer wisselen', fr: "Échange d'entrée", it: 'Scambio di input', es: 'Intercambio de entrada', pl: 'Zamiana wejściowa', uk: 'Input Swap', 'zh-cn': '输入交换', }, type: 'boolean', role: 'switch.enable', read: true, write: true, }, }; deviceObj[`Cover${coverId}.InputMode`] = { device_mode: 'cover', mqtt: { http_publish: `/rpc/Cover.GetConfig?id=${coverId}`, http_publish_funct: value => (value ? JSON.parse(value).in_mode : undefined), mqtt_cmd: '<mqttprefix>/rpc', mqtt_cmd_funct: (value, self) => { return JSON.stringify({ id: self.getNextMsgId(), src: 'iobroker', method: 'Cover.SetConfig', params: { id: coverId, config: { in_mode: value } }, }); }, }, common: { name: { en: 'Input Mode', de: 'Eingangsmodus', ru: 'Режим ввода', pt: 'Modo de entrada', nl: 'Invoermodus', fr: 'Mode de saisie', it: 'Modalità di immissione', es: 'Modo de entrada', pl: 'Tryb wprowadzania', uk: 'Режим введення', 'zh-cn': '输入模式', }, type: 'string', role: 'state', read: true, write: true, states: { single: 'single', dual: 'dual', detached: 'detached', }, }, }; deviceObj[`Cover${coverId}.LimitPower`] = { device_mode: 'cover', mqtt: { http_publish: `/rpc/Cover.GetConfig?id=${coverId}`, http_publish_funct: value => (value ? JSON.parse(value).power_limit : undefined), mqtt_cmd: '<mqttprefix>/rpc', mqtt_cmd_funct: (value, self) => { return JSON.stringify({ id: self.getNextMsgId(), src: 'iobroker', method: 'Cover.SetConfig', params: { id: coverId, config: { power_limit: value } }, }); }, }, common: { name: { en: 'Power Limit', de: 'Leistungsbegrenzung', ru: 'Ограничение мощности', pt: 'Limite de potência', nl: 'Vermogenslimiet', fr: 'Limite de puissance', it: 'Limite di potenza', es: 'Límite de potencia', pl: 'Ograniczenie mocy', uk: 'Обмеження потужності', 'zh-cn': '功率限制', }, type: 'number', role: 'level.max', unit: 'W', read: true, write: true, }, }; deviceObj[`Cover${coverId}.LimitCurrent`] = { device_mode: 'cover', mqtt: { http_publish: `/rpc/Cover.GetConfig?id=${coverId}`, http_publish_funct: value => (value ? JSON.parse(value).current_limit : undefined), mqtt_cmd: '<mqttprefix>/rpc', mqtt_cmd_funct: (value, self) => { return JSON.stringify({ id: self.getNextMsgId(), src: 'iobroker', method: 'Cover.SetConfig', params: { id: coverId, config: { current_limit: value } }, }); }, }, common: { name: { en: 'Current Limit', de: 'Strombegrenzung', ru: 'Текущий предел', pt: 'Limite de corrente', nl: 'Huidige limiet', fr: 'Limite de courant', it: 'Limite di corrente', es: 'Límite de corriente', pl: 'Obecny limit', uk: 'Обмеження струму', 'zh-cn': '电流限制', }, type: 'number', role: 'level.current.max', unit: 'A', read: true, write: true, }, }; deviceObj[`Cover${coverId}.LimitVoltage`] = { device_mode: 'cover', mqtt: { http_publish: `/rpc/Cover.GetConfig?id=${coverId}`, http_publish_funct: value => (value ? JSON.parse(value).voltage_limit : undefined), mqtt_cmd: '<mqttprefix>/rpc', mqtt_cmd_funct: (value, self) => { return JSON.stringify({ id: self.getNextMsgId(), src: 'iobroker', method: 'Cover.SetConfig', params: { id: coverId, config: { voltage_limit: value } }, }); }, }, common: { name: { en: 'Voltage Limit', de: 'Spannungsbegrenzung', ru: 'Предел напряжения', pt: 'Limite de tensão', nl: 'Spanningslimiet', fr: 'Limite de tension', it: 'Limite di tensione', es: 'Límite de voltaje', pl: 'Ograniczenie napięcia', uk: 'Обмеження напруги', 'zh-cn': '电压限制', }, type: 'number', role: 'level.voltage.max', unit: 'V', read: true, write: true, }, }; deviceObj[`Cover${coverId}.Position`] = { device_mode: 'cover', mqtt: { mqtt_publish: `<mqttprefix>/status/cover:${coverId}`, mqtt_publish_funct: value => JSON.parse(value).current_pos, mqtt_cmd: '<mqttprefix>/rpc', mqtt_cmd_funct: (value, self) => { return JSON.stringify({ id: self.getNextMsgId(), src: 'iobroker', method: 'Cover.GoToPosition', params: { id: coverId, pos: value }, }); }, }, common: { name: { en: 'Current Position', de: 'Aktuelle Position', ru: 'Текущая позиция', pt: 'Posição atual', nl: 'Huidige positie', fr: 'Poste actuel', it: 'Posizione attuale', es: 'Posición actual', pl: 'Obecna pozycja', uk: 'Поточна позиція', 'zh-cn': '当前位置', }, type: 'number', role: 'level.blind', read: true, write: true, def: 0, unit: '%', min: 0, max: 100, }, }; deviceObj[`Cover${coverId}.TargetPosition`] = { device_mode: 'cover', mqtt: { mqtt_publish: `<mqttprefix>/status/cover:${coverId}`, mqtt_publish_funct: value => JSON.parse(value).target_pos, mqtt_cmd: '<mqttprefix>/rpc', mqtt_cmd_funct: (value, self) => { return JSON.stringify({ id: self.getNextMsgId(), src: 'iobroker', method: 'Cover.GoToPosition', params: { id: coverId, pos: value }, }); }, }, common: { name: { en: 'Target Position', de: 'Zielposition', ru: 'Целевая позиция', pt: 'Posição do alvo', nl: 'Doelpositie', fr: 'Position cible', it: 'Posizione di destinazione', es: 'Posición objetivo', pl: 'Pozycja docelowa', uk: 'Цільова позиція', 'zh-cn': '目标位置', }, type: 'number', role: 'level.blind', read: true, write: true, def: 0, unit: '%', min: 0, max: 100, }, }; deviceObj[`Cover${coverId}.Status`] = { device_mode: 'cover', mqtt: { mqtt_publish: `<mqttprefix>/status/cover:${coverId}`, mqtt_publish_funct: value => JSON.parse(value).state, }, common: { name: { en: 'Cover Status', de: 'Coverstatus', ru: 'Статус обложки', pt: 'Status da capa', nl: 'Dekkingsstatus', fr: 'Statut de la couverture', it: 'Stato di copertura', es: 'Estado de la cubierta', pl: 'Status okładki', uk: 'Статус обкладинки', 'zh-cn': '封面状态', }, type: 'string', role: 'state', read: true, write: false, }, }; deviceObj[`Cover${coverId}.Power`] = { device_mode: 'cover', mqtt: { mqtt_publish: `<mqttprefix>/status/cover:${coverId}`, mqtt_publish_funct: value => JSON.parse(value).apower, }, common: { name: { en: 'Power', de: 'Leistung', ru: 'Власть', pt: 'Poder', nl: 'Stroom', fr: 'Pouvoir', it: 'Energia', es: 'Fuerza', pl: 'Moc', uk: 'потужність', 'zh-cn': '力量', }, type: 'number', role: 'value.power', read: true, write: false, def: 0, unit: 'W', }, }; deviceObj[`Cover${coverId}.Voltage`] = { device_mode: 'cover', mqtt: { mqtt_publish: `<mqttprefix>/status/cover:${coverId}`, mqtt_publish_funct: value => JSON.parse(value).voltage, }, common: { name: { en: 'Voltage', de: 'Spannung', ru: 'Напряжение', pt: 'Tensão', nl: 'Voltage', fr: 'Tension', it: 'Tensione', es: 'Voltaje', pl: 'Voltage', 'zh-cn': '动产', }, type: 'number', role: 'value.voltage', read: true, write: false, def: 0, unit: 'V', }, }; deviceObj[`Cover${coverId}.Current`] = { device_mode: 'cover', mqtt: { mqtt_publish: `<mqttprefix>/status/cover:${coverId}`, mqtt_publish_funct: value => JSON.parse(value).current, }, common: { name: { en: 'Current', de: 'Stromstärke', ru: 'Сила тока', pt: 'Amperagem', nl: 'Amperage', fr: 'Intensité de courant', it: 'Amperaggio', es: 'Amperaje', pl: 'Natężenie w amperach', uk: 'Сила струму', 'zh-cn': '安培数', }, type: 'number', role: 'value.current', read: true, write: false, def: 0, unit: 'A', }, }; deviceObj[`Cover${coverId}.Energy`] = { device_mode: 'cover', mqtt: { mqtt_publish: `<mqttprefix>/status/cover:${coverId}`, mqtt_publish_funct: value => JSON.parse(value).aenergy?.total, }, common: { name: { en: 'Energy', de: 'Energie', ru: 'Энергия', pt: 'Energia', nl: 'Energie', fr: 'Énergie', it: 'Energia', es: 'Energía', pl: 'Energia', uk: 'Енергія', 'zh-cn': '活力', }, type: 'number', role: 'value.energy', read: true, write: false, def: 0, unit: 'Wh', }, }; deviceObj[`Cover${coverId}.source`] = { device_mode: 'cover', mqtt: { mqtt_publish: `<mqttprefix>/status/cover:${coverId}`, mqtt_publish_funct: value => JSON.parse(value).source, }, common: { name: { en: 'Source of last command', de: 'Quelle des letzten Befehls', ru: 'Источник последней команды', pt: 'Fonte do último comando', nl: 'Vertaling:', fr: 'Source de la dernière commande', it: "Fonte dell'ultimo comando", es: 'Fuente del último comando', pl: 'Źródło ostatniego dowództwa', 'zh-cn': '最后一次指挥的来源', }, type: 'string', role: 'text', read: true, write: false, }, }; deviceObj[`Cover${coverId}.temperatureC`] = { device_mode: 'cover', mqtt: { mqtt_publish: `<mqttprefix>/status/cover:${coverId}`, mqtt_publish_funct: value => JSON.parse(value).temperature.tC, }, common: { name: { en: 'Temperature', de: 'Temperatur', ru: 'Температура', pt: 'Temperatura', nl: 'Temperatuur', fr: 'Température', it: 'Temperatura', es: 'Temperatura', pl: 'Temperatura', 'zh-cn': '模范', }, type: 'number', role: 'value.temperature', read: true, write: false, unit: '°C', }, }; deviceObj[`Cover${coverId}.temperatureF`] = { device_mode: 'cover', mqtt: { mqtt_publish: `<mqttprefix>/status/cover:${coverId}`, mqtt_publish_funct: value => JSON.parse(value).temperature.tF, }, common: { name: { en: 'Temperature', de: 'Temperatur', ru: 'Температура', pt: 'Temperatura', nl: 'Temperatuur', fr: 'Température', it: 'Temperatura', es: 'Temperatura', pl: 'Temperatura', 'zh-cn': '模范', }, type: 'number', role: 'value.temperature', read: true, write: false, unit: '°F', }, }; deviceObj[`Cover${coverId}.PosControl`] = { device_mode: 'cover', mqtt: { mqtt_publish: `<mqttprefix>/status/cover:${coverId}`, mqtt_publish_funct: value => JSON.parse(value).pos_control, }, common: { name: { en: 'positioncontrol supported', de: 'Positionsregelung unterstützt', ru: 'поддерживается позиционное управление', pt: 'controle de posição suportado', nl: 'positiecontrole ondersteund', fr: 'contrôle de position pris en charge', it: 'controllo della posizione supportato', es: 'control de posición compatible', pl: 'obsługa kontroli położenia', uk: 'підтримується керування положенням', 'zh-cn': '支持位置控制', }, type: 'boolean', role: 'indicator', read: true, write: false, }, }; // Favorites support: // http://<shell-ip>/rpc/Shelly.GetConfig // "sys": { // "ui_data": { // "cover": "12,80,60", // ... deviceObj[`Cover${coverId}.FavoritePos1.Pos`] = { device_mode: 'cover', mqtt: { http_publish: `/rpc/Shelly.GetConfig`, http_publish_funct: async (value, _self) => { const ui = JSON.parse(value).sys?.ui_data?.cover; //self.adapter.log.debug(`ui: ${ui}`); return ui === undefined ? null : ui.split(',')[0]; }, }, common: { name: 'Position', type: 'number', role: 'level.blind', read: true, write: false, unit: '%', min: 0, max: 100, }, }; deviceObj[`Cover${coverId}.FavoritePos2.Pos`] = { device_mode: 'cover', mqtt: { http_publish: `/rpc/Shelly.GetConfig`, http_publish_funct: async (value, _self) => { const ui = JSON.parse(value).sys?.ui_data?.cover; return ui === undefined ? null : ui.split(',')[1]; }, }, common: { name: 'Position', type: 'number', role: 'level.blind', read: true, write: false, unit: '%', min: 0, max: 100, }, }; deviceObj[`Cover${coverId}.FavoritePos3.Pos`] = { device_mode: 'cover', mqtt: { http_publish: `/rpc/Shelly.GetConfig`, http_publish_funct: async (value, _self) => { const ui = JSON.parse(value).sys?.ui_data?.cover; return ui === undefined ? null : ui.split(',')[2]; }, }, common: { name: 'Position', type: 'number', role: 'level.blind', read: true, write: false, unit: '%', min: 0, max: 100, }, }; deviceObj[`Cover${coverId}.FavoritePos1.GoTo`] = { device_mode: 'cover', mqtt: { mqtt_cmd: '<mqttprefix>/rpc', mqtt_cmd_funct: async (_value, self) => { const pos = await shellyHelper.getState(self, `Cover${coverId}.FavoritePos1.Pos`); return pos === undefined ? undefined : JSON.stringify({ id: self.getNextMsgId(), src: 'iobroker', method: 'Cover.GoToPosition', params: { id: coverId, pos: pos }, }); }, }, common: { name: 'Set favorite position', type: 'boolean', role: 'button', read: false, write: true, }, }; deviceObj[`Cover${coverId}.FavoritePos2.GoTo`] = { device_mode: 'cover', mqtt: { mqtt_cmd: '<mqttprefix>/rpc', mqtt_cmd_funct: async (_value, self) => { const pos = await shellyHelper.getState(self, `Cover${coverId}.FavoritePos2.Pos`); return pos === undefined ? undefined : JSON.stringify({ id: self.getNextMsgId(), src: 'iobroker', method: 'Cover.GoToPosition', params: { id: coverId, pos: pos }, }); }, }, common: { name: 'Set favorite position', type: 'boolean', role: 'button', read: false, write: true, }, }; deviceObj[`Cover${coverId}.FavoritePos3.GoTo`] = { device_mode: 'cover', mqtt: { mqtt_cmd: '<mqttprefix>/rpc', mqtt_cmd_funct: async (_value, self) => { const pos = await shellyHelper.getState(self, `Cover${coverId}.FavoritePos3.Pos`); return pos === undefined ? undefined : JSON.stringify({ id: self.getNextMsgId(), src: 'iobroker', method: 'Cover.GoToPosition', params: { id: coverId, pos: _value }, }); }, }, common: { name: 'Set favorite position', type: 'boolean', role: 'button', read: false, write: true, }, }; if (hasSlat) { deviceObj[`Cover${coverId}.SlatPos`] = { device_mode: 'cover', mqtt: { mqtt_publish: `<mqttprefix>/status/cover:${coverId}`, mqtt_publish_funct: value => JSON.parse(value).slat_pos != undefined ? JSON.parse(value).slat_pos : null, mqtt_cmd: '<mqttprefix>/rpc', mqtt_cmd_funct: (value, self) => { return JSON.stringify({ id: self.getNextMsgId(), src: 'iobroker', method: 'Cover.GoToPosition', params: { id: coverId, slat_pos: value }, }); }, }, common: { name: { en: 'slat position', de: 'Lamellenposition', ru: 'положение планки', pt: 'posição das ripas', nl: 'latpositie', fr: 'position des lattes', it: 'posizione della stecca', es: 'posición de la lama', pl: 'pozycja listew', uk: 'положення ламелі', 'zh-cn': '缝翼位置', }, type: 'number', role: 'value', read: true, write: true, min: 0, max: 100, unit: '%', }, }; } } /** * Component EM * https://shelly-api-docs.shelly.cloud/gen2/ComponentsAndServices/EM * * Adds a generic energymeter definition for Gen 2+ devices * * @param deviceObj * @param emId * @param phases */ function addEM(deviceObj, emId, phases) { deviceObj[`EM${emId}.ChannelName`] = { device_mode: 'triphase', mqtt: { http_publish: `/rpc/EM.GetConfig?id=${emId}`, http_publish_funct: async (value, self) => { return value ? await shellyHelper.setChannelName(self, `EM${emId}`, JSON.parse(value).name) : undefined; }, mqtt_cmd: '<mqttprefix>/rpc', mqtt_cmd_funct: (value, self) => { return JSON.stringify({ id: self.getNextMsgId(), src: 'iobroker', method: 'EM.SetConfig', params: { id: emId, config: { name: value } }, }); }, }, common: { name: { en: 'Channel name', de: 'Kanalname', ru: 'Имя канала', pt: 'Nome do canal', nl: 'Kanaalnaam', fr: 'Nom du canal', it: 'Nome del canale', es: 'Nombre del canal', pl: 'Channel imię', 'zh-cn': '姓名', }, type: 'string', role: 'text', read: true, write: true, }, }; deviceObj[`EM${emId}.CurrentN`] = { device_mode: 'triphase', mqtt: { mqtt_publish: `<mqttprefix>/status/em:${emId}`, mqtt_publish_funct: value => { return JSON.parse(value)[`n_current`]; }, }, common: { name: { en: 'Current N', de: 'Stromstärke N', ru: 'Сила тока N', pt: 'Amperagem N', nl: 'Amperage N', fr: 'Ampérage N', it: 'Amperaggio N', es: 'Amperaje N', pl: 'Natężenie prądu N', uk: 'Сила струму Н', 'zh-cn': '安培数 N', }, type: 'number', role: 'value.current', read: true, write: false, def: 0, unit: 'A', }, }; deviceObj[`EM${emId}.TotalCurrent`] = { device_mode: 'triphase', mqtt: { mqtt_publish: `<mqttprefix>/status/em:${emId}`, mqtt_publish_funct: value => { return JSON.parse(value)[`total_current`]; }, }, common: { name: { en: 'Total Current', de: 'Gesamtstromstärke', ru: 'Общий ток', pt: 'Corrente total', nl: 'Totale stroom', fr: 'Courant total', it: 'Corrente totale', es: 'Corriente total', pl: 'Całkowity prąd', uk: 'Загальний струм', 'zh-cn': '总电流', }, type: 'number', role: 'value.current', read: true, write: false, def: 0, unit: 'A', }, }; deviceObj[`EM${emId}.TotalActivePower`] = { device_mode: 'triphase', mqtt: { mqtt_publish: `<mqttprefix>/status/em:${emId}`, mqtt_publish_funct: value => { return JSON.parse(value)[`total_act_power`]; }, }, common: { name: { en: 'Total Active Power', de: 'Gesamtwirkleistung', ru: 'Общая активная мощность', pt: 'Potência Ativa Total', nl: 'Totaal actief vermogen', fr: 'Puissance active totale', it: 'Potenza attiva totale', es: 'Potencia activa total', pl: 'Całkowita moc czynna', uk: 'Загальна активна потужність', 'zh-cn': '总有功功率', }, type: 'number', role: 'value.power.active', read: true, write: false, def: 0, unit: 'W', }, }; deviceObj[`EM${emId}.TotalApparentPower`] = { device_mode: 'triphase', mqtt: { mqtt_publish: `<mqttprefix>/status/em:${emId}`, mqtt_publish_funct: value => { return JSON.parse(value)[`total_aprt_power`]; }, }, common: { name: { en: 'Total Apparent Power', de: 'Gesamtscheinleistung', ru: 'Общая кажущаяся мощность', pt: 'Potência aparente total', nl: 'Totaal schijnbaar vermogen', fr: 'Puissance apparente totale', it: 'Potenza apparente totale', es: 'Potencia aparente total', pl: 'Całkowita moc pozorna', uk: 'Загальна видима потужність', 'zh-cn': '总视在功率', }, type: 'number', role: 'value.power', read: true, write: false, def: 0, unit: 'VA', }, }; for (const phase of phases) { const phaseUp = String(phase).toUpperCase(); deviceObj[`EM${emId}.Voltage${phaseUp}`] = { device_mode: 'triphase', mqtt: { mqtt_publish: `<mqttprefix>/status/em:${emId}`, mqtt_publish_funct: value => { return JSON.parse(value)[`${phase}_voltage`]; }, }, common: { name: { en: 'Voltage', de: 'Spannung', ru: 'Напряжение', pt: 'Tensão', nl: 'Voltage', fr: 'Tension', it: 'Tensione', es: 'Voltaje', pl: 'Voltage', 'zh-cn': '动产', }, type: 'number', role: 'value.voltage', read: true, write: false, def: 0, unit: 'V', }, }; deviceObj[`EM${emId}.Current${phaseUp}`] = { device_mode: 'triphase', mqtt: { mqtt_publish: `<mqttprefix>/status/em:${emId}`, mqtt_publish_funct: value => { return JSON.parse(value)[`${phase}_current`]; }, }, common: { name: { en: 'Current', de: 'Stromstärke', ru: 'Сила тока', pt: 'Amperagem', nl: 'Amperage', fr: 'Intensité de courant', it: 'Amperaggio', es: 'Amperaje', pl: 'Natężenie w amperach', uk: 'Сила струму', 'zh-cn': '安培数', }, type: 'number', role: 'value.current', read: true, write: false, def: 0, unit: 'A', }, }; deviceObj[`EM${emId}.ActivePower${phaseUp}`] = { device_mode: 'triphase', mqtt: { mqtt_publish: `<mqttprefix>/status/em:${emId}`, mqtt_publish_funct: value => { return JSON.parse(value)[`${phase}_act_power`]; }, }, common: { name: { en: 'Active Power', de: 'Wirkleistung', ru: 'Активная мощность', pt: 'Potência Ativa', nl: 'Actief vermogen', fr: 'Puissance active', it: 'Potenza attiva', es: 'Potencia activa', pl: 'Moc czynna', uk: 'Активна потужність', 'zh-cn': '有功功率', }, type: 'number', role: 'value.power.active', read: true, write: false, def: 0, unit: 'W', }, }; deviceObj[`EM${emId}.ApparentPower${phaseUp}`] = { device_mode: 'triphase', mqtt: { mqtt_publish: `<mqttprefix>/status/em:${emId}`, mqtt_publish_funct: value => { return JSON.parse(value)[`${phase}_aprt_power`]; }, }, common: { name: { en: 'Apparent Power', de: 'Scheinleistung', ru: 'Кажущаяся мощность', pt: 'Poder Aparente', nl: 'Schijnbare kracht', fr: 'Puissance apparente', it: 'Potenza apparente', es: 'Potencia aparente', pl: 'Moc pozorna', uk: 'Видима потужність', 'zh-cn': '视在功率', }, type: 'number', role: 'value.power', read: true, write: false, def: 0, unit: 'VA', }, }; deviceObj[`EM${emId}.PowerFactor${phaseUp}`] = { device_mode: 'triphase', mqtt: { mqtt_publish: `<mqttprefix>/status/em:${emId}`, mqtt_publish_funct: value => { return JSON.parse(value)[`${phase}_pf`]; }, }, common: { name: { en: 'Power Factor', de: 'Leistungsfaktor', ru: 'Коэффициент мощности', pt: 'Fator de potência', nl: 'Vermogensfactor', fr: 'Facteur de puissance', it: 'Fattore di potenza', es: 'Factor de potencia', pl: 'Współczynnik mocy', uk: 'Фактор потужності', 'zh-cn': '功率因数', }, type: 'number', role: 'value', read: true, write: false, def: 0, }, }; } } /** * Component EMData * https://shelly-api-docs.shelly.cloud/gen2/ComponentsAndServices/EMData * * Adds a generic energymeter data definition for Gen 2+ devices * * @param deviceObj * @param emId * @param phases */ function addEMData(deviceObj, emId, phases) { deviceObj[`EMData${emId}.ResetCounters`] = { device_mode: 'triphase', mqtt: { //http_publish: `/rpc/Input.GetConfig?id=${pmId}`, //http_publish_funct: value => (value ? JSON.parse(value).type : undefined), mqtt_cmd: '<mqttprefix>/rpc', mqtt_cmd_funct: (value, self) => { return JSON.stringify({ id: self.getNextMsgId(), src: 'iobroker', method: 'EMData.ResetCounters', params: { id: emId }, }); }, }, common: { name: { en: 'Reset counters', de: 'Zähler zurücksetzen', ru: 'Сбросить счетчик', pt: 'Reiniciar contador', nl: 'Teller resetten', fr: 'Réinitialiser le compteur', it: 'Azzera contatore', es: 'Reiniciar contador', pl: 'Zresetuj licznik', uk: 'Скинути лічильник', 'zh-cn': '重置计数器', }, type: 'boolean', role: 'button', read: false, write: true, }, }; deviceObj[`EMData${emId}.TotalActiveEnergy`] = { device_mode: 'triphase', mqtt: { mqtt_publish: `<mqttprefix>/status/emdata:${emId}`, mqtt_publish_funct: value => { return JSON.parse(value)[`total_act`]; }, }, common: { name: { en: 'Total Energy', de: 'Gesamtenergie', ru: 'Общая энергия', pt: 'Energia Total', nl: 'Totale energie', fr: 'Énergie totale', it: 'Energia totale', es: 'Energía total', pl: 'Całkowita energia', uk: 'Загальна енергія', 'zh-cn': '总能量', }, type: 'number', role: 'value.energy.consumed', read: true, write: false, def: 0, unit: 'Wh', }, }; deviceObj[`EMData${emId}.TotalActiveReturnEnergy`] = { device_mode: 'triphase', mqtt: { mqtt_publish: `<mqttprefix>/status/emdata:${emId}`, mqtt_publish_funct: value => { return JSON.parse(value)[`total_act_ret`]; }, }, common: { name: { en: 'Total Returned Energy', de: 'Gesamte zurückgegebene Energie', ru: 'Общая возвращенная энергия', pt: 'Energia Total Retornada', nl: 'Totaal teruggegeven energie', fr: 'Énergie totale restituée', it: 'Energia totale restituita', es: 'Energía total devuelta', pl: 'Całkowita zwrócona energia', uk: 'Загальна повернута енергія', 'zh-cn': '总回馈能量', }, type: 'number', role: 'value.energy.produced', read: true, write: false, def: 0, unit: 'Wh', }, }; for (const phase of phases) { const phaseUp = String(phase).toUpperCase(); deviceObj[`EMData${emId}.TotalActiveEnergy${phaseUp}`] = { device_mode: 'triphase', mqtt: { mqtt_publish: `<mqttprefix>/status/emdata:${emId}`, mqtt_publish_funct: value => { return JSON.parse(value)[`${phase}_total_act_energy`]; }, }, common: { name: { en: 'Energy', de: 'Energie', ru: 'Энергия', pt: 'Energia', nl: 'Energie', fr: 'Énergie', it: 'Energia', es: 'Energía', pl: 'Energia', uk: 'Енергія', 'zh-cn': '活力', }, type: 'number', role: 'value.energy.consumed', read: true, write: false, def: 0, unit: 'Wh', }, }; deviceObj[`EMData${emId}.TotalActiveReturnEnergy${phaseUp}`] = { device_mode: 'triphase', mqtt: { mqtt_publish: `<mqttprefix>/status/emdata:${emId}`, mqtt_publish_funct: value => { return JSON.parse(value)[`${phase}_total_act_ret_energy`]; }, }, common: { name: { en: 'Returned Energy', de: 'Zurückgegebene Energie', ru: 'Возвращенная энергия', pt: 'Energia Retornada', nl: 'Teruggegeven energie', fr: 'Énergie restituée', it: 'Energia restituita', es: 'Energía devuelta', pl: 'Zwrócona energia', uk: 'Повернена енергія', 'zh-cn': '回馈能量', }, type: 'number', role: 'value.energy.produced', read: true, write: false, def: 0, unit: 'Wh', }, }; } } /** * Component EM1 * https://shelly-api-docs.shelly.cloud/gen2/ComponentsAndServices/EM1 * * Adds a generic energymeter definition for Gen 2+ devices * * @param deviceObj * @param emId * @param addEM1Data * * NOTE: * For new devices every component should be added individually. addEM1Data is only present for backwards compatibility */ function addEM1(deviceObj, emId, addEM1Data) { deviceObj[`EM1:${emId}.Power`] = { device_mode: 'monophase', mqtt: { mqtt_publish: `<mqttprefix>/status/em1:${emId}`, mqtt_publish_funct: value => JSON.parse(value).act_power, }, common: { name: { en: 'Active Power', de: 'Wirkleistung', ru: 'Активная мощность', pt: 'Potência Ativa', nl: 'Actief vermogen', fr: 'Puissance active', it: 'Potenza attiva', es: 'Potencia activa', pl: 'Moc czynna', uk: 'Активна потужність', 'zh-cn': '有功功率', }, type: 'number', role: 'value.power.active', read: true, write: false, def: 0, unit: 'W', }, }; deviceObj[`EM1:${emId}.Voltage`] = { device_mode: 'monophase', mqtt: { mqtt_publish: `<mqttprefix>/status/em1:${emId}`, mqtt_publish_funct: value => JSON.parse(value).voltage, }, common: { name: { en: 'Voltage', de: 'Spannung', ru: 'Напряжение', pt: 'Tensão', nl: 'Voltage', fr: 'Tension', it: 'Tensione', es: 'Voltaje', pl: 'Voltage', 'zh-cn': '动产', }, type: 'number', role: 'value.voltage', read: tru