Automate charge cycles for devices still connected to a wall outlet

Is there a way to automate charge cycles (charging from 40% to 80% only) if the device is still connected to a power outlet? I am looking for an application that reads the load level and sends commands to external devices to turn on / off the power outlet.