Collection of utilities for interfacing with various PDUs and smart outlets.
Project description
smartoutlet
Collection of utilities for interfacing with various PDUs and smart outlets. Meant to be used alongside home automation scripts or Home Assistant with the "command_line" platform.
CLI
A pair of command-line scripts are included that can probe or set the state of any supported outlet type. These can be used from the "command_line" platform of Home Assistant as long as you make sure this package is installed in your installation's venv and that fetchoutlet
and setoutlet
are located in the home directory of your Home Assistant setup. Some example uses are as follows.
Fetch the status of the first outlet on a Synaccess NP-02B PDU that is at 10.0.0.100:
./fetchoutlet np-02b 10.0.0.100 1
This will print the string "on" to stdout when the outlet is on, and "off" when the outlet is off.
Turn on the third outlet of an APC AP7900 PDU that is at 10.0.0.125:
./setoutlet ap7900 10.0.0.125 3 on
Turn the same outlet back off again:
./setoutlet ap7900 10.0.0.125 3 off
Obviously, you can substitute your own device's IP (or local DNS entry if you have set it up) for the IP of the device. The outlets should be numbered as they appear on the device's silkscreen. You should always use "on" and "off" to denote the on and off state of an outlet, or when fetching the state of an outlet. Note that if a unit can't be queried (you specified the wrong IP, have a bad username/password combo, specified an out-of-range outlet or haven't enabled SNMP for instance) fetchoutlet will instead return "unknown".
Sample Home Assistant Configuration
The following is an example for how to hook up a command-line switch in Home Assistant using the above CLI. The example assumes a NP-02B PDU with IP 192.168.0.50 where the thing we want to control is located on outlet #2. You can place this section directly in your configuration.yaml file. Be sure to validate your configuration before reloading!
switch:
- platform: command_line
scan_interval: 1
switches:
your_switch_name_here:
command_on: "./setoutlet np-02b 192.168.0.50 2 on &"
command_off: "./setoutlet np-02b 192.168.0.50 2 off &"
command_state: "./fetchoutlet np-02b 192.168.0.50 2"
value_template: '{{ value == "on" }}'
friendly_name: Your Switch Name Here
unique_id: your_switch_name_here
icon_template: >-
{% if value == "on" %}
mdi:light-switch
{% else %}
mdi:light-switch-off
{% endif %}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file smartoutlet-0.1.1.tar.gz
.
File metadata
- Download URL: smartoutlet-0.1.1.tar.gz
- Upload date:
- Size: 7.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.28.1 requests-toolbelt/0.8.0 tqdm/4.62.3 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 339d8f90d9de8791cc761ac41fd70787f0380a3d4e6283ec63b71bea154e2423 |
|
MD5 | 432fff6c24111004bf7272ec435a9b49 |
|
BLAKE2b-256 | ecf2ba258091017e762a10ff3a9e6d5d3a1673c98c6e2787993afaf9a66aa804 |
File details
Details for the file smartoutlet-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: smartoutlet-0.1.1-py3-none-any.whl
- Upload date:
- Size: 8.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.28.1 requests-toolbelt/0.8.0 tqdm/4.62.3 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 44e368bb1461fbbbcb4a28e11a48abb9991ee26afd34179af59ea963347c3383 |
|
MD5 | 9e66357e99f2e6f8a3fe0898f0a71bae |
|
BLAKE2b-256 | 5da9b777cbe0fa020e1aeefaf4b7e847931b159ffdf8b2b3852753401b874818 |