Python Scripts
Python-dlipower
Special thanks to our valued customer Dwight Hubbard for these handy Python scripts and examples.
Best for the legacy (pre 2017) DLI power controllers.
The newest version is on the python pypi repository (https://pypi.python.org/pypi/dlipower/)
The source is on github (https://github.com/dwighthubbard/python-dlipower)
Thanks again, Dwight.
Hammock (Best for WiFI capable controllers)
For those interested only in the WiFi capable power controllers, Hammock
https://github.com/kadirpekel/hammock/ is quite
sufficient to obtain a
convenient REST API interface.
Sample code:
from hammock import Hammock from requests.auth import HTTPDigestAuth import time auth = HTTPDigestAuth('admin', '1234') pcr=Hammock("http://192.168.0.100/restapi",append_slash=True,auth=auth,headers={'X-CSRF': 'x'}) print (pcr.auth.users.GET().json()) # [{u'outlet_access': [True, True, True, True, True, True, True, True], u'password': {u'$ref': u'0/password/'}, u'is_allowed': True, u'is_admin': True, u'name': u'admin'}]
print (pcr.auth.users(0).outlet_access.GET().json()) # [True, True, True, True, True, True, True, True]
# Outlets/Relays are zero indexed in the REST API (0-7) pcr.relay.outlets(0).state.PUT(json=True) # Relay 0 switches on time.sleep(5) outlets=pcr.relay.outlets # Relay 1 starts switching on for i in range(1,7): outlets(i).state.PUT(json=True) # outlets 1-7 switch on time.sleep(7) for i in range(8): outlets(i).state.PUT(json=False) # all outlets switch off print (pcr.auth.users("is_admin=true").name.GET().json()) # admin