Page 1 of 1

Android battery level over mqtt in espeasy.

Posted: 08 Dec 2023, 17:45
by nobody@all
Hello:)
Does somebody tryied reading battery status from phone or tablet ?
I want to use old tablet for lcd screen but it will be not offen use and for safety i don't want to have still battery charger connected to it.
My idea is to read every 5min battery status and when it will be less than 20% using relay turn on wall charger and disconnect when be 100%

Re: Android battery level over mqtt in espeasy.

Posted: 08 Dec 2023, 21:17
by Ath
There are a few things to consider here:
- MQTT is a push protocol, so the measured value has to be pushed to a broker to be visible for others. So you can't pull that info by using MQTT.
- Moving the control to an external device, like an ESP unit, might create an undesirable triangle-dependency, maybe it should be more simple

I've used a somewhat different approach:
- Install the Android app Automate (free version with some limitations available, but enough for this purpose)
- Create a flow that checks the battery level, and when below the desired level (20%) send a command (http://ip.of.your.esp/control?cmd=event,poweron) to an ESPEasy-powered Sonoff S20 power plug (other brands/models can also be used, of course) to switch on, then wait for 10 minutes and loop
- Create another flow that checks for battery level 100%, and when reached, wait for an extra hour, the send a command (http://ip.of.your.esp/control?cmd=event,poweroff) to the the plug. Then wait for 10 minutes and loop.

Of course, the events poweron and poweroff have to be added as rules in the ESPEasy unit:

Code: Select all

on PowerOn do
  gpio,12,1
endon
on PowerOff do
  gpio,12,0
endon
Works like a charm :)

Re: Android battery level over mqtt in espeasy.

Posted: 10 Dec 2023, 21:49
by nobody@all
Thank You for reply, thank You Very much!
I will try in free moment of time.
:P