Some IoT devices are powered by electric battery and rely on ADC pin to do the battery measurement.
The issue is that the voltage value generally exceed voltage reference of Beken ADC pin who is by default 2400mv.
So to bypass that issue Tuya implement some voltage divider activated by a relay pin. here's an example on CBU:
thanks @nelliug54 for the schema
in this example BAT_ADC is on pin 5 and BAT_Relay on pin 20. when relay is activated it will divide the voltage on pin 5 by ~2.3 (it's mostly the case 2 or 3 AAA power sensor) on schema. but in real the divider was 2.29 so the vdivider really need to be adapt on each sensor (depending on the quality of resistor)
OpenBeken has a driver to capture that and publish the value in voltage and battery mqtt topic of the device.
If BAT_ADC pin is assign Battery driver will launched automatically and take measurement every 10sec.
it come with two command :
"Battery_Setup" : it permit to change the default parameter to calculate battery value.
- vmin(required) : minimal value accepted by the device in mv (default 2000)
- vmax(required) : maximal value accepted by the device in mv (default 3000)
- vdivider(optional) : divider (default 2.29 but to adapt on your sensor if value seems not good)
- vref(optional) : vref of the ADC pin (default 2400 and static on BK7231)
- adcbits(optional) : number of bits available in ADC (default 4096 in 99% of case shoud be that)
"Battery_cycle" <int> : it permit to adjust the number of frame to skip to take measurement (1 frames = 1seconds) (default = 10 )
On most device the default value should be ok, so just starting the driver and launch a scheduleHADiscovery will do the trick.
Edit : Change the order of args for battery setup to simplify script implementation (https://github.com/openshwprojects/OpenBK7231T_App/pull/692)
Edit 2 : Adding BAT pin reference and Autostart
The issue is that the voltage value generally exceed voltage reference of Beken ADC pin who is by default 2400mv.
So to bypass that issue Tuya implement some voltage divider activated by a relay pin. here's an example on CBU:
![[OpenBeken] Battery measurement driver based ADC with voltage divider [OpenBeken] Battery measurement driver based ADC with voltage divider](https://obrazki.elektroda.pl/4462413500_1676978226_thumb.jpg)
thanks @nelliug54 for the schema

in this example BAT_ADC is on pin 5 and BAT_Relay on pin 20. when relay is activated it will divide the voltage on pin 5 by ~2.3 (it's mostly the case 2 or 3 AAA power sensor) on schema. but in real the divider was 2.29 so the vdivider really need to be adapt on each sensor (depending on the quality of resistor)
OpenBeken has a driver to capture that and publish the value in voltage and battery mqtt topic of the device.
If BAT_ADC pin is assign Battery driver will launched automatically and take measurement every 10sec.
it come with two command :
"Battery_Setup" : it permit to change the default parameter to calculate battery value.
- vmin(required) : minimal value accepted by the device in mv (default 2000)
- vmax(required) : maximal value accepted by the device in mv (default 3000)
- vdivider(optional) : divider (default 2.29 but to adapt on your sensor if value seems not good)
- vref(optional) : vref of the ADC pin (default 2400 and static on BK7231)
- adcbits(optional) : number of bits available in ADC (default 4096 in 99% of case shoud be that)
"Battery_cycle" <int> : it permit to adjust the number of frame to skip to take measurement (1 frames = 1seconds) (default = 10 )
On most device the default value should be ok, so just starting the driver and launch a scheduleHADiscovery will do the trick.
Edit : Change the order of args for battery setup to simplify script implementation (https://github.com/openshwprojects/OpenBK7231T_App/pull/692)
Edit 2 : Adding BAT pin reference and Autostart
Cool? Ranking DIY