[Magisk] yomama163:
Hey Guys, just wanted to give my 2 cents to this topic as I once asked for someone to maybe code a Tasker profile for charging during sleep and in the end I did it myself. Feel free to copy my idea

My plan was to have my charging levels vary while I sleep (and instead of waking up every time just to change the mcs variables I wanted Tasker to take over that obviously). In this example I start with mcs 60 40 (more less ideal battery charge stats) and make it charge to 100% 1 hour before my alarm rings (just to be sure any low current charging adapter can charge it in time).

This requires root access on Tasker and AutoAlarm from the Play Store.

1. Device Boot

I encountered something weird where I started mcs from terminal without it running and it gave me an output with a prompt to disable it (Vol Down + C). This can kill my task as Tasker terminal thinks it's still handling code via Terminal (which we only need once shortly and not at all after that). In order to override that problem I enabled mcs as soon as my device boots and checks if mcs is running.

Profile: Device Boot (27)
Event: Device Boot
Enter: Start mcs (28)
A1: Wait [ MS:0 Seconds:10 Minutes:0 Hours:0 Days:0 ]
A2: Run Shell [ Command:su -c mcs -s Timeout (Seconds):0 Use Root:eek:n Store Output In:%MCS Store Errors In: Store Result In: ]
A3: If [ %MCS ~R paused ]
A4: Run Shell [ Command:su -c mcs -s Timeout (Seconds):0 Use Root:eek:n Store Output In:%MCS Store Errors In: Store Result In: ]

2. Before Alarm

I set my "Before Alarm" status to 1 hour before my alarm is going to ring to initiate the full charge.

Profile: Before Alarm (42)
Priority: 10
State: Variable Value [ %ALARM1 ~ 1 & %ALARM2 ~ 0 ]
Enter: Before Alarm Charge (43)
A1: Run Shell [ Command:su -c mcs 100 100 Timeout (Seconds):0 Use Root:eek:n Store Output In: Store Errors In: Store Result In: ]
A2: Profile Status [ Name:Before Alarm Set:eek:ff ]

3. Sleep Charging

This version of my sleeping task is a small snippet of my actual sleeping task (involving way more tasks that control Wifi, Mobile Data etc) with only the charging limits put in.

You can also replace my values to your desire if you want. I have this task set as a button press on my home screen as my time of sleep often varies.

Sleeping Time 2 (36)

A1: AutoAlarm [ Configuration:NOTE: This will not work correctly if the 'Relible Alarms' option is enabled in Tasker. No extra configuration needed Timeout (Seconds):10 Continue Task After Error:eek:n ]
---> AutoAlarm reads the Android Alarm API and converts the values into variable
A2: If [ %hoursc < 12 & %daysc = 0 ]
---> Checking if my alarm is ringing in 12 hours
A3: Run Shell [ Command:su -c mcs 60 40 Timeout (Seconds):0 Use Root:eek:ff Store Output In: Store Errors In: Store Result In: ]
---> set the charging limit to 60 40 because these are the healthiest percentages for the battery
A4: Profile Status [ Name:Before Alarm Set:eek:n ]
---> Activate "Before Alarm" Profile
A5: AutoAlarm [ Configuration:NOTE: This will not work correctly if the 'Relible Alarms' option is enabled in Tasker. No extra configuration needed Timeout (Seconds):10 Continue Task After Error:eek:n ]
---> Needed for the next tasks
A6: Variable Set [ Name:%ALARM1 To:%hoursc Recurse Variables:eek:ff Do Maths:eek:ff Append:eek:ff ]
---> Hours until alarm rings noted as variable
A7: Variable Set [ Name:%ALARM2 To:%minutesc Recurse Variables:eek:ff Do Maths:eek:ff Append:eek:ff ]
---> Minutes until alarm rings noted as variable
A8: If [ %hoursc < 12 & %daysc = 0 ]
---> same as A2
A9: Wait [ MS:0 Seconds:10 Minutes:0 Hours:0 Days:0 ]
---> If my alarm is ringing in 12 hours wait for 10 seconds
A10: Goto [ Type:Action Number Number:14 Label: ]
---> Loop the task until Alarm goes off
A11: Else
A12: Run Shell [ Command:su -c mcs 90 80 Timeout (Seconds):0 Use Root:eek:ff Store Output In: Store Errors In: Store Result In: ]
---> Alarm went off, time to set mcs to "optimized" charging values without unnecessary bloating the battery
A13: End If
A14: End If
A15: Variable Clear [ Name:%ALARM1 Pattern Matching:eek:ff Local Variables Only:eek:ff ]
---> Clearing variables
A16: Variable Clear [ Name:%ALARM2 Pattern Matching:eek:ff Local Variables Only:eek:ff ]
---> Clearing variables