How to read the temperature of battery.

112 views
Skip to first unread message

The 32-bit guy

unread,
Jan 21, 2019, 2:55:24 PM1/21/19
to DroidScript
You can read the temperature of your phone battery,health etc with this code:

//Called when application is started.
function OnStart()
{
//Sets theme
theme = app.CreateTheme( "Light" );
theme.SetTextColor( "black" );
app.SetTheme( theme );

//Create a layout with objects vertically centered.
lay = app.CreateLayout( "linear", "VCenter,FillXY" );

//Create a text label and add it to layout.(Gets stats from sys on devices /)
BatT = app.CreateText("Battery Temp " + app.ReadFile("/sys/class/power_supply/battery/batt_temp" )/10 + " Degrees");
BatT.SetTextSize( 20 );
lay.AddChild( BatT );

//Create a text label and add it to layout.
BatH = app.CreateText("Battery Health " + app.ReadFile("/sys/class/power_supply/sec-fuelgauge/health" ));
BatH.SetTextSize( 20 );
lay.AddChild( BatH );

//Add layout to app.
app.AddLayout( lay );
}

Steve Garman

unread,
Jan 21, 2019, 3:19:24 PM1/21/19
to DroidScript
I don't know whether this works on all rooted devices but I'm pretty sure it won't work on any unrooted devices.

BareK

unread,
Jan 21, 2019, 3:32:44 PM1/21/19
to DroidScript
It work on ma unrooted OnePlus One, but I had to change the paths.
I used the immediate window of the WiFi IDE to check them using "$cat path" and this link to check for infos:

So here is the code that work on my device:

//Called when application is started.
function OnStart()
{
   
//Sets theme
    theme
= app.CreateTheme( "Light" );
    theme
.SetTextColor( "black" );
    app
.SetTheme( theme );
   
   
//Create a layout with objects vertically centered.

    lay
= app.CreateLayout( "Linear", "VCenter,FillXY" );        
   
   
//Create a text label and add it to layout.(Gets stats from sys on devices /)
   
BatT = app.CreateText("Battery Temp " +  app.ReadFile("/sys/class/power_supply/battery/temp" )/10 + " Degrees");

   
BatT.SetTextSize( 20 );
    lay
.AddChild( BatT );
   
   
//Create a text label and add it to layout.

   
BatH = app.CreateText("Battery Health " +  app.ReadFile("/sys/class/power_supply/battery/health" ));

   
BatH.SetTextSize( 20 );
    lay
.AddChild( BatH );
   
   
//Add layout to app.        
    app
.AddLayout( lay );
}

I would be interested if it works on other devices :)

Anyway, thanks for sharing!

The 32-bit guy

unread,
Jan 21, 2019, 4:54:07 PM1/21/19
to DroidScript
I want to make sure the code works for all phones.
I'm currently experimenting with a android 5.11 so if a few people could ensure the code would work on their phones it would be good.

Chris

unread,
Jan 22, 2019, 6:48:38 PM1/22/19
to DroidScript
I see you are using premium functions. (themes). Why not post in Premium forum?

The 32-bit guy

unread,
Jan 26, 2019, 8:21:42 AM1/26/19
to DroidScript
Never got the Email.
Screenshot_2019-01-26-13-19-42.jpg

Lino Gorjan

unread,
Aug 8, 2019, 8:58:16 AM8/8/19
to DroidScript
On huawei p20 pro (android 8.1) this program doesn't work. So I am looking to find some solution for battery temperature firstly

The 32-bit guy

unread,
Aug 10, 2019, 9:19:40 AM8/10/19
to DroidScript
Look around in the same sys folder used in the code for sec-fuelgauge, power-supply for anything related to temperature and read the files with 7zipper 2.0 "text" option.

Awuah Dominic

unread,
Aug 10, 2019, 11:41:02 AM8/10/19
to DroidScript
itel p13,
Version 8.1, goEdition..
Result after testing...
Temp..0 degree
Bhealth... Good...
Does that look working?
Reply all
Reply to author
Forward
0 new messages