How to automate sending my current battery percentage to PC over the internet every 5 minutes? I'm using Android 9 on my device, there are many times when I'm away from my phone and it is charging in a different room or someone else is using it, is there was a way to send over the battery percentage say bp over to my PC at regular intervals via the internet.

There maybe apps that can do this but I'm interested more in a script or terminal based approach

Ideas I'm thinking of are:


using a script manager on my phone like https://play.google.com/store/apps/details?id=org.androidideas.scriptlauncher
crontab with a script that sends out bp to a copy pasta and my PC can have it's own script reading that
using cat /sys/class/power_supply/battery/capacity or dumpsys battery | grep "level:" | awk '{ print $2 }' once my device is rooted as mentioned here : How to get battery status in terminal? and doing that every N minutes using cron


I have Termux installed and my device is not rooted yet how do I proceed.
I'm using gist by Github (which can be done using gem install gist after installing ruby package) for broadcasting my battery percentage first to a private file,  tried using ix.io but pkg install ix didn't work on Android terminal the config.guess threw and error saying unable to guess system type.

Already had Termux installed on my Android with necessary packages and with pkg install termux-battery-status and installing the Playstore api app : https://play.google.com/store/apps/details?id=com.termux.api&amp;hl=en_IN using termux-battery-status | grep percentage | grep -oP '\: (.*?)\,' | grep -Eo '[0-9]{1,3}' gave the battery percentage in terminal.

Finally I added permissions using chmod +x bp.sh and set up crontab on Android to do this every minute using crontab -e and adding the line * * * * * ~/bp.sh

EDIT

Have started to make use of jq to parse json ouput, so now the one liner for script is termux-battery-status | jq .percentage | gist -f bp -u gist_id and start the crontab using crond

PS : I've put the entire thing here :  https://github.com/himanshuxd/bp-broadcast