-- Leo's gemini proxy

-- Connecting to gmi.runtimeterror.dev:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini;lang=en-US

💻 [runtimeterror $]

2020-11-14

Safeguard your Android's battery with Tasker + Home Assistant



A few months ago, I started using the AccuBattery app [1] to keep a closer eye on how I'd been charging my phones. The app has a handy feature that notifies you once the battery level reaches a certain threshold so you can pull the phone off the charger and extend the lithium battery's service life, and it even offers an estimate for what that impact might be. For instance, right now the app indicates that charging my Pixel 5 from 51% to 100% would cause 0.92 wear cycles, while stopping the charge at 80% would impose just 0.17 cycles.

[1] AccuBattery app

Image: AccuBattery screenshot

But that depends on me being near my phone and conscious so I can take action when the notification goes off. That's often a big assumption to make - and, frankly, I'm lazy.

I'm fortunately also fairly crafty, so I came up with a way to combine my favorite Android automation app with my chosen home automation platform to take my laziness out of the picture.

The Ingredients

Wemo Mini Smart Plug


Raspberry Pi 3 [2] with Home Assistant [3] installed

Tasker

Home Assistant Plug-In for Tasker

[2] Raspberry Pi 3

[3] Home Assistant

I'm not going to go through how to install Home Assistant on the Pi or how to configure it beyond what's strictly necessary for this particular recipe. The official getting started documentation [4] is a great place to start.

[4] getting started documentation

The Recipe

Plug the Wemo into a wall outlet, and plug a phone charger into the Wemo. Add the Belkin Wemo integration in Home Assistant, and configure the device and entity. I named mine `switchy`. Make a note of the Entity ID: `switch.switchy`. We'll need that later.

Image: The new entity in HA

Either point your phone's browser to your Home Assistant instance's local URL [5], or use the Home Assistant app [6] to access it. Tap your username at the bottom of the menu and scroll all the way down to the Long-Lived Access Tokens section. Tap to create a new token. It doesn't matter what you name it, but be sure to copy to token data once it is generated since you won't be able to display it again.

Install the Home Assistant Plug-In for Tasker [7]. Open Tasker, create a new Task called 'ChargeOff', and set the action to `Plugin > Home Assistant Plug-in for Tasker > Call Service`. Tap the pencil icon to edit the configuration, and then tap the plus sign to add a new server. Give it whatever name you like, and then enter your Home Assistant's IP address for the Base URL, followed by the port number `8123`. For example, `http://192.168.1.99:8123`. Paste in the Long-Lived Access Token you generated earlier. Go on and hit the Test Server button to make sure you got it right. It'll wind up looking something like this:

Image: Configuring the HA connection in Tasker

For the Service field, you need to tell HA what you want it to do. We want it to turn off a switch so enter `switch.turn_off`. We'll use the Service Data field to tell it which switch, in JSON format:

{"entity_id": "switch.switchy"}

Tap Test Service to make sure it works - and verify that the switch does indeed turn off.

Image: Creating and testing the service

Hard part is over. Now we just need to set up a profile in Tasker to fire our new task. I named mine 'Charge Limiter'. I started with `State > Power > Battery Level` and set it to trigger between 81-100%., and also added `State > Power > Source: Any` so it will only be active while charging. I also only want this to trigger while my phone is charging at home, so I added `State > Net > Wifi Connected` and then specified my home SSID. Link this profile to the Task you created earlier, and never worry about overcharging your phone again.

Image: Tasker profile to kill power above 80%

[5] Home Assistant instance's local URL

[6] Home Assistant app

[7] Home Assistant Plug-In for Tasker

You can use a similar Task to turn the switch back on at a set time - or you could configure that automation directly in Home Assistant. I added an action to turn on the switch to my Google Assistant bedtime routine and that works quite well for my needs.




---


📧 Reply by email



Related articles


Automating Security Camera Notifications With Home Assistant and Ntfy

Easy Push Notifications With ntfy.sh

K8s on vSphere: Building a Kubernetes Node Template With Packer

---


Home

This page on the big web

-- Response ended

-- Page fetched on Fri May 10 20:20:15 2024