Skip to main content

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.

Support

Supports fetching the state of and setting the state of any outlet on the following models.

  • APC AP7900 (Uses SNMP interface)
  • APC AP7901 (Uses SNMP interface)
  • Synaccess NP-02 (Uses SNMP interface)
  • Synaccess NP-02B (Uses HTTP interface)

Note that it is most-likely trivial to add support for other models of the same manufacturer. Namely, The NP-08 and NP-05 line of PDUs from Synaccess are likely identical save for outlet limits enforced in code. However, I don't have them to test so I haven't added them. Note also that if you have a PDU that works via standard SNMP you can use the "SNMP" generic outlet and provide the read and update MIBs as well as the on and off values.

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

See generic help on how to use fetchoutlet:

./fetchoutlet --help

See specific parameter help for fetchoutlet with an np-02 outlet:

./fetchoutlet np-02 --help

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 %}

If you have a large number of switches, you can speed up Home Assistant's polling and operation of them by adding --daemon to both the fetchoutlet and setoutlet calls. This works only on OSX/Linux and will start a separate process that monitors and caches the values of each of your queried/set outlets automatically, making Home Assistant appear more responsive. This is necessary as Home Assistant polls all switches sequentially and only sends update commands between a full poll cycle. So, of you have lots of switches and they take awhile to respond, you will notice very slow operation of your switches unless you activate daemon mode.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

smartoutlet-0.2.2.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

smartoutlet-0.2.2-py3-none-any.whl (14.6 kB view details)

Uploaded Python 3

File details

Details for the file smartoutlet-0.2.2.tar.gz.

File metadata

  • Download URL: smartoutlet-0.2.2.tar.gz
  • Upload date:
  • Size: 12.5 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

Hashes for smartoutlet-0.2.2.tar.gz
Algorithm Hash digest
SHA256 ab54b585a60f816648dcb63f17d74246173684b411674859c94f21709dd4912e
MD5 b33e2da1161639bc8398141d2e046c9a
BLAKE2b-256 a8e5e9314e986b2ea425403ec138d7b9276c2ce79ba940e987fd08150bdb6900

See more details on using hashes here.

File details

Details for the file smartoutlet-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: smartoutlet-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 14.6 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

Hashes for smartoutlet-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8098f7268f70c1c1c40029955de78e06ffcdf2db74656588228a31fcfc692f58
MD5 778d8d85b43ec32085ca50e403b04ef4
BLAKE2b-256 5d579e6baa038081b8f8bd666b1f8dfdbc3478c8fcc2faadd9aebc2bc80ee8b1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page