{"id":8960,"library":"dlipower","title":"dlipower","description":"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.","status":"active","version":"1.0.176","language":"en","source_language":"en","source_url":"https://github.com/dwighthubbard/python-dlipower/","tags":["hardware","power control","digital loggers","network","api","automation"],"install":[{"cmd":"pip install dlipower","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Used for HTTP communication with the power switch.","package":"requests","optional":false}],"imports":[{"symbol":"PowerSwitch","correct":"from dlipower import PowerSwitch"}],"quickstart":{"code":"import os\nfrom dlipower import PowerSwitch\n\nHOSTNAME = os.environ.get('DLI_HOSTNAME', 'lpc.digital-loggers.com')\nUSERID = os.environ.get('DLI_USERID', 'admin')\nPASSWORD = os.environ.get('DLI_PASSWORD', '4321') # Replace with actual password or secure method\n\ntry:\n    # Connect to the Digital Loggers Power Switch\n    switch = PowerSwitch(hostname=HOSTNAME, userid=USERID, password=PASSWORD)\n\n    # Print the current state of all outlets\n    print(f\"\\nCurrent Power Switch Status at {HOSTNAME}:\")\n    print(switch)\n\n    # Turn off the first outlet (outlet number 1)\n    print(\"\\nTurning off outlet 1...\")\n    switch.off(1)\n    print(f\"Outlet 1 state: {switch[0].state}\")\n\n    # Turn on the second outlet (accessed by index 1, which is outlet number 2)\n    print(\"\\nTurning on outlet 2...\")\n    switch[1].on()\n    print(f\"Outlet 2 state: {switch[1].state}\")\n\n    # Rename an outlet\n    # print(\"\\nRenaming outlet 3 to 'My Device A'...\")\n    # switch[2].name = 'My Device A'\n    # print(f\"Outlet 3 new name: {switch[2].name}\")\n\n    print(\"\\nOperations complete.\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")","lang":"python","description":"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."},"warnings":[{"fix":"Verify your Digital Loggers device model and production date against the library's recommended use case. Consider alternative control methods for newer devices if issues arise.","message":"The `dlipower` library is specifically noted as being 'Best for the legacy (pre 2017) DLI power controllers.' Compatibility with newer Digital Loggers devices may vary or require alternative libraries/APIs.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure the `userid` and `password` are correct. Check the Digital Loggers device's web interface for 'Access Settings' or 'External API' configurations to ensure that basic authentication is enabled and not restricted. For secure communication, consider using `use_https=True` if your device supports it.","message":"Authentication failures (e.g., 'login denied') are common if the Digital Loggers device's web interface settings are not configured to allow plain-text logins or if incorrect credentials are provided.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Provide only the hostname or IP address without any scheme or trailing slashes (e.g., `192.168.0.100` or `lpc.digital-loggers.com`). The library handles the HTTP/HTTPS protocol internally, configurable via the `use_https` parameter.","message":"Passing a hostname with an HTTP/HTTPS scheme (e.g., `http://192.168.0.100/`) to `PowerSwitch(hostname=...)` can lead to connection errors or `TypeError: object of type 'NoneType' has no len()` when trying to access outlets.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always specify a `timeout` value in seconds when creating a `PowerSwitch` instance (e.g., `PowerSwitch(..., timeout=10)`) to prevent applications from becoming unresponsive due to network issues or device unreachability.","message":"Network requests can hang indefinitely without a timeout. The `PowerSwitch` constructor accepts a `timeout` parameter, which defaults to `None` (no timeout).","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Provide only the IP address or hostname without the protocol (e.g., `hostname='192.168.0.100'` instead of `hostname='http://192.168.0.100/'`). Ensure the DLI device is reachable and credentials are correct.","cause":"This error typically occurs when the `PowerSwitch` object fails to connect to the DLI device, often due to an incorrectly formatted hostname (e.g., including `http://` or `https://` in the hostname string).","error":"TypeError: object of type 'NoneType' has no len()"},{"fix":"Double-check the `userid` and `password`. On the DLI device's web interface, navigate to 'Access Settings' or 'External APIs' and ensure that the user has appropriate permissions and that plain HTTP/plaintext authentication is allowed if `use_https=False` is used, or ensure HTTPS is enabled and `use_https=True`.","cause":"The DLI power switch denied the login attempt. This often means incorrect credentials were provided, or the device's security settings prevent plain-text logins.","error":"login denied for admin@10.1.48.158 (plaintext): password check failed"},{"fix":"Verify network connectivity to the DLI device. Ensure the device is powered on and responsive. Increase the `timeout` parameter in the `PowerSwitch` constructor. Check the device's logs if accessible.","cause":"The connection to the DLI power switch was unexpectedly closed by the device itself, often due to network instability, device overload, or the device rejecting the connection attempt prematurely.","error":"requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))"}]}