Check if AC should be disconnected? (Poorman's AlDente)

I have a MacBook Retina, 12-inch, 2017, which makes using a tool like AlDente (for keeping the battery in good condition) impossible.

This is a scheduled script that notifies me to manually unplug when I reach 80% charge, and again manually plug it back in when the charge drops to 40%.

Open monitor-battery in Script Kit

// Menu: Battery Monitor
// Description: Check if AC should be disconnected? Poorman's AlDente
// Author: Richard Dyce
// Twitter: @dickiedyce
// schedule: 0,15,20,45 5-22 * * *
import "@johnlindquist/kit"
const result = await exec(`pmset -g batt`)
const charge = 1 * result.stdout.match(/(\d+)\%/)[1]
const state = result.stdout.match(/(discharging|charging)/)[0]
const source = result.stdout.match(/(Battery Power|AC Power)/)[0]
if(charge > 80 && source == 'AC Power' ) {
notify(`UNPLUG! The laptop is ${state} from ${source}, at ${charge}%`)
} else if (charge < 40 && source == 'Battery Power') {
notify(`PLUG-IN! The laptop is ${state} from ${source}, at ${charge}%`)
} else {
// notify(`The laptop is ${state} from ${source}, at ${charge}%`)
}

Future plans: I have a Wemo WiFI Smart Plug on order, so if I can't stop the battery charging, I should be able to turn the charger off at the wall. ;-)