Here is more you ever wanted to know about ecowitt battery reporting.. i did not write this code just interpretting it and also reasearched some on the net.
Apparently in their ultimate wisdom ecowitt reports battery level 3 ways.
-
as a voltage that you can control min and max in the hubitat app settings but the default is
min = 1.3, max = 1.65. in the hubitat app this is converted to a percentage then as always the batteryOrg which means original has the raw value reported.
-
as a number between 0 and 5 again converted to 0 - 100 with the original in the batteryorg and
finally
3, as you know either 0 or 1 , ie is the battery low yes or no 0 or 1
raw code:
private Boolean attributeUpdateBattery(String val, String attribBattery, String attribBatteryIcon, String attribBatteryOrg, Integer type) {
//
// Convert all different batteries returned values to a 0-100% range
// Type: 1) voltage: range from 1.30V (empty) to 1.65V (full)
// 2) pentastep: range from 0 (empty) to 5 (full)
// 0) binary: 0 (full) or 1 (empty)
//
BigDecimal original = val.toBigDecimal();
BigDecimal percent;
BigDecimal icon;
String unitOrg;
// log.debug "in attribute update battery val = $val attrib = $attribBattery type = $type"
switch (type) {
case 1:
// Change range from voltage to (0% - 100%)
BigDecimal vMin, vMax;
if (!(settings.voltageMin) || !(settings.voltageMax)) {
// First time: initialize and show the preference
vMin = 1.3;
vMax = 1.65;
device.updateSetting("voltageMin", [value: vMin, type: "string"]);
device.updateSetting("voltageMax", [value: vMax, type: "string"]);
}
else {
vMin = (settings.voltageMin).toBigDecimal();
vMax = (settings.voltageMax).toBigDecimal();
}
percent = convertRange(original, vMin, vMax, 0, 100);
unitOrg = "V";
break;
case 2:
// Change range from (0 - 5) to (0% - 100%)
percent = convertRange(original, 0, 5, 0, 100);
unitOrg = "level";
break;
default:
// Change range from (0 or 1) to (100% or 0%)
percent = (original == 0)? 100: 0;
unitOrg = "!bool";
}
if (percent < 10) icon = 0;
else if (percent < 30) icon = 20;
else if (percent < 50) icon = 40;
else if (percent < 70) icon = 60;
else if (percent < 90) icon = 80;
else icon = 100;
Boolean updated = attributeUpdateNumber(percent, attribBattery, "%", 0);
if (attributeUpdateNumber(icon, attribBatteryIcon, "%")) updated = true;
if (attributeUpdateNumber(original, attribBatteryOrg, unitOrg)) updated = true;
return (updated);
}