NEWS
Bitte um Hilfe bei MQTT zerlegen
-
Hallo,
ich habe Probleme beim zerlegen von einem Mqtt String.
Der von hier verwendete Script zeigt keine Fehler.
Es werden aber keine Datenpunkte angelegt.
Ich kapier das einfach nicht, liegt wohl am Alter.hier mal der Script
const JSPath = '0_userdata.0'/Example state/ // JS- Pfad
const parsedStatesPath = JSPath + ".Pelletofen" // Pfad fuer geparste States
const zigbee2mqttJsonPath = 'mqtt.0.service'/service/
let IDs = [];$("[id=" + zigbee2mqttJsonPath + ".*]").each(function (id) {
IDs.push(id)
})on({id: IDs, change: "ne"}, function (obj) {
let JsonObj = JSON.parse(obj.state.val)
Object.keys(JsonObj).forEach(function(key){
if (getState(obj.id.replace(zigbee2mqttJsonPath, parsedStatesPath)).notExist){
createState(obj.id.replace(zigbee2mqttJsonPath, parsedStatesPath) + '.' + key, JsonObj[key], {read: true, write: true, type: typeof(JsonObj[key]), name: '' , desc: ''},function(){
setState(obj.id.replace(zigbee2mqttJsonPath, parsedStatesPath) + '.' + key, JsonObj[key])
})
}else {
setState(obj.id.replace(zigbee2mqttJsonPath, parsedStatesPath) + '.' + key, JsonObj[key])
};
})
})

Vilen Dank schonmal im voraus.
Klaus -
Hallo,
ich habe Probleme beim zerlegen von einem Mqtt String.
Der von hier verwendete Script zeigt keine Fehler.
Es werden aber keine Datenpunkte angelegt.
Ich kapier das einfach nicht, liegt wohl am Alter.hier mal der Script
const JSPath = '0_userdata.0'/Example state/ // JS- Pfad
const parsedStatesPath = JSPath + ".Pelletofen" // Pfad fuer geparste States
const zigbee2mqttJsonPath = 'mqtt.0.service'/service/
let IDs = [];$("[id=" + zigbee2mqttJsonPath + ".*]").each(function (id) {
IDs.push(id)
})on({id: IDs, change: "ne"}, function (obj) {
let JsonObj = JSON.parse(obj.state.val)
Object.keys(JsonObj).forEach(function(key){
if (getState(obj.id.replace(zigbee2mqttJsonPath, parsedStatesPath)).notExist){
createState(obj.id.replace(zigbee2mqttJsonPath, parsedStatesPath) + '.' + key, JsonObj[key], {read: true, write: true, type: typeof(JsonObj[key]), name: '' , desc: ''},function(){
setState(obj.id.replace(zigbee2mqttJsonPath, parsedStatesPath) + '.' + key, JsonObj[key])
})
}else {
setState(obj.id.replace(zigbee2mqttJsonPath, parsedStatesPath) + '.' + key, JsonObj[key])
};
})
})

Vilen Dank schonmal im voraus.
Klaus@klaus-anders
Den Javascript-Code bitte in Code tags einbetten, da so nicht lesbar.
Wolltest Du die Datenpunkte nicht unter "0_userdata.0.Pelletofen" anlegen?
const JSPath = '0_userdata.0'; // JS- Pfad const parsedStatesPath = JSPath + ".Pelletofen."; // Pfad fuer geparste States const idJSON = 'mqtt.0.service'; on(idJSON, function (dp) { let JsonObj = JSON.parse(dp.state.val); Object.keys(JsonObj).forEach(function(key) { if(existsState(parsedStatesPath + key)) setState(parsedStatesPath + key, JsonObj[key], true); else createState(parsedStatesPath + key, JsonObj[key], {read: true, write: false, type: typeof JsonObj[key], name: key}); }); }); -
@klaus-anders
Den Javascript-Code bitte in Code tags einbetten, da so nicht lesbar.
Wolltest Du die Datenpunkte nicht unter "0_userdata.0.Pelletofen" anlegen?
const JSPath = '0_userdata.0'; // JS- Pfad const parsedStatesPath = JSPath + ".Pelletofen."; // Pfad fuer geparste States const idJSON = 'mqtt.0.service'; on(idJSON, function (dp) { let JsonObj = JSON.parse(dp.state.val); Object.keys(JsonObj).forEach(function(key) { if(existsState(parsedStatesPath + key)) setState(parsedStatesPath + key, JsonObj[key], true); else createState(parsedStatesPath + key, JsonObj[key], {read: true, write: false, type: typeof JsonObj[key], name: key}); }); });@paul53
Vielen Dank, das funzt.
Hey! Du scheinst an dieser Unterhaltung interessiert zu sein, hast aber noch kein Konto.
Hast du es satt, bei jedem Besuch durch die gleichen Beiträge zu scrollen? Wenn du dich für ein Konto anmeldest, kommst du immer genau dorthin zurück, wo du zuvor warst, und kannst dich über neue Antworten benachrichtigen lassen (entweder per E-Mail oder Push-Benachrichtigung). Du kannst auch Lesezeichen speichern und Beiträge positiv bewerten, um anderen Community-Mitgliedern deine Wertschätzung zu zeigen.
Mit deinem Input könnte dieser Beitrag noch besser werden 💗
Registrieren Anmelden