In the API scripting you don’t so much ‘configure’ the power off event to do something (which can be done in the SixFab Power interface at power.sixfab.com), instead you’d have to create a background script that would continually monitor the working_mode: github.com/sixfab/sixfab-power-python-api/blob/master/power_api/power_api.py:
def get_working_mode(self, timeout=RESPONSE_DELAY):
"""
Function for getting working mode
Parameters
-----------
timeout : int (optional)
timeout while receiving the response (default is RESPONSE_DELAY)
Returns
-------
working_mode : int
"1" for CHARGING, "2" for FULLY_CHARGED, "3" for BATTERY POWERED
"""
command.create_command(command.PROTOCOL_COMMAND_GET_WORKING_MODE)
command.send_command()
delay_ms(timeout)
raw = command.receive_command(COMMAND_SIZE_FOR_UINT8)
mode = raw[PROTOCOL_HEADER_SIZE]
return mode
What’s important in the snippet above is working_mode: 3 which would flag that mains has been disconnected.
I won’t teach you to suck eggs and write this for you because where’s the fun in that?
But what you want is a python script that imports PowerApi (You can check the examples here) and checks the input status every second or so, then you can set up your ‘disconnection timeout’ accordingly!
Hope this helps, if you’ve got any questions just lemme know.
Regards,
Daniel
Something worth knowing: It is not necessarily correct to assume get_working_mode indicates a full disconnect. While connected to external power, under heavy usage, the battery will be discharging. So, BATTERY_POWERED does not mean that external power is disconnected.
One must monitor the voltages to be sure it is disconnected.