adjust battery percent formula: max 3.3V and min 2.7V (the minimum voltage required by ATTiny85)

This commit is contained in:
Nicu Hodos 2025-10-03 10:24:33 +02:00
parent 7c9678a57c
commit 6edcafe27c

View File

@ -58,7 +58,7 @@ auto presenceTracker = Builder<BinarySensor>::instance(PRESENCE_SENSOR)
.withParent(gatewayDevice))
.withValueTemplate("{{ value_json.sensor.state }}")
.addDiagnostic(new VoltageSensor{PRESENCE_SENSOR, "Battery voltage", "{{ value_json.sensor.diagnostic.voltage }}"})
.addDiagnostic(new BatterySensor{PRESENCE_SENSOR, "Battery level", "{{ ((value_json.sensor.diagnostic.voltage|float-2.5)|round(2)*100/2)|int }}"})
.addDiagnostic(new BatterySensor{PRESENCE_SENSOR, "Battery level", "{{ ((value_json.sensor.diagnostic.voltage|float-2.7)|round(2)*100/0.6)|int }}"})
.withOffDelaySeconds(5*60)
.withDeviceClass("presence")
.build();