this post was submitted on 13 Sep 2024
20 points (100.0% liked)

Android

27549 readers
585 users here now

DROID DOES

Welcome to the droidymcdroidface-iest, Lemmyest (Lemmiest), test, bestest, phoniest, pluckiest, snarkiest, and spiciest Android community on Lemmy (Do not respond)! Here you can participate in amazing discussions and events relating to all things Android.

The rules for posting and commenting, besides the rules defined here for lemmy.world, are as follows:

Rules


1. All posts must be relevant to Android devices/operating system.


2. Posts cannot be illegal or NSFW material.


3. No spam, self promotion, or upvote farming. Sources engaging in these behavior will be added to the Blacklist.


4. Non-whitelisted bots will be banned.


5. Engage respectfully: Harassment, flamebaiting, bad faith engagement, or agenda posting will result in your posts being removed. Excessive violations will result in temporary or permanent ban, depending on severity.


6. Memes are not allowed to be posts, but are allowed in the comments.


7. Posts from clickbait sources are heavily discouraged. Please de-clickbait titles if it needs to be submitted.


8. Submission statements of any length composed of your own thoughts inside the post text field are mandatory for any microblog posts, and are optional but recommended for article/image/video posts.


Community Resources:


We are Android girls*,

In our Lemmy.world.

The back is plastic,

It's fantastic.

*Well, not just girls: people of all gender identities are welcomed here.


Our Partner Communities:

!android@lemmy.ml


founded 1 year ago
MODERATORS
 

I have an unrooted GrapheneOS phone. I was surprised that it doesn’t offer a native option to limit battery charging to a specific upper limit (e.g., 80%) to preserve battery health and prolong the battery's life.

To work around this, I decided to implement a charging limit feature using automation software and a Wi-Fi-controllable plug. After some research, I bought a Shelly Plug S for this purpose. I'm trying to keep things open-source, so I avoid Google Play apps when possible. The closest Tasker alternative I found on F-Droid is Easer. Unfortunately, Easer seems to lack some crucial features that would make this process easier, such as switching Wi-Fi networks or starting external apps.

Here’s my plan so far:

  • My phone’s charger is plugged into the Shelly Plug S, which is connected to my Wi-Fi network.
  • I want to use Easer to automate the process: It would turn on the plug when the charger is connected, monitor the battery level, and, once it reaches 80%, turn off the Shelly Plug S by making an HTTP call to its local web interface (or an API call).
  • I prefer to block the Shelly Plug from accessing the Internet entirely (to avoid leaking data to the cloud) by setting up firewall rules that restrict its access to only my local network.

However, Easer seems to have some limitations that make this more challenging than expected:

  • Easer cannot switch Wi-Fi networks: I was hoping to use the Shelly Plug’s local access point (AP mode) for a more portable solution, but since Easer doesn’t have permission to switch networks, I'm restricted to my home network.
  • Easer cannot start external apps: It also can’t trigger external apps that might help with network switching or more advanced controls.

At the moment, I’m stuck with these limitations and was wondering if anyone has experience with similar setups or has already written code to implement something like this. Specifically:

Has anyone written or seen code to automate switching off a Shelly Plug once a certain battery level is reached? Are there any workarounds for Easer’s limitations, or should I consider switching to a different automation tool that fits my FOSS preference?

I would greatly appreciate any tips, code snippets, or discussions around best practices for this type of setup. Ideally, I'd love to make this work while keeping the setup local and portable, but I’m open to suggestions!

Thanks in advance for your help!

top 13 comments
sorted by: hot top controversial new old
[–] brian@programming.dev 6 points 5 days ago

not portable or self contained, but homeassistant handles things like this quite well. you'd need it running somewhere else though. worth the effort if you plan to automate more things though

[–] seaQueue@lemmy.world 2 points 5 days ago* (last edited 5 days ago) (2 children)

Not the solution you're asking for but I've used the ACC magisk module to do this on devices for years. If you're willing to install magisk and then ignore it this is a very mature solution.

Otherwise, like others have said, run home assistant on your network somewhere and have tasker call to HA to switch the charger plug off when you hit your target charge level. That should be pretty straightforward.

[–] IceFoxX@lemm.ee 2 points 4 days ago (1 children)

Well I like magisk but he could try shizuku or grant perminission over adb and stay without root

[–] seaQueue@lemmy.world 2 points 4 days ago (1 children)

Yeah, shizuku could work I'm just not aware of any shizuku enabled charge control software

[–] IceFoxX@lemm.ee 2 points 4 days ago (1 children)

You can ignore my answer. To set a limit when recharging probably does not work with shizuku. root is unfortunately mandatory if not implemented in the system. That's sad

[–] seaQueue@lemmy.world 2 points 4 days ago (1 children)

Yeah, that's about what I expected unfortunately

[–] bremen15@feddit.org 1 points 5 days ago

I agree; that is a good solution for a rooted device. I use it on a lineageOS tablet.

[–] ptz@dubvee.org 1 points 5 days ago (1 children)

Easer cannot switch Wi-Fi networks: I was hoping to use the Shelly Plug’s local access point (AP mode) for a more portable solution, but since Easer doesn’t have permission to switch networks, I'm restricted to my home network.

What about setting up a reverse proxy on your main network that can then make the call to the Shelly Plug on its VLAN? I do this with my HomeAssistant and its devices which are all on an isolated network. The HA machine has internet access, but none of the other devices do (via firewall rules for that VLAN).

You'd have to make a firewall rule to allow the reverse proxy to be able to reach the restricted network, but that's pretty straightforward.

Easer cannot start external apps: It also can’t trigger external apps that might help with network switching or more advanced controls.

Not familiar with Easer (will have to check it out, though), but can it make an HTTP(S) call natively?

[–] bremen15@feddit.org 2 points 5 days ago (1 children)

Not familiar with Easer (will have to check it out, though), but can it make an HTTP(S) call natively?

Yes, it can. I plan to use that feature to access the plugs web interface.

[–] ptz@dubvee.org 1 points 5 days ago (1 children)

In that case, a reverse proxy on your "main" network that can access the Shelly Plug on the "restricted" network should work.

[–] bremen15@feddit.org 2 points 5 days ago (1 children)

Yes, it should. I hope someone has already implemented this setup and can confirme that it works as we think it does.

[–] ptz@dubvee.org 1 points 5 days ago

Should be pretty easy if you use Nginx. You can just proxy the full URI and params.

Main network:  192.168.1.0/24
Restricted network:  10.10.10.0/24
ShellyPlug IP:  10.10.10.5  (assuming it's REST API is on port 80, but adjust if needed)
Reverse Proxy IP:  192.168.1.10

Nginx "conf.d/shellyplug_proxy.conf": 

server {
  listen 80;
  server_name  shellyplug.lan;
  location / {
    proxy_pass http://10.10.10.5:80;
  }
}

As long as your reverse proxy (Nginx) on your main network can reach 10.10.10.5 port 80 on the restricted VLAN, it should work, and you should be able to use call the api from your main network at http://shellyplug.lan (or http://192.168.1.10) just as you would to it directly to the plug on its restricted network.

HTH