dlipower

1.0.176 · active · verified Thu Apr 16

The dlipower library provides a Python API for managing Digital Loggers networked power switches. It allows programmatic control over power outlets, including turning them on/off, cycling power, and renaming outlets. The library also functions as a command-line utility. The current version is 1.0.176, and while still functional, it is noted as being best suited for older (pre-2017) DLI power controllers.

Common errors

Warnings

Install

Imports

Quickstart

Connects to a Digital Loggers Web Power Switch using environment variables for credentials and hostname. It then prints the overall switch status, turns off the first outlet, and turns on the second outlet. Replace `HOSTNAME`, `USERID`, and `PASSWORD` with your actual device's details, or set the corresponding environment variables.

import os
from dlipower import PowerSwitch

HOSTNAME = os.environ.get('DLI_HOSTNAME', 'lpc.digital-loggers.com')
USERID = os.environ.get('DLI_USERID', 'admin')
PASSWORD = os.environ.get('DLI_PASSWORD', '4321') # Replace with actual password or secure method

try:
    # Connect to the Digital Loggers Power Switch
    switch = PowerSwitch(hostname=HOSTNAME, userid=USERID, password=PASSWORD)

    # Print the current state of all outlets
    print(f"\nCurrent Power Switch Status at {HOSTNAME}:")
    print(switch)

    # Turn off the first outlet (outlet number 1)
    print("\nTurning off outlet 1...")
    switch.off(1)
    print(f"Outlet 1 state: {switch[0].state}")

    # Turn on the second outlet (accessed by index 1, which is outlet number 2)
    print("\nTurning on outlet 2...")
    switch[1].on()
    print(f"Outlet 2 state: {switch[1].state}")

    # Rename an outlet
    # print("\nRenaming outlet 3 to 'My Device A'...")
    # switch[2].name = 'My Device A'
    # print(f"Outlet 3 new name: {switch[2].name}")

    print("\nOperations complete.")

except Exception as e:
    print(f"An error occurred: {e}")

view raw JSON →