Accessing Plugwise Circles with Python

2 minute read

Published:

Plugwise products are widely-spread in Europe. Plugwise Circles, a compact and popular kind of smart plugs, are measurement devices that are utilised in academia for teaching purposes as well as in measurement campaigns (e.g., GREEND dataset). Usually, a smart plug is attached to an electrical appliance to record its power consumption over time to identify power eaters or detect abnormal behaviour.

Already some years ago, Sven Petai released the python-plugwise project on Bitbucket. This Python library allows communication with Plugwise smart plugs. The repository can be found here.

In this blog post, we explain how python-plugwise can be installed and show first steps. We thank Sven Petai for sharing this project!

Before you proceed, make sure that you have a working Python installation on your computer. As always, we recommend Python 3.6 with Anaconda and PyCharm IDE.

Installation

hg clone https://bitbucket.org/hadara/python-plugwise
cd python-plugwise
sudo python setup.py install

We faced problems with pyserial during the installation process and fixed it with a simple:

pip install pyserial

Usage

As a first step, we import libraries and create some global variables:

import time
from plugwise import Stick, Circle

plug_list = ['000D6F0004555218', '000D6F00045431E6','000D6F000454B4B3']
plug_dictionary = {
    'main':'000D6F0004555218',
    'washer':'000D6F00045431E6',
    'light':'000D6F000454B4B3',
}

Plugwise circles are accessed via USB. This is reflected by the object Stick, which has to be created and bound to the USB adapter:

device_id = 2
device_name = 'light'

stick_port = '/dev/tty.usbserial-A103IXQ5'
st = Stick(stick_port)

To read information from a Plugwise circle, we need to create a new object:

# Access Plugwise circle and read values
smart_plug = Circle(plug_list[device_id], st)
power_consumption = round(smart_plug.get_power_usage(),2)
info = smart_plug.get_info()

Beside simple information, the library allows to control the integrated relay:

# Switch plugwise circle off and on again
smart_plug.switch_off()
time.sleep(1)
smart_plug.switch_on()

Finally, we print the readings:

# Print readings
print(device_name+' consumes: '+str(power_consumption)+ ' W')

print('Information on circle '+str(plug_list[device_id])+':')
print(str('Firmware version: ' + str(info['fw_ver'])))

print(str('Frequency: ' + str(info['hz'])))
print(str('Relay state: ' + str(info['relay_state'])))

Output:

light consumes: 8.51 W
Information on circle 000D6F000454B4B3:
Firmware version: 2011-06-27 10:52:18
Frequency: 50
Relay state: 1

Documentation

The creators of python-plugwise provide a compact documentation in the docstrings:

import plugwise
help(plugwise)

To be extended…

We will frequently update and extend this manual…

Comments