@endurance
Habs herausgefunden, daten stecken alle in einem Objekt....
Habs mit dem folgenden Skript auseinandergenommen:
// === Einstellungen ===
const MQTT_STATE = 'mqtt.0.ecowitt.3C8A1F2A63C7'; // <- DEINE State-ID hier eintragen
const BASE = '0_userdata.0.ecowitt.'; // Zielordner
// === Hilfsfunktionen ===
function toNumber(x) { const n = Number(x); return isFinite(n) ? n : null; }
function f2c(f){ const n = toNumber(f); return n==null ? null : (n-32)*5/9; }
function inHg2hPa(h){ const n = toNumber(h); return n==null ? null : n*33.8638866667; }
function mph2ms(m){ const n = toNumber(m); return n==null ? null : m*0.44704; }
function inch2mm(i){ const n = toNumber(i); return n==null ? null : i*25.4; }
// Einfacher Querystring‑Parser (ohne URLSearchParams)
function parseQuery(q) {
const out = {};
if (typeof q !== 'string' || !q) return out;
// WU-Style: '+' = Leerzeichen
q = q.replace(/\+/g, ' ');
// Teile erst an & und dekodiere dann key/value
q.split('&').forEach(pair => {
const idx = pair.indexOf('=');
let k, v;
if (idx >= 0) {
k = decodeURIComponent(pair.slice(0, idx));
v = decodeURIComponent(pair.slice(idx + 1));
} else {
k = decodeURIComponent(pair);
v = '';
}
if (k) out[k] = v;
});
return out;
}
// State-Schreiber (legt State an, falls nicht vorhanden)
async function put(id, val, unit='', type='number') {
const full = BASE + id;
if (!await existsStateAsync(full)) {
await setObjectAsync(full, {type: 'state', common: {name: id, read: true, write: false, type, role: 'value', unit}, native: {}});
}
setState(full, val, true);
}
// === Subscriber: jedes Update parsen ===
on({ id: MQTT_STATE, change: 'any' }, async obj => {
try {
if (!obj || !obj.state || typeof obj.state.val !== 'string') return;
const params = parseQuery(obj.state.val);
// Meta
await put('meta.stationtype', params.stationtype || '', '', 'string');
await put('meta.model', params.model || '', '', 'string');
await put('meta.dateutc', params.dateutc || '', '', 'string');
await put('meta.interval', toNumber(params.interval));
// Innen
await put('inside.temp_C', f2c(params.tempinf), '°C');
await put('inside.humidity_pct', toNumber(params.humidityin), '%');
await put('pressure.rel_hPa', inHg2hPa(params.baromrelin), 'hPa');
await put('pressure.abs_hPa', inHg2hPa(params.baromabsin), 'hPa');
// Außen
await put('outside.temp_C', f2c(params.tempf), '°C');
await put('outside.humidity_pct', toNumber(params.humidity), '%');
await put('outside.vpd_kPa', toNumber(params.vpd), 'kPa');
// Wind
await put('wind.dir_deg', toNumber(params.winddir), '°');
await put('wind.dir_avg10m_deg', toNumber(params.winddir_avg10m), '°');
await put('wind.speed_ms', mph2ms(params.windspeedmph), 'm/s');
await put('wind.gust_ms', mph2ms(params.windgustmph), 'm/s');
await put('wind.maxdailygust_ms', mph2ms(params.maxdailygust), 'm/s');
// Solar/UV
await put('solar.radiation_Wm2', toNumber(params.solarradiation), 'W/m²');
await put('uv.index', toNumber(params.uv));
// Regen (Zoll -> mm)
await put('rain.rate_mmph', inch2mm(params.rrain_piezo), 'mm/h');
await put('rain.event_mm', inch2mm(params.erain_piezo), 'mm');
await put('rain.hour_mm', inch2mm(params.hrain_piezo), 'mm');
await put('rain.day_mm', inch2mm(params.drain_piezo), 'mm');
await put('rain.week_mm', inch2mm(params.wrain_piezo), 'mm');
await put('rain.month_mm', inch2mm(params.mrain_piezo), 'mm');
await put('rain.year_mm', inch2mm(params.yrain_piezo), 'mm');
// Batteries / Misc (Wittboy)
await put('wittboy.cap_volt', toNumber(params.ws90cap_volt), 'V');
await put('wittboy.version', toNumber(params.ws90_ver));
await put('wittboy.batt_V', toNumber(params.wh90batt), 'V');
// Rohdaten ablegen (optional, hilfreich zum Debuggen)
await put('raw.query', obj.state.val, '', 'string');
} catch (e) {
log(`Ecowitt parse error: ${e}`, 'error');
}
});