Skip to main content

Python API for controlling myStrom switches

Project description

Python API for controlling myStrom switches/plugs.

Requirements

You need to have Python installed.

Installation

The package is available in the Python Package Index .

$ pip install python-mystrom

Details

At the moment the following endpoints are covered:

  • /report: for getting the current state and the power consumption

  • /relay: for setting the relay state

You will still be able to use your device with the smartphone application, curl, or other tools. The samples below shows how to use the switch with httpie and curl along with python-mystrom.

$ http http://IP_ADDRESS_PLUG/report
HTTP/1.1 200 OK
Content-Length: 39
Content-Type: application/json
Date: Mon, 15 Feb 2016 17:52:21 GMT

{
    "power": 51.630947,
    "relay": true
}
$ curl -X GET http://IP_ADDRESS_PLUG/relay?state=1

Example

The sample below shows how to use this Python module.

import pymystrom

plug = pymystrom.MyStromPlug('IP_ADDRESS_PLUG')

# Preserve state
STATE_ON = plug.get_relay_state()

# Switch relay on if the plug is currently off
if not STATE_ON:
    print('Relay will be switched on.')
    plug.set_relay_on()
    # Wait a few seconds to get a reading of the power consumption
    print('Waiting for a couple of seconds...')
    time.sleep(10)

# Get the new state of the switch
print('Relay state: ', plug.get_relay_state())
print('Power consumption:', plug.get_consumption())

# Switch relay off if it was off.
if not STATE_ON:
    plug.set_relay_off()

License

python-mystrom is licensed under MIT, for more details check LICENSE.

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

python-mystrom-0.3.6.tar.gz (3.0 kB view details)

Uploaded Source

File details

Details for the file python-mystrom-0.3.6.tar.gz.

File metadata

File hashes

Hashes for python-mystrom-0.3.6.tar.gz
Algorithm Hash digest
SHA256 01b732d222779a0f39e45720d4e757143952979c5a2d71ce00ed3bf72a8ec32d
MD5 b02039068f4c4b5c2ba29201aadbb941
BLAKE2b-256 4c0dbe83accf6308bdc1cee96b3ab592ec166c3d16fdca7f7aa313b80b11b2e3

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