NiMH si alkalineIn acest repository exista o conversie configurabila pentru nivelul bateriei raportat de Zigbee2MQTT, folosita atunci cand dispozitivul are baterii reincarcabile NiMH in loc de baterii alkaline.
Motivatia este simpla: multe dispozitive raporteaza procentul bateriei pe o curba calibrata mai degraba pentru baterii alcaline, iar celulele NiMH au o curba de descarcare mai plata. Din acest motiv, procentul brut poate parea prea mic pentru baterii NiMH, mai ales in zona de mijloc a descarcarii.
Comportamentul este:
batteryType este alkaline, valoarea ramane neschimbatabatteryType este nimh, valoarea este remapata printr-o conversie bazata pe curbe aproximative alkaline -> tensiune -> NiMHbattery, cat si pentru derivarea lui battery_low atunci cand dispozitivul nu furnizeaza explicit acest campConversia este controlata din UI-ul nodurilor Node-RED prin campul Battery type, cu valoarea implicita alkaline.
Referinte UI:
Valorile disponibile sunt:
alkalinenimhPragul pentru battery_low este separat si configurabil prin batteryLowThreshold, implicit 20.
Fluxul logic este acelasi in ambele adaptoare:
payload.battery0..100nimh, procentul este convertit mai intai intr-o tensiune echivalenta pe o curba alkalineNiMHbatterybattery_low se calculeaza din valoarea convertita daca dispozitivul nu trimite deja un camp battery_lowzg-204zv/homebus-adapterImplementarea este in:
Configurarea tipului de baterie:
Unde este folosita functia:
battery: zg-204zv/homebus-adapter/z2m-zg-204zv-homebus.jsbattery_low: zg-204zv/homebus-adapter/z2m-zg-204zv-homebus.jsFunctia:
var ALKALINE_BATTERY_CURVE = [
{ pct: 100, voltage: 1.60 },
{ pct: 90, voltage: 1.55 },
{ pct: 80, voltage: 1.50 },
{ pct: 70, voltage: 1.46 },
{ pct: 60, voltage: 1.42 },
{ pct: 50, voltage: 1.36 },
{ pct: 40, voltage: 1.30 },
{ pct: 30, voltage: 1.25 },
{ pct: 20, voltage: 1.20 },
{ pct: 10, voltage: 1.10 },
{ pct: 0, voltage: 0.90 }
];
var NIMH_BATTERY_CURVE = [
{ pct: 100, voltage: 1.40 },
{ pct: 95, voltage: 1.33 },
{ pct: 90, voltage: 1.28 },
{ pct: 85, voltage: 1.24 },
{ pct: 80, voltage: 1.20 },
{ pct: 75, voltage: 1.19 },
{ pct: 70, voltage: 1.18 },
{ pct: 60, voltage: 1.17 },
{ pct: 50, voltage: 1.16 },
{ pct: 40, voltage: 1.15 },
{ pct: 30, voltage: 1.13 },
{ pct: 20, voltage: 1.11 },
{ pct: 10, voltage: 1.07 },
{ pct: 0, voltage: 1.00 }
];
function translateBatteryLevel(rawValue) {
if (rawValue === undefined) return undefined;
var raw = clamp(Math.round(Number(rawValue)), 0, 100);
if (node.batteryType !== "nimh") return raw;
var estimatedVoltage = interpolateCurve(ALKALINE_BATTERY_CURVE, "pct", "voltage", raw);
var nimhPct = interpolateCurve(NIMH_BATTERY_CURVE, "voltage", "pct", estimatedVoltage);
return clamp(Math.round(nimhPct), 0, 100);
}
Observatii:
alkaline este reinterpretat ca tensiune echivalenta pe celulaNiMH1.20V pe celula este tratata ca o zona inca sanatoasa pentru NiMH, nu ca baterie aproape goalaExemple:
| Brut | Convertit nimh |
|---|---|
| 5 | 0 |
| 10 | 18 |
| 20 | 80 |
| 25 | 83 |
| 30 | 86 |
| 40 | 92 |
| 50 | 97 |
| 60 | 100 |
| 80 | 100 |
| 100 | 100 |
Impact functional:
battery/value publica procentul convertitbattery_low/value este calculat din procentul convertit daca nu exista deja battery_low in payload20, un raw=5 devine 25, deci nu va fi marcat imediat ca battery_lowPA-44Z/homebus-adapterImplementarea este in:
Configurarea tipului de baterie:
Unde este folosita functia:
battery: PA-44Z/homebus-adapter/z2m-pa-44z-homebus.jsbattery_low: PA-44Z/homebus-adapter/z2m-pa-44z-homebus.jsFunctia:
var ALKALINE_BATTERY_CURVE = [
{ pct: 100, voltage: 1.60 },
{ pct: 90, voltage: 1.55 },
{ pct: 80, voltage: 1.50 },
{ pct: 70, voltage: 1.46 },
{ pct: 60, voltage: 1.42 },
{ pct: 50, voltage: 1.36 },
{ pct: 40, voltage: 1.30 },
{ pct: 30, voltage: 1.25 },
{ pct: 20, voltage: 1.20 },
{ pct: 10, voltage: 1.10 },
{ pct: 0, voltage: 0.90 }
];
var NIMH_BATTERY_CURVE = [
{ pct: 100, voltage: 1.40 },
{ pct: 95, voltage: 1.33 },
{ pct: 90, voltage: 1.28 },
{ pct: 85, voltage: 1.24 },
{ pct: 80, voltage: 1.20 },
{ pct: 75, voltage: 1.19 },
{ pct: 70, voltage: 1.18 },
{ pct: 60, voltage: 1.17 },
{ pct: 50, voltage: 1.16 },
{ pct: 40, voltage: 1.15 },
{ pct: 30, voltage: 1.13 },
{ pct: 20, voltage: 1.11 },
{ pct: 10, voltage: 1.07 },
{ pct: 0, voltage: 1.00 }
];
function translateBatteryLevel(rawValue) {
if (rawValue === null || rawValue === undefined) return null;
var raw = clamp(Math.round(Number(rawValue)), 0, 100);
if (node.batteryType !== "nimh") return raw;
var estimatedVoltage = interpolateCurve(ALKALINE_BATTERY_CURVE, "pct", "voltage", raw);
var nimhPct = interpolateCurve(NIMH_BATTERY_CURVE, "voltage", "pct", estimatedVoltage);
return clamp(Math.round(nimhPct), 0, 100);
}
Observatii:
ZG-204ZVNiMHExemple:
| Brut | Convertit nimh |
|---|---|
| 5 | 0 |
| 10 | 18 |
| 15 | 40 |
| 20 | 80 |
| 30 | 86 |
| 50 | 97 |
| 55 | 98 |
| 95 | 100 |
Impact functional:
battery publicat pe HomeBus este valoarea convertitapayload.battery_low lipseste, acesta este derivat din valoarea convertita si comparat cu batteryLowThresholdIn varianta actuala, ambele adaptoare folosesc aceeasi abordare bazata pe curbe, pentru a evita discrepantele dintre proiecte.
Explicatiile din help-ul nodurilor confirma intentia conversiei:
In starea actuala a repository-ului, functia de conversie intre NiMH si alkaline este folosita in doua proiecte:
zg-204zv/homebus-adapterPA-44Z/homebus-adapterAmbele aplica conversia doar cand batteryType este setat la nimh, iar pentru alkaline publica procentul brut primit de la Zigbee2MQTT.