Здравствуйте!
Я использую вот такой конвертер на wb-rules, написанный родственником:
tasmota.js
// Указание объекта имен, с ключами в виде id устройств.
var maxWaitTime = 330;
var config = {
'tasmota_4914DB': 'name1', //сюда пишете свое название для устройства
'tasmota_0B21F7': 'name2',
'tasmota_3213B6': 'name3',
'tasmota_4248ED': 'name4',
'tasmota_B56D2A': 'name4'
};
// Указание объекта значений, с ключами в виде адресов, значения в формате: [value, type, canEdit]
var map = {
'POWER': ['k1', 'switch'],
'POWER1': ['k1', 'switch'],
'POWER2': ['k2', 'switch'],
'POWER3': ['k3', 'switch'],
'POWER4': ['k4', 'switch'],
'AM2301.Temperature': ['temperature', 'temperature'],
'AM2301.Humidity': ['humidity', 'rel_humidity'],
'MHZ19B.CarbonDioxide': ['co2', 'concentration'],
'StatusNET.IPAddress': ['ip'],
'Info2.IPAddress': ['ip'],
'LWT': ['status', 'switch', false],
};
var controls = {};
// управляем контролом
var waitTimeout = {};
function setData(device, controlName, value) {
var el = map[controlName];
if(!el) return;
var key = device.getId() + '/' + el[0];
controls[key] = controlName;
if(el[1] === 'switch') {
if(el[2] !== false) el[2] = true;
value = ['ON', 'on', 'Online'].indexOf(value) > -1;
}
if(!getControl(key)) {
device.addControl(el[0], {
type: el[1] || "text",
value: value,
readonly: !el[2],
});
if(el[2]) defineRule(key, {
whenChanged: key,
then: function (newValue, cellName, controlName) {
var key = cellName + '/' + controlName;
if(el[1] === 'switch') newValue = newValue ? 'on' : 'off';
publish('cmnd/' + cellName + '/' + controls[key], newValue);
}
});
}
if(dev[key] != value) {
if(!waitTimeout[key]) {
dev[key] = value;
waitTimeout[key] = setTimeout(function(){
waitTimeout[key] = false;
}, 300);
}
}
}
var statusTimeouts = {};
// обрабатываем все устройства
for(var deviceCode in config) {
var device = defineVirtualDevice(deviceCode, {
title: config[deviceCode],
cells: {}
});
trackMqtt('+/' + deviceCode + '/#', function(message){
var parse = message.topic.split('/');
device = getDevice(parse[1]);
try {
var data = JSON.parse(message.value);
if(typeof data === 'object') {
if(data.StatusSNS) data = data.StatusSNS;
if(data.StatusSTS) data = data.StatusSTS;
for(var key in data) {
if(typeof data[key] === 'object')
for(var name in data[key]) {
setData(device, key + '.' + name, data[key][name]);
}
else
setData(device, key, data[key]);
}
}
if(statusTimeouts[device.getId()]) clearTimeout(statusTimeouts[device.getId()]);
statusTimeouts[device.getId()] = setTimeout(function(){
setData(device, 'LWT', 0);
}, maxWaitTime * 1000)
} catch(e) {
if(message.value) setData(device, parse[2], message.value);
}
});
// устанавливаем системное время на tasmota
publish('cmnd/' + deviceCode + '/Time', Date.now() / 1000);
publish('cmnd/' + deviceCode + '/Timezone',(new Date).getHours() - (new Date).getUTCHours());
// инифиируем параметры tasmota
publish('cmnd/' + deviceCode + '/Status', '0');
}