• Du musst dich registrieren, bevor du Beiträge verfassen kannst. Klicke auf Jetzt registrieren!, um den Registrierungsprozess zu starten. Registrierte User surfen werbefrei, können Suchen durchführen und sehen die volle Darstellung des Forums!!!

WlanThermo Mini V2 mit ESP32 in Smarthome einbinden

Markus7501

Veganer
Hallo,
Da der iobroker Adapter für das Nano nicht mit den Mini V2 mit ESP32 funktioniert, habe ich mal ein Script erstellt, welches die Daten vom MQTT Server ausliest und bereit stellt.
derzeit nur

So sieht es im IOBROKER bei den Objekten aus:

0051484C-CE95-4CF0-AB85-7F72BD888BBD.png


024A132F-0415-4A24-BF99-27D32CB9793F.png


Folgendes muss im Script an eure Gegebenheiten angepasst werden.

var device = "MINI-2xxxxxxxxxx"; //Name Mini
var pathmqtt = "mqtt.0.WLanThermo."; //MQTT Name
var pathdata = pathmqtt + device + ".status.data"; //MQTT volständiger Pfad
var pathjs = "javascript.0.Grill."; //genera iobroker path
var pathChannels = pathjs + device + ".channel"; // path to store chanels
var pathPitmaster = pathjs + device + ".pitmaster"; // path to store pitmaster
var pathSettings= pathjs + device +".settings"; // settings path in iobroiker
var pitmaster_connected = 2 ; // number of connected Pitmaster modules
var max_chanels = 12; // anzahl der verfügbaren Kanäle

Hier das ganze Script (leider lässt sich die Datei nicht Hochladen):

//Init
//1. Benötigte Variabelen als Einstellungen, weden später in einer Variabelen geseiuchert und können zur Laufzeit verändert werden
var device = "MINI-2462abc32738"; //Name Mini
var pathmqtt = "mqtt.0.WLanThermo."; //MQTT Name
var pathdata = pathmqtt + device + ".status.data"; //MQTT volständiger Pfad
var pathjs = "javascript.0.Grill."; //genera iobroker path
var pathChannels = pathjs + device + ".channel"; // path to store chanels
var pathPitmaster = pathjs + device + ".pitmaster"; // path to store pitmaster
var pathSettings= pathjs + device +".settings"; // settings path in iobroiker
var pitmaster_connected = 2 ; // number of connected Pitmaster modules
var max_chanels = 12; // anzahl der verfügbaren Kanäle
var debug = false ; // debug write infos

// save Settings
createState(pathSettings +'.device', device, {type: 'string',name: 'Grill.0.Settings.device'});
createState(pathSettings +'.pathmqtt', pathmqtt, {type: 'string',name: 'Grill.0.Settings.pathmqtt'});
createState(pathSettings +'.fullpath', pathdata, {type: 'string',name: 'Grill.0.Settings.fullpath'});
createState(pathSettings +'.pathjs', pathjs, {type: 'string',name: 'Grill.0.Settings.pathjs'});
createState(pathSettings +'.pathChannels', pathChannels, {type: 'string',name: 'Grill.0.Settings.pathChannels'});
createState(pathSettings +'.pathPitmaster', pathPitmaster, {type: 'string',name: 'Grill.0.Settings.pathPitmaster'});
createState(pathSettings +'.max_chanels', max_chanels, {type: 'int',name: 'Grill.0.Settings.max_chanels'});

//2. Alle Kanäle autonmatisch anlegen.

function create_varaiables (debug, max_chanels,pitmaster_connected)

{
var variab =`${pathChannels}.${max_chanels}.alarm`;

if (debug == true){ log ("Check variabels");log("Varaib12Alarm is :" + (getState(variab).val)); log ("variab is :" + variab);}
//Prüfen ob alle Variabelen schon existieren, wennn nicht neu anlegen
if ((getState(variab).val)==null)
{
if (debug == true){ log ("Varaib 12 not found, create all");}
//Variabelen anlegen für max 12 Kanäle ( je nach definition oben)
for (var i = 0; i < max_chanels; i++)
{


createState(`${pathChannels}.${i+1}.alarm`, 0, {type: 'number',name: `${pathChannels}.${i+1}.alarm`});
createState(`${pathChannels}.${i+1}.temp_min`, 0, {type: 'number',name: `${pathChannels}.${i+1}.temp_min`});
createState(`${pathChannels}.${i+1}.temp_max`, 0, {type: 'number',name: `${pathChannels}.${i+1}.temp_max`});
createState(`${pathChannels}.${i+1}.actual_temp`, 0, {type: 'number',name: `${pathChannels}.${i+1}.actual_temp`});
createState(`${pathChannels}.${i+1}.color`, 0, {type: 'string',name: `${pathChannels}.${i+1}.color`});
createState(`${pathChannels}.${i+1}.type`, 0, {type: 'number',name: `${pathChannels}.${i+1}.type`});
createState(`${pathChannels}.${i+1}.connected`, false, {type: 'boolean',name: `${pathChannels}.${i+1}.connected`});
createState(`${pathChannels}.${i+1}.fixed`, false, {type: 'boolean',name: `${pathChannels}.${i+1}.fixed`});
createState(`${pathChannels}.${i+1}.name`, "name", {type: 'string',name: `${pathChannels}.${i+1}.name`});
}
}


// Variabelen für den Pitmaster
var variab =`${pathPitmaster}.${pitmaster_connected}.status`;
if ((getState(variab).val)==null)
{
for (var i = 0; i < pitmaster_connected; i++)
{


createState(`${pathPitmaster}.${i+1}.pitmaster`, 0, {type: 'number',name: `${pathPitmaster}.${i+1}.pitmaster`});
createState(`${pathPitmaster}.${i+1}.connected_chanel`, 0, {type: 'number',name: `${pathPitmaster}.${i+1}.connected_chanel`});
createState(`${pathPitmaster}.${i+1}.pid`, 0, {type: 'number',name: `${pathPitmaster}.${i+1}.pid`});
createState(`${pathPitmaster}.${i+1}.current_value`, 0, {type: 'number',name: `${pathPitmaster}.${i+1}.current_value`});
createState(`${pathPitmaster}.${i+1}.set_temp`, 0, {type: 'number',name: `${pathPitmaster}.${i+1}.set_temp`});
createState(`${pathPitmaster}.${i+1}.status`, "0", {type: 'string',name: `${pathPitmaster}.${i+1}.status`});
createState(`${pathPitmaster}.${i+1}.set_color`, "0", {type: 'string',name: `${pathPitmaster}.${i+1}.set_color`});
createState(`${pathPitmaster}.${i+1}.value_color`, "0", {type: 'string',name: `${pathPitmaster}.${i+1}.value_color`});
}

}

}



function read_vaues_and_set (debug, max_chanels, pitmaster)
{ // Werte aus MQTT lesen und in alle Kanäle ( max 12 Schreiben)
//log ("pathdata is :" + pathdata);
// log (getState(pathdata).val);

try {
jr = JSON.parse(getState(pathdata).val);
}
catch (e) {
console.error('Cannot parse: ' + getState(pathdata).val);
return;
}

// Werte auslesen und ablegen für die Kanäle
for (var i = 0; i < max_chanels; i++) {

setState(`${pathChannels}.${i+1}.actual_temp`, (jr.channel.temp));
setState(`${pathChannels}.${i+1}.name`, (jr.channel.name));
setState(`${pathChannels}.${i+1}.temp_min`, (jr.channel.min));
setState(`${pathChannels}.${i+1}.temp_max`, (jr.channel.max));
setState(`${pathChannels}.${i+1}.type`, (jr.channel.typ));
setState(`${pathChannels}.${i+1}.alarm`, (jr.channel.alarm));
setState(`${pathChannels}.${i+1}.color`, (jr.channel.color));
setState(`${pathChannels}.${i+1}.connected`, (jr.channel.connected));
setState(`${pathChannels}.${i+1}.fixed`, (jr.channel.fixed));
}


if (debug == true) {console.log('Data ausgelesen');}

}


function read_pid_and_set (debug, max_chanels, pitmaster)
{ // Werte aus MQTT lesen und in alle Kanäle ( max 12 Schreiben)
//log ("pathdata is :" + pathdata);
// log (getState(pathdata).val);

try {
jr = JSON.parse(getState(pathdata).val);
}
catch (e) {
console.error('Cannot parse: ' + getState(pathdata).val);
return;
}

//Werte Auslesen für die Pitmaster ! Mini V1 = 1 Mini V2 = 2
for (var i = 0; i < 2; i++)
{

setState(`${pathPitmaster}.${i+1}.pitmaster`, (jr.pitmaster.pm.id));
setState(`${pathPitmaster}.${i+1}.connected_chanel`, (jr.pitmaster.pm.channel));
setState(`${pathPitmaster}.${i+1}.pid`, (jr.pitmaster.pm.pid));
setState(`${pathPitmaster}.${i+1}.current_value`, (jr.pitmaster.pm.value));
setState(`${pathPitmaster}.${i+1}.set_temp`, (jr.pitmaster.pm.set));
setState(`${pathPitmaster}.${i+1}.status`, (jr.pitmaster.pm.typ));
setState(`${pathPitmaster}.${i+1}.set_color`, (jr.pitmaster.pm.set_color));
setState(`${pathPitmaster}.${i+1}.value_color`, (jr.pitmaster.pm.value_color));

}
if (debug == true) {console.log('Data ausgelesen');}

}



function main(debug)
{ log ("debug is :" + debug)
create_varaiables(debug, max_chanels,pitmaster_connected);
read_vaues_and_set(debug, max_chanels, pitmaster_connected);
read_pid_and_set(debug, max_chanels, pitmaster_connected);
}
//Event based start
on({id: pathdata, change: "any"}, function (obj) {
main(debug);
});
 
Oben Unten